1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/tests/step1_read_print.mal
Dov Murik 539427f0db nim: fix tokenizer endless loop (and out-of-memory) on bad input
The input string `(prn "abc` caused the nim implementaion (from step1
onwards) to enter an endless loop in tokenize (which eventually caused
out-of-memory).

The fix verfies that indeed the regex matches a non-empty substring
before adding that substring as a token.
2015-12-04 15:35:39 -05:00

139 lines
1.8 KiB
Plaintext

;; Testing read of nil/true/false
nil
;=>nil
true
;=>true
false
;=>false
;; Testing read of numbers
1
;=>1
7
;=>7
7
;=>7
;; Testing read of symbols
+
;=>+
abc
;=>abc
abc
;=>abc
abc5
;=>abc5
abc-def
;=>abc-def
;; Testing read of strings
"abc"
;=>"abc"
"abc"
;=>"abc"
"abc (with parens)"
;=>"abc (with parens)"
"abc\"def"
;=>"abc\"def"
;;;"abc\ndef"
;;;;=>"abc\ndef"
""
;=>""
;; Testing read of lists
(+ 1 2)
;=>(+ 1 2)
((3 4))
;=>((3 4))
(+ 1 (+ 2 3))
;=>(+ 1 (+ 2 3))
( + 1 (+ 2 3 ) )
;=>(+ 1 (+ 2 3))
(* 1 2)
;=>(* 1 2)
(** 1 2)
;=>(** 1 2)
;; Test commas as whitespace
(1 2, 3,,,,),,
;=>(1 2 3)
;; Testing read of quoting
'1
;=>(quote 1)
'(1 2 3)
;=>(quote (1 2 3))
`1
;=>(quasiquote 1)
`(1 2 3)
;=>(quasiquote (1 2 3))
~1
;=>(unquote 1)
~(1 2 3)
;=>(unquote (1 2 3))
~@(1 2 3)
;=>(splice-unquote (1 2 3))
;;
;; Testing reader errors
;;; TODO: fix these so they fail correctly
(1 2
; expected ')', got EOF
[1 2
; expected ']', got EOF
"abc
; expected '"', got EOF
(1 "abc
; expected ')', got EOF
;;
;; -------- Optional Functionality --------
;; Testing keywords
:kw
;=>:kw
(:kw1 :kw2 :kw3)
;=>(:kw1 :kw2 :kw3)
;; Testing read of vectors
[+ 1 2]
;=>[+ 1 2]
[[3 4]]
;=>[[3 4]]
[+ 1 [+ 2 3]]
;=>[+ 1 [+ 2 3]]
[ + 1 [+ 2 3 ] ]
;=>[+ 1 [+ 2 3]]
;; Testing read of hash maps
{"abc" 1}
;=>{"abc" 1}
{"a" {"b" 2}}
;=>{"a" {"b" 2}}
{"a" {"b" {"c" 3}}}
;=>{"a" {"b" {"c" 3}}}
{ "a" {"b" { "cde" 3 } }}
;=>{"a" {"b" {"cde" 3}}}
{ :a {:b { :cde 3 } }}
;=>{:a {:b {:cde 3}}}
;; Testing read of comments
;; whole line comment (not an exception)
1 ; comment after expression
;=>1
1; comment after expression
;=>1
;; Testing read of ^/metadata
^{"a" 1} [1 2 3]
;=>(with-meta [1 2 3] {"a" 1})
;; Testing read of @/deref
@a
;=>(deref a)