summaryrefslogtreecommitdiffstats
path: root/tests/012/parse.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-20 09:07:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-20 09:07:45 -0700
commita9835d6c37d2a3c762c4620294d0b2a13d543ccb (patch)
tree7089aff7f2d274ed013115f4152ac311f79c21ea /tests/012/parse.tl
parent7c34d91f30e5a77bc12b811f6c836cea71905529 (diff)
downloadtxr-a9835d6c37d2a3c762c4620294d0b2a13d543ccb.tar.gz
txr-a9835d6c37d2a3c762c4620294d0b2a13d543ccb.tar.bz2
txr-a9835d6c37d2a3c762c4620294d0b2a13d543ccb.zip
read/get-json: reject trailing junk in string input.
* parser.c (lisp_parse_impl): If parsing from string, check for trailing junk and diagnose. JSON parsing doesn't use lookahead because it doesn't have a.b syntax, so the recent_tok gives the last token that actually went into the syntax, and not a lookahead token. So in the case of JSON, we call yylex to see if there is any trailing token. * tests/010/json.tl: Extend get-json tests to more kinds of objects, and then replicate with trailing whitespace and trailing junk to provide coverage for these cases. * tests/012/parse.t: Slew of new read tests and iread also. * txr.1: Documented.
Diffstat (limited to 'tests/012/parse.tl')
-rw-r--r--tests/012/parse.tl52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/012/parse.tl b/tests/012/parse.tl
index 2bce20dc..6d091b00 100644
--- a/tests/012/parse.tl
+++ b/tests/012/parse.tl
@@ -12,3 +12,55 @@
(test (regex-parse (str-buf #b'F3FF'))
(compound #\xDCF3 #\xDCFF)))
+
+(mtest
+ (read "0") 0
+ (read "0x") 0x
+ (read "a") a
+ (read "abc") abc
+ (read "abc.def") abc.def
+ (read "(1 2 3)") (1 2 3)
+ (read "#;(1 2 3) 4") 4
+ (read "#;(1 2 3) #; a.b 4") 4
+ (read "0 ") 0
+ (read "0x ") 0x
+ (read "a ") a
+ (read "abc ") abc
+ (read "abc.def ") abc.def
+ (read "(1 2 3) ") (1 2 3)
+ (read "#;(1 2 3) 4 ") 4
+ (read "#;(1 2 3) #; a.b 4 ") 4
+ (read "0,") :error
+ (read "0x,") :error
+ (read "a,") :error
+ (read "abc,") :error
+ (read "abc.def,") :error
+ (read "(1 2 3),") :error
+ (read "#;(1 2 3) 4,") :error
+ (read "#;(1 2 3) #; a.b 4,") :error)
+
+(mtest
+ (iread "0") 0
+ (iread "0x") 0x
+ (iread "a") a
+ (iread "abc") abc
+ (iread "abc.def") abc
+ (iread "(1 2 3)") (1 2 3)
+ (iread "#;(1 2 3) 4") 4
+ (iread "#;(1 2 3) #; a.b 4") .b
+ (iread "0 ") 0
+ (iread "0x ") 0x
+ (iread "a ") a
+ (iread "abc ") abc
+ (iread "abc.def ") abc
+ (iread "(1 2 3) ") (1 2 3)
+ (iread "#;(1 2 3) 4 ") 4
+ (iread "#;(1 2 3) #; a.b 4 ") .b
+ (iread "0,") 0
+ (iread "0x,") 0x
+ (iread "a,") a
+ (iread "abc,") abc
+ (iread "abc.def,") abc
+ (iread "(1 2 3),") (1 2 3)
+ (iread "#;(1 2 3) 4,") 4
+ (iread "#;(1 2 3) #; a.b 4,") .b)