tests/global.min
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
'min-test require :test ;;; "global" *test/describe (2 'a define (3 a + (5 'a define a) -> +) -> a + 12 ==) *test/assert (symbols "a" in? false ==) *test/assert ('abcdefg defined-symbol? false ==) *test/assert 5 :five (symbols "five" in?) *test/assert ( (1 2 3 4 5 6) :test-data ( :item "_$1" (item) => % :namesym item (dup *) cons namesym define namesym ROOT publish ) :def test-data def foreach _2 -> _5 -> _1 -> + + 30 == ) *test/assert ( (dup *) ^square 3 square 9 == ) *test/assert 'five delete-symbol (symbols "five" in? false ==) *test/assert ("3 4 +" eval 7 ==) *test/assert ("2 2 +" "tests/testload.min" fwrite 'testload load 4 ==) *test/assert "tests/testload.min" rm ("2 :two 3 :three" "tests/testrequire.min" fwrite 'testrequire require :tm *tm/two *tm/three + 5 ==) *test/assert "tests/testrequire.min" rm (2 quote (2) ==) *test/assert ((2 3) dequote get-stack (2 3) ==) *test/assert (3 (succ) 3 times 6 ==) *test/assert ((2 3 >) ("YES") ("NO") if "NO" ==) *test/assert ((2 3 <) ("YES") ("NO") if "YES" ==) *test/assert ("NO" (2 3 >) ("YES") when "NO" ==) *test/assert ((2 3 <) ("YES") when "YES" ==) *test/assert ((2 3 >) ("YES") unless "YES" ==) *test/assert (1 type "int" ==) *test/assert ({} type "dict" ==) *test/assert (ROOT type "dict:module" ==) *test/assert (5 (dup 0 ==) (1 +) (dup 1 -) ( * ) linrec 120 ==) *test/assert ;factorial of 5 ( ( (pop) ('error dget) ("finally") ) try get-stack ("MinEmptyStackError" "finally") ==) *test/assert ("aaaa" :cd cd "aaaa" ==) *test/assert ;It is possible to shadow sealed symbols in child scopes (((2 :a1 'a1 seal-symbol 3 :a1) ("failed")) try "failed" ==) *test/assert ( 1 :a1 'a1 seal-symbol 'a1 unseal-symbol 2 :a1 2 a1 ==) *test/assert ( ( ({"TestError" :error "Test Message" :message} raise) (/error) ) try "TestError" ==) *test/assert ( (("test" °test :)) try get-stack ("test") ==) *test/assert ( ( (() 1 get) (1) ) try 1 ==) *test/assert ((a b +) {4 :a 5 :b} with 9 ==) *test/assert ("{\"a\": 1, \"b\": 2.3}" from-json {1 :a 2.3 :b} ==) *test/assert ((1 2 3 "aaa" 'q q true) to-json "\r\n" "" replace "\n" "" replace " " "" replace "[1,2,3,\"aaa\",\";sym:'q\",\";sym:q\",true]" ==) *test/assert ((1 2 3 "aaa" 'q q true) to-json from-json (1 2 3 "aaa" 'q q true) ==) *test/assert (((1 2 3)) :sym1 >sym1 saved-symbols "sym1" in?) *test/assert (<sym1 symbols "sym1" in?) *test/assert ('sym1 remove-symbol saved-symbols "sym1" in? false ==) *test/assert (0 :temp (1 2 3) (temp + @temp) foreach 6 temp ==) *test/assert ( (1 +) ^mysucc 'mysucc source (1 +) ==) *test/assert (6 ( ((3 ==) (false)) ((3 <) (false)) ((3 >) (true)) ) case ) *test/assert (time scope-symbols ("datetime" "now" "tformat" "timeinfo" "timestamp" "to-timestamp") ==) *test/assert (sys scope-sigils ("!" "$" "&") ==) *test/assert ({3 :a 5 :b} scope-symbols ("a" "b") ==) *test/assert (dev?) ((opts {true :d} ==) *test/assert) ((opts {} ==) *test/assert) if (args first "\.min$" match?) *test/assert (3 string "3" ==) *test/assert ("false" boolean false ==) *test/assert ("" boolean false ==) *test/assert (0 boolean false ==) *test/assert (false boolean false ==) *test/assert (0.0 boolean false ==) *test/assert ("something" boolean true ==) *test/assert ("345" integer 345 ==) *test/assert (true integer 1 ==) *test/assert (3.5 integer 3 ==) *test/assert (3.5 float 3.5 ==) *test/assert (3 float 3.0 ==) *test/assert (false float 0.0 ==) *test/assert ("3.678" float 3.678 ==) *test/assert ( {1 :a 2 :b 3 :c} ( (dup /a succ succ %a) (dup /b succ %b) ) tap {3 :a 3 :b 3 :c} == ) *test/assert ( {} :data data ( 1 %a 2 %b ) tap {1 :a 2 :b} == ) *test/assert ( "" :s1 "test" ( (' "1" swap append "" join) (' "2" swap append "" join) (' "3" swap append "" join @s1 s1) ) tap! s1 "test123" == ) *test/assert (3.4 "test" 1 (int str num) expect (3.4 "test" 1) ==) *test/assert ("aaa bbb ccc 2 2 + (2 3 4)" parse (aaa bbb ccc 2 2 + (2 3 4)) ==) *test/assert ({} :myscope (2 :two 3 :three scope @myscope) -> myscope scope-symbols ("three" "two") ==) *test/assert ((2 < 3 and (4 > 2)) >< true) *test/assert ((float 3) >> 3.0 ==) *test/assert ( ( sigil del (str :in ==> str :out) (in "--" suffix "--" prefix @out) ) :: del"test" "--test--" == ) *test/assert ( ( sigil x (str :in ==> str :out) (in "x" prefix @out) ) :: 'x unseal-sigil 'x delete-sigil 'x defined-sigil? false == ) *test/assert ( {{100 :b} :a} :test *test/a/b 100 == ) *test/assert ( ( symbol pow-mul (num :base int :exp ==> num :pr num :mr) ( exp 1 - :n base exp * @mr base (dup) n times (*) n times @pr ) ) operator 2 4 pow-mul - 8 == ) *test/assert ( ( sigil nt (str :s ==> bool :result) ( ("int" s ==) (true @result return) when ("num" s ==) (true @result return) when ("flt" s ==) (true @result return) when "not gonna be printed if true!" puts false @result ) ) :: nt"flt" ) *test/assert ; (:n ((n integer?) (n 0 >)) &&) 'natural typeclass ( typeclass natural (int :n ==> bool :out) (((n integer?) (n 0 >)) && @out) ) :: ("typeclass:natural" defined-symbol?) *test/assert ( symbol natural-sum (natural :n natural :m ==> natural :result) (n m + @result) ) :: (dev?) ( null :err ( (3 -3 natural-sum) (@err) ) try pop ;Remove 3 that was left on the stack. (err format-error "expected: natural natural natural-sum" match?) *test/assert (2 3 natural-sum 5 ==) *test/assert ) when ( constructor test-c (str :in ==> dict :out) ( {} in %test @out ) ) :: ("aaa" test-c 'dict:test-c type?) *test/assert ( symbol add ((str|num|quot :t) :a t :b ==> t :result) ( (a type "str" ==) (a b suffix @result return) when (a type "num" ==) (a b + @result return) when (a type "quot" ==) (a b concat @result return) when ) ) :: ("a" "b" add "ab" ==) *test/assert ((1 2 3) (4 5) add (1 2 3 4 5) ==) *test/assert (typeclass fiveplus (int :n ==> bool :o) ( n 5 > @o ) ) :: (typeclass tenminus (int :n ==> bool :o) ( n 10 < @o ) ) :: (typeclass even (int :n ==> bool :o) ( n 2 mod 0 == @o ) ) :: ( 'tenminus&fiveplus 'five-to-ten typealias (symbol test (!even|five-to-ten :n ==> bool :o) ( true @o ) ) :: 6 test 11 test and ) *test/assert *test/report ; Tidy up clear-stack |