# Clyx core implementation test suite # Created by Luxferre in 2026, released into the public domain # 1. Stack Manipulation "Testing stack operations..." puts cr 5 dup = if [ " dup PASS" puts cr ] [ " dup FAIL" puts cr ] # Test dup 5 6 drop 5 = if [ " drop PASS" puts cr ] [ " drop FAIL" puts cr ] # Test drop 5 6 swap - 1 = if [ " swap PASS" puts cr ] [ " swap FAIL" puts cr ] # Test swap 5 6 7 rot [] cons cons cons [ 6 7 5 ] streq if [ " rot PASS" puts cr ] [ " rot FAIL" puts cr ] # Test rot 5 6 over [] cons cons cons [ 5 6 5 ] streq if [ " over PASS" puts cr ] [ " over FAIL" puts cr ] # Test over 5 6 nip 6 = if [ " nip PASS" puts cr ] [ " nip FAIL" puts cr ] # Test nip 5 6 tuck [] cons cons cons [ 6 5 6 ] streq if [ " tuck PASS" puts cr ] [ " tuck FAIL" puts cr ] # Test tuck # 2. Control Flow "Testing control flow..." puts cr [ 42 ] i 42 = if [ " i PASS" puts cr ] [ " i FAIL" puts cr ] # Test i 1 if [ " if true PASS" ] [ " if true FAIL" ] puts cr # Test if true 0 if [ " if false FAIL" ] [ " if false PASS" ] puts cr # Test if false 10 20 [ 5 - ] dip [] cons cons [ 5 20 ] streq if [ " dip PASS" puts cr ] [ " dip FAIL" puts cr ] # Test dip 5 dup while [ 1 - dup ] 0 = if [ " while loop PASS" puts cr ] [ " while loop FAIL" puts cr ] # Test while # 3. Mathematics & Arithmetic "Testing math and logic..." puts cr 10 4 - 6 = if [ " subtraction PASS" puts cr ] [ " subtraction FAIL" puts cr ] # Test subtraction 0 0= if [ " 0= with zero PASS" puts cr ] [ " 0= with zero FAIL" puts cr ] # Test 0= 5 0= if [ " 0= with non-zero FAIL" puts cr ] [ " 0= with non-zero PASS" puts cr ] # Test 0= -5 0< if [ " 0< with negative PASS" puts cr ] [ " 0< with negative FAIL" puts cr ] # Test 0< 0 0< if [ " 0< with zero FAIL" puts cr ] [ " 0< with zero PASS" puts cr ] # Test 0< 5 0< if [ " 0< with positive FAIL" puts cr ] [ " 0< with positive PASS" puts cr ] # Test 0< 5 3 nand -2 = if [ " nand PASS" puts cr ] [ " nand FAIL" puts cr ] # Test nand 5 3 * 15 = if [ " multiplication PASS" puts cr ] [ " multiplication FAIL" puts cr ] # Test multiplication 10 4 / 2.5 = if [ " division PASS" puts cr ] [ " division FAIL" puts cr ] # Test division 10 4 divmod [] cons cons [ 2 2 ] streq if [ " divmod PASS" puts cr ] [ " divmod FAIL" puts cr ] # Test divmod 10 4 div 2 = if [ " integer division PASS" puts cr ] [ " integer division FAIL" puts cr ] # Test div 10 4 mod 2 = if [ " modulo PASS" puts cr ] [ " modulo FAIL" puts cr ] # Test mod 5 2 shl 20 = if [ " shl left PASS" puts cr ] [ " shl left FAIL" puts cr ] # Test shl left 20 -2 shl 5 = if [ " shl right PASS" puts cr ] [ " shl right FAIL" puts cr ] # Test shl right 0 tan 0= if [ " tan PASS" puts cr ] [ " tan FAIL" puts cr ] # Test tan 0.5 cotan 0.5 cos 0.5 sin / = if [ " cotan PASS" puts cr ] [ " cotan FAIL" puts cr ] # Test cotan 5 neg -5 = if [ " neg PASS" puts cr ] [ " neg FAIL" puts cr ] # Test neg 5 1/ 0.2 = if [ " 1/ PASS" puts cr ] [ " 1/ FAIL" puts cr ] # Test 1/ 20 2 shr 5 = if [ " shr PASS" puts cr ] [ " shr FAIL" puts cr ] # Test shr 2 3 ^ 8 = if [ " power PASS" puts cr ] [ " power FAIL" puts cr ] # Test power 0 sin 0= if [ " sin PASS" puts cr ] [ " sin FAIL" puts cr ] # Test sin 0 cos 1.0 = if [ " cos PASS" puts cr ] [ " cos FAIL" puts cr ] # Test cos 0 atan 0= if [ " atan PASS" puts cr ] [ " atan FAIL" puts cr ] # Test atan 0 exp 1.0 = if [ " exp PASS" puts cr ] [ " exp FAIL" puts cr ] # Test exp 1 log 0= if [ " log PASS" puts cr ] [ " log FAIL" puts cr ] # Test log 9 sqrt 3.0 = if [ " sqrt PASS" puts cr ] [ " sqrt FAIL" puts cr ] # Test sqrt "Testing random..." puts cr 10 rand 10 div 0 = if [ 1 rand 0 = if [ " rand PASS" puts cr ] [ " rand FAIL" puts cr ] ] [ " rand FAIL" puts cr ] # Test rand # 4. Logical Operators "Testing logical operators..." puts cr 0 not 1 = 1 not 0 = and 1 1 and 1 = and 1 0 and 0 = and 1 0 or 1 = and 0 0 or 0 = and if [ " logic PASS" puts cr ] [ " logic FAIL" puts cr ] # 5. Input / Output & Networking "Testing I/O..." puts cr " Testing dot: " puts 123 . # Test dot " Testing emit: " puts 65 emit cr # Test emit " Testing readln: " puts readln puts cr # Test readln " Testing .s: " puts .s cr # Test .s "ok" "test_temp.txt" writef 2 = if [ "test_temp.txt" readf "ok" streq if [ "test_temp.txt" delf " file I/O PASS" puts cr ] [ "test_temp.txt" delf " file I/O FAIL" puts cr ] ] [ " file I/O FAIL" puts cr ] # Test file I/O "test_dir_clyx" maked "test_dir_clyx" listd qlen 0 = if [ "test_dir_clyx" deld " dir PASS" puts cr ] [ "test_dir_clyx" deld " dir FAIL" puts cr ] # Test dir 1000 rand 9000 + dup nlstn swap "127.0.0.1" swap nopen over read swap dup 10 chr "hello" + write drop swap dup read [ close ] dip [ close ] dip swap close "hello" streq if [ " sockets PASS" puts cr ] [ " sockets FAIL" puts cr ] # Test sockets # 6. Type Checking & Comparison "Testing type and predicates..." puts cr 42 type 0 = [ "hello" type 1 = ] dip and [ [ 1 2 ] type 2 = ] dip and if [ drop drop drop " type PASS" puts cr ] [ drop drop drop " type FAIL" puts cr ] 42 isnum [ "hello" isnum not ] dip and [ [ 1 2 ] isnum not ] dip and if [ drop drop drop " isnum PASS" puts cr ] [ drop drop drop " isnum FAIL" puts cr ] "hello" isstr [ 42 isstr not ] dip and [ [ 1 2 ] isstr not ] dip and if [ drop drop drop " isstr PASS" puts cr ] [ drop drop drop " isstr FAIL" puts cr ] [ 1 2 ] isquot [ 42 isquot not ] dip and [ "hello" isquot not ] dip and if [ drop drop drop " isquot PASS" puts cr ] [ drop drop drop " isquot FAIL" puts cr ] "Testing binary predicates..." puts cr 5 3 > 3 5 > not and 3 5 < and 5 3 < not and 5 5 >= and 5 3 >= and 3 5 >= not and 5 5 <= and 3 5 <= and 5 3 <= not and 5 5 = and 5 3 = not and 5 3 != and 5 5 != not and if [ " binary predicates PASS" puts cr ] [ " binary predicates FAIL" puts cr ] "Testing streq and vlen..." puts cr "abc" "abc" streq "abc" "abd" streq not and "abc" "ab" streq not and "abc" vlen 3 = and [ 1 2 3 4 ] vlen 4 = and if [ " streq and vlen PASS" puts cr ] [ " streq and vlen FAIL" puts cr ] # 7. String Operations "Testing string operations..." puts cr "abc" slen 3 = if [ "" slen 0 = if [ 5 slen 0 = if [ " slen PASS" puts cr ] [ " slen FAIL" puts cr ] ] [ " slen FAIL" puts cr ] ] [ " slen FAIL" puts cr ] # Test slen 65 chr uncons 1 = if [ 65 = if [ uncons 0= if [ drop " chr PASS" puts cr ] [ drop " chr FAIL" puts cr ] ] [ " chr FAIL" puts cr ] ] [ " chr FAIL" puts cr ] # Test chr "A" asc 65 = if [ " asc PASS" puts cr ] [ " asc FAIL" puts cr ] # Test asc "a\"b" slen 3 = if [ "a\"b" uncons drop drop uncons drop swap drop 34 = if [ " backslash quote escape PASS" puts cr ] [ " backslash quote escape FAIL" puts cr ] ] [ " backslash quote escape FAIL" puts cr ] # Test escape "a\nb" uncons drop drop uncons drop swap drop 10 = "a\tb" uncons drop drop uncons drop swap drop 9 = and "a\rb" uncons drop drop uncons drop swap drop 13 = and "a\sb" uncons drop drop uncons drop swap drop 32 = and "a\bb" uncons drop drop uncons drop swap drop 8 = and "a\fb" uncons drop drop uncons drop swap drop 12 = and [ " hello " ] i " hello " streq and [ "\shello\s" ] i "\shello\s" streq and if [ " whitespace escape PASS" puts cr ] [ " whitespace escape FAIL" puts cr ] "AbC" lower "abc" streq "aBc" upper "ABC" streq and "abc" "def" s+ "abcdef" streq and "abc" s2l [ 97 98 99 ] streq and if [ " streq, lower, and upper PASS" puts cr ] [ " streq, lower, and upper FAIL" puts cr ] # 8. List Operations "Testing list operations..." puts cr 5 [ 6 ] cons uncons 1 = [ 5 = ] dip and [ [ 6 ] streq ] dip and if [ " cons/uncons PASS" puts cr ] [ " cons/uncons FAIL" puts cr ] # Test cons/uncons 5 [ 6 ] qpush [ 6 5 ] streq if [ " qpush PASS" puts cr ] [ " qpush FAIL" puts cr ] # Test qpush [ 6 5 ] qpop 5 = [ [ 6 ] streq ] dip and if [ " qpop PASS" puts cr ] [ " qpop FAIL" puts cr ] # Test qpop [ 1 2 3 ] qlen 3 = if [ [ ] qlen 0 = if [ 5 qlen 0 = if [ " qlen PASS" puts cr ] [ " qlen FAIL" puts cr ] ] [ " qlen FAIL" puts cr ] ] [ " qlen FAIL" puts cr ] # Test qlen [ 10 20 30 ] 1 qget 20 = if [ [ 10 20 30 ] 0 qget 10 = if [ " qget PASS" puts cr ] [ " qget FAIL" puts cr ] ] [ " qget FAIL" puts cr ] # Test qget 99 [ 10 20 30 ] 1 qset [ 10 99 30 ] streq if [ " qset PASS" puts cr ] [ " qset FAIL" puts cr ] # Test qset [ 1 2 3 ] rev [ 3 2 1 ] streq [ 1 2 ] [ 3 4 ] lcat [ 1 2 3 4 ] streq and [ 1 2 ] s2l [ 1 2 ] streq and if [ " rev, lcat and s2l PASS" puts cr ] [ " rev, lcat and s2l FAIL" puts cr ] # 9. Bitwise Operations "Testing bitwise operations..." puts cr 0 bitnot -1 = -1 bitnot 0 = and 3 5 bitand 1 = and 3 5 bitor 7 = and 3 5 bitxor 6 = and if [ " bitwise PASS" puts cr ] [ " bitwise FAIL" puts cr ] # 10. Word Definition "Testing definition words..." puts cr "my_const" [ 99 ] defw my_const 99 = if [ " defw (no-inline) PASS" puts cr ] [ " defw (no-inline) FAIL" puts cr ] # Test defw :: my_inline [ 100 ] my_inline 100 = if [ " :: (inline) PASS" puts cr ] [ " :: (inline) FAIL" puts cr ] # Test inline ::