summaryrefslogtreecommitdiff
path: root/tests/parser/tokens.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-21 17:09:31 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-21 17:09:31 +0100
commit78da2bdd5d77d1b8572e5e9da119bfa68127a3fa (patch)
tree020c8c39268690d34226eb7e33e75f86304988d6 /tests/parser/tokens.rs
parent1c1c994c46f7dc30ee34dbc99b02f2342c4617f3 (diff)
Decoupled function parser 🔗 [WIP]
Diffstat (limited to 'tests/parser/tokens.rs')
-rw-r--r--tests/parser/tokens.rs123
1 files changed, 60 insertions, 63 deletions
diff --git a/tests/parser/tokens.rs b/tests/parser/tokens.rs
index fb48b32e..66e44ac5 100644
--- a/tests/parser/tokens.rs
+++ b/tests/parser/tokens.rs
@@ -1,80 +1,77 @@
// Whitespace.
t "" => []
-t " " => [W(0)]
-t " " => [W(0)]
-t "\t" => [W(0)]
-t " \t" => [W(0)]
-t "\n" => [W(1)]
-t "\n " => [W(1)]
-t " \n" => [W(1)]
-t " \n " => [W(1)]
-t " \n\t \n " => [W(2)]
-t "\r\n" => [W(1)]
-t " \r\r\n \x0D" => [W(3)]
-t "\n\r" => [W(2)]
+t " " => [S(0)]
+t " " => [S(0)]
+t "\t" => [S(0)]
+t " \t" => [S(0)]
+t "\n" => [S(1)]
+t "\n " => [S(1)]
+t " \n" => [S(1)]
+t " \n " => [S(1)]
+t " \n\t \n " => [S(2)]
+t "\r\n" => [S(1)]
+t " \r\r\n \x0D" => [S(3)]
+t "\n\r" => [S(2)]
// Comments.
-t "a // bc\n " => [T("a"), W(0), LC(" bc"), W(1)]
-t "a //a//b\n " => [T("a"), W(0), LC("a//b"), W(1)]
-t "a //a//b\r\n" => [T("a"), W(0), LC("a//b"), W(1)]
-t "a //a//b\n\nhello" => [T("a"), W(0), LC("a//b"), W(2), T("hello")]
+t "a // bc\n " => [T("a"), S(0), LC(" bc"), S(1)]
+t "a //a//b\n " => [T("a"), S(0), LC("a//b"), S(1)]
+t "a //a//b\r\n" => [T("a"), S(0), LC("a//b"), S(1)]
+t "a //a//b\n\nhello" => [T("a"), S(0), LC("a//b"), S(2), T("hello")]
t "/**/" => [BC("")]
-t "_/*_/*a*/*/" => [U, BC("_/*a*/")]
+t "_/*_/*a*/*/" => [Underscore, BC("_/*a*/")]
t "/*/*/" => [BC("/*/")]
-t "abc*/" => [T("abc"), SS]
+t "abc*/" => [T("abc"), Invalid("*/")]
// Header only tokens.
-t "[" => [LB]
-t "]" => [RB]
-t "[(){}:=,]" => [LB, LP, RP, LBR, RBR, CL, EQ, CM, RB]
-t "[a:b]" => [LB, ID("a"), CL, ID("b"), RB]
-t "[🌓, 🌍,]" => [LB, T("🌓"), CM, W(0), T("🌍"), CM, RB]
-t "[=]" => [LB, EQ, RB]
-t "[,]" => [LB, CM, RB]
-t "a: b" => [T("a"), T(":"), W(0), T("b")]
-t "c=d, " => [T("c"), T("=d"), T(","), W(0)]
-t r#"["hello\"world"]"# => [LB, STR(r#"hello\"world"#), RB]
-t r#"["hi", 12pt]"# => [LB, STR("hi"), CM, W(0), SIZE(Size::pt(12.0)), RB]
-t "\"hi\"" => [T("\"hi"), T("\"")]
-t "[a: true, x=1]" => [LB, ID("a"), CL, W(0), BOOL(true), CM, W(0),
- ID("x"), EQ, NUM(1.0), RB]
-t "[120%]" => [LB, NUM(1.2), RB]
+th "[" => [Func("", None, false)]
+th "]" => [Invalid("]")]
+th "(){}:=," => [LP, RP, LB, RB, Colon, Equals, Comma]
+th "a:b" => [Id("a"), Colon, Id("b")]
+th "=" => [Equals]
+th "," => [Comma]
+th r#""hello\"world""# => [Str(r#"hello\"world"#)]
+th r#""hi", 12pt"# => [Str("hi"), Comma, S(0), Size(12.0)]
+th "\"hi\"" => [T("\"hi"), T("\"")]
+th "a: true, x=1" => [Id("a"), Colon, S(0), Bool(true), Comma, S(0),
+ Id("x"), Equals, Num(1.0)]
+th "120%" => [Num(1.2)]
+th "🌓, 🌍," => [T("🌓"), Comma, S(0), T("🌍"), Comma]
+tb "a: b" => [T("a"), T(":"), S(0), T("b")]
+tb "c=d, " => [T("c"), T("=d"), T(","), S(0)]
// Body only tokens.
-t "_*`" => [U, S, B]
-t "[func]*bold*" => [LB, ID("func"), RB, S, T("bold"), S]
-t "[_*`]" => [LB, T("_"), T("*"), T("`"), RB]
-t "hi_you_ there" => [T("hi"), U, T("you"), U, W(0), T("there")]
+tb "_*`" => [Underscore, Star, Backtick]
+tb "[func]*bold*" => [Func("func", None, true), Star, T("bold"), Star]
+tb "hi_you_ there" => [T("hi"), Underscore, T("you"), Underscore, S(0), T("there")]
+th "_*`" => [Invalid("_"), Invalid("*"), Invalid("`")]
// Nested functions.
-t "[f: [=][*]]" => [LB, ID("f"), CL, W(0), LB, EQ, RB, LB, S, RB, RB]
-t "[_][[,],]," => [LB, T("_"), RB, LB, LB, CM, RB, T(","), RB, T(",")]
-t "[=][=][=]" => [LB, EQ, RB, LB, T("="), RB, LB, EQ, RB]
-t "[=][[=][=][=]]" => [LB, EQ, RB, LB, LB, EQ, RB, LB, T("="), RB, LB, EQ, RB, RB]
+tb "[f: [=][*]]" => [Func("f: [=][*]", None, true)]
+tb "[_][[,],]," => [Func("_", Some("[,],"), true), T(",")]
+tb "[=][=][=]" => [Func("=", Some("="), true), Func("=", None, true)]
+tb "[=][[=][=][=]]" => [Func("=", Some("[=][=][=]")), true]
// Escapes.
-t r"\[" => [T("[")]
-t r"\]" => [T("]")]
-t r"\\" => [T(r"\")]
-t r"\/" => [T("/")]
-t r"\*" => [T("*")]
-t r"\_" => [T("_")]
-t r"\`" => [T("`")]
+tb r"\[" => [T("[")]
+tb r"\]" => [T("]")]
+tb r"\\" => [T(r"\")]
+tb r"\/" => [T("/")]
+tb r"\*" => [T("*")]
+tb r"\_" => [T("_")]
+tb r"\`" => [T("`")]
// Unescapable special symbols.
-t r"\:" => [T(r"\"), T(":")]
-t r"\=" => [T(r"\"), T("=")]
-t r"[\:]" => [LB, T(r"\"), CL, RB]
-t r"[\=]" => [LB, T(r"\"), EQ, RB]
-t r"[\,]" => [LB, T(r"\"), CM, RB]
+th r"\:" => [T(r"\"), T(":")]
+th r"\=" => [T(r"\"), T("=")]
+th r"\:" => [T(r"\"), Colon]
+th r"\=" => [T(r"\"), Equals]
+th r"\," => [T(r"\"), Comma]
-// Spans
-ts "hello" => [(0:0, 0:5, T("hello"))]
-ts "ab\r\nc" => [(0:0, 0:2, T("ab")), (0:2, 1:0, W(1)), (1:0, 1:1, T("c"))]
-ts "[a=10]" => [(0:0, 0:1, LB), (0:1, 0:2, ID("a")), (0:2, 0:3, EQ),
- (0:3, 0:5, NUM(10.0)), (0:5, 0:6, RB)]
-ts r#"[x = "(1)"]*"# => [(0:0, 0:1, LB), (0:1, 0:2, ID("x")), (0:2, 0:3, W(0)),
- (0:3, 0:4, EQ), (0:4, 0:5, W(0)), (0:5, 0:10, STR("(1)")),
- (0:10, 0:11, RB), (0:11, 0:12, S)]
-ts "// ab\r\n\nf" => [(0:0, 0:5, LC(" ab")), (0:5, 2:0, W(2)), (2:0, 2:1, T("f"))]
-ts "/*b*/_" => [(0:0, 0:5, BC("b")), (0:5, 0:6, U)]
+// Spans.
+tbs "hello" => [(0:0, 0:5, T("hello"))]
+tbs "ab\r\nc" => [(0:0, 0:2, T("ab")), (0:2, 1:0, S(1)), (1:0, 1:1, T("c"))]
+tbs "[x = \"(1)\"]*" => [(0:0, 0:11, Func("x = \"(1)\"", None, true)), (0:11, 0:12, Star)]
+tbs "// ab\r\n\nf" => [(0:0, 0:5, LC(" ab")), (0:5, 2:0, S(2)), (2:0, 2:1, T("f"))]
+tbs "/*b*/_" => [(0:0, 0:5, BC("b")), (0:5, 0:6, Underscore)]
+ths "a=10" => [(0:0, 0:1, Id("a")), (0:1, 0:2, Equals), (0:2, 0:4, Num(10.0))]