scripts/test.hex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
#!/usr/bin/env hex 0x0 "test-count" : 0x0 "successes" : 0x0 "failures" : () "errors" : () "fails" : 0x0 "result" : (dup puts) "_" :: ( "current-test" : test-count 0x1 + "test-count" : ( (current-test .) ( "." print successes 0x1 + "successes" : ) ( "x" print failures 0x1 + "failures" : fails test-count dec ' cat "fails" : ) if ) ( ; Store error errors " - Test #" test-count dec cat ": " cat error cat ' cat "errors" : "x" print failures 0x1 + "failures" : fails test-count dec ' cat "fails" : ) try ) "test" : ; --- Define tests ( (0x1 "a" : a 0x1 ==) ("a" # 0x1) ("aaa" type "string" == 0x1 type "integer" == () type "quotation" == and and) ((0x1 0x2 +) . 0x3 ==) ;4 ("0x2 0x2 -" ! 0x0 ==) (0x4 0x5 + 0x9 ==) (0x5 0x3 - 0x2 ==) (0x5 0x2 * 0xa ==) ;8 (0x5 0x2 / 0x2 ==) (0x4 0x2 % 0x0 ==) (0x10101 0x01010 & 0x0 ==) (0x10111 0x01000 | 0x11111 ==) ;12 (0x1 0x1 ^ 0x0 ==) (0x1 ~ 0xfffffffe ==) (0x1 0x4 << 0x10 ==) (0x10 0x4 >> 0x1 ==) ;16 ("10" int 0x10 ==) (0x10 str "10" ==) (0xa dec "10" ==) ("10" hex 0xa ==) ;20 ("aaa" "aaa" ==) (0x20 0x20 ==) (0x21 0x22 !=) ("abba" "aaa" !=) ;24 (0x2 0x1 >) (0x2 0x2 >=) (0x2 0x3 <) (0x3 0x3 <=) ;28 (0x2 0x3 and) (0x1 0x0 or) (0x1 0x0 xor) (0x1 0x1 xor not) ;32 ("hello" " world" cat "hello world" ==) ((0x1 "a") ("b") cat (0x1 "a" "b") ==) ((() not) (error) try "[symbol not] Integer required" ==) ((() 0x1 xor) (error) try "[symbol xor] Two integers required" ==) ;36 ("aaaaa" len 0x5 ==) ((0x1 0x3 puts "aaa") len 0x4 ==) ((0x2 0x3 0x4) 0x2 get 0x4 ==) ("abcde" 0x1 get "b" ==) ;40 ("a/b/c" "t-path" : (t-path "/" index 0x0 >=) (t-path "/" "\\" replace "t-path" :) while t-path "a\\b\\c" == "t-path" #) ("assets\"" "\"" "/" replace "assets/" ==) (("" () cat) (error) try "[symbol cat] Two quotations or two strings required" ==) ((0x4 len) (error) try "[symbol len] Quotation or string required" ==) ;44 ("this is a test" "is" index 0x2 ==) (("a" 0x1 "b") "b" index 0x2 ==) ("abc" "d" index 0xffffffff ==) (("0" "0" "0" "0") "." join "0.0.0.0"==) ;48 ("0.0.0.0" "." split ("0" "0" "0" "0") ==) ("Hello, World!" "Hello" "Goodbye" replace "Goodbye, World!" ==) ("test" "test.txt" write "test.txt" read "test" ==) ("!" "test.txt" append "test.txt" read "test!" ==) ;52 ("rm test.txt" exec 0x0 ==) ("rm test.txt" run 0x0 get 0x1 ==) ("ls web/contents" run 0x1 get "\n" split len 0x7 ==) (args 0x1 get "scripts/test.hbx" ==) ;56 ((args len 0x2 ==) ("two") ("no") if "two" ==) ((args len 0x3 !=) ("yes") when "yes" ==) (0x1 "tmp-a" : (tmp-a 0x3 <) (tmp-a 0x1 + "tmp-a" :) while tmp-a 0x3 ==) (0x0 "tmp-b" : (0x1 0x2 0x3) (tmp-b + "tmp-b" :) each tmp-b 0x6 ==) ;60 ((0x2 0x0 /) (error "[symbol /] Division by zero" ==) try) (error "" ==) ("a" ' ' ' ((("a"))) ==) ((0x1 0x2 0x3) (dup dup * *) map (0x1 0x8 0x1b) ==) ;64 (0x2 dup stack (0x2 0x2) ==) (clear stack () ==) (0x1 0x2 swap pop stack (0x2) ==) ;68 (("aaa" "puts" :) (error) try "[symbol :] Failed to store symbol 'puts'" ==) (("puts" #) (error) try "[symbol #] Cannot free native symbol 'puts'" ==) (("aaa" 0x2 :) (error) try "[symbol :] Symbol name must be a string" ==) ((0x2 #) (error) try "[symbol #] Symbol name must be a string" ==) ;72 (("puts" .) (error) try "[symbol .] Quotation required" ==) (((puts) !) (error) try "[symbol !] Quotation must contain only integers" ==) (("3" 0x3 +) (error) try "[symbol +] Two integers required" ==) (("3" 0x3 -) (error) try "[symbol -] Two integers required" ==) ;76 ((0x2 0x3 0x3) (0x2 0x3) > 0x1 ==) ((0x2 0x3) (0x2 0x1) > 0x1 ==) ((test abc) (test cde) < 0x1 ==) (("test" "abc") ("test" "abc") <= 0x1 ==) ;80 ("hello" "" split ("h" "e" "l" "l" "o") ==) (("3" 0x3 /) (error) try "[symbol /] Two integers required" ==) ((0x4 0x0 %) (error) try "[symbol %] Division by zero" ==) ((() 0x3 %) (error) try "[symbol %] Two integers required" ==) ;84 ((() 0x3 &) (error) try "[symbol &] Two integers required" ==) ((0x2 "" |) (error) try "[symbol |] Two integers required" ==) ((() "" ^) (error) try "[symbol ^] Two integers required" ==) ((() 0x1 >>) (error) try "[symbol >>] Two integers required" ==) ;88 ((() 0x1 <<) (error) try "[symbol <<] Two integers required" ==) (("" ~) (error) try "[symbol ~] Integer required" ==) ((0x5 int) (error) try "[symbol int] String representing a hexadecimal integer required" ==) (((0x3) int) (error) try "[symbol int] String representing a hexadecimal integer required" ==) ;92 (("5" str) (error) try "[symbol str] Integer required" ==) ((("aaa") str) (error) try "[symbol str] Integer required" ==) (("10" dec) (error) try "[symbol dec] Integer required" ==) ((0x5 hex) (error) try "[symbol hex] String representing a decimal integer required" ==) ;96 ("0x2" 0x2 == 0x0 ==) ("0x2" (0x2) !=) ((0x3 "aaa") ("aaa" 0x5) > 0x0 ==) (("aaa" 0x5) ("aaa" 0x5 0x4) >= 0x0 ==) ;100 ((test "aaa") (test "aaa" 0x5) < 0x1 ==) (("aaa" 0x5) ("" "aaa" 0x5) <= 0x1 ==) (("a" "b" and) (error) try "[symbol and] Two integers required" ==) ((0x1 "a" or) (error) try "[symbol or] Two integers required" ==) ;104 (("abc" 0x3 get) (error) try "[symbol get] Index out of range" ==) (((0x2) 0x2 get) (error) try "[symbol get] Index out of range" ==) ((() 0x0 get) (error) try "[symbol get] Index out of range" ==) ((0x4 0x4 get) (error) try "[symbol get] Quotation or string required" ==) ;108 (("abc" "b" get) (error) try "[symbol get] Index must be an integer" ==) (((0x4 "aa" test) "b" get) (error) try "[symbol get] Index must be an integer" ==) ("a" ord 0x61 ==) (0x61 chr "a" ==) ;112 ("=" ord 0x3d ==) (0x3d chr "=" ==) (0xffffffff dec "-1" ==) (0x80 chr "" ==) ;116 ("abc" ord 0xffffffff ==) ((0x56 ord) (error) try "[symbol ord] String required" ==) (("t" chr) (error) try "[symbol chr] Integer required" ==) ((() chr) (error) try "[symbol chr] Integer required" ==) ;120 ((dup *) "square" :: 0x2 square 0x4 == "square" #) ) "tests" : ; --- Run tests tests (test .) each ; --- Report "\nSuccessful Tests: " print successes dec print "/" print successes failures + dec puts (errors len 0x0 >) ( "Errors:" warn errors (warn) each 0x1 "result" : ) when (fails len 0x0 >) ( "Failed Tests: " fails ", " join cat warn 0x1 "result" : ) when result exit |