summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-16 23:00:39 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-16 23:00:39 +0100
commit70878885f5d169f2c5d9e66d3919ee56d5f9f9ca (patch)
treefc4ebbc0f0246edb93e6fde6c816cbca4dc93bef /tests
parent08b91a265fcda74f5463473938ec33873b49a7f7 (diff)
Do argument parsing ☑
Diffstat (limited to 'tests')
-rw-r--r--tests/parser/trees.rs37
-rw-r--r--tests/src/parser.rs12
2 files changed, 34 insertions, 15 deletions
diff --git a/tests/parser/trees.rs b/tests/parser/trees.rs
index 442f71dd..d761fe24 100644
--- a/tests/parser/trees.rs
+++ b/tests/parser/trees.rs
@@ -1,15 +1,19 @@
+// Basics.
p "" => []
p "hi" => [T("hi")]
p "hi you" => [T("hi"), S, T("you")]
p "❤\n\n 🌍" => [T("❤"), N, T("🌍")]
+// Functions.
p "[func]" => [func!("func"; None)]
p "[tree][hi *you*]" => [func!("tree"; Some([T("hi"), S, B, T("you"), B]))]
-
p "from [align: left] to" => [
T("from"), S, func!("align", pos: [ID("left")]; None), S, T("to"),
]
-
+p "[f: left, 12pt, false]" => [
+ func!("f", pos: [ID("left"), SIZE(Size::pt(12.0)), BOOL(false)]; None)
+]
+p "[f: , hi, * \"du\"]" => [func!("f", pos: [ID("hi"), STR("du")]; None)]
p "[box: x=1.2pt, false][a b c] bye" => [
func!(
"box",
@@ -20,14 +24,23 @@ p "[box: x=1.2pt, false][a b c] bye" => [
S, T("bye"),
]
-c "hi" => []
-c "[align: left][\n _body_\n]" => [
- (0:0, 0:1, B),
- (0:1, 0:6, FN),
- (0:6, 0:7, CL),
- (0:8, 0:12, ID),
- (0:12, 0:13, B),
- (0:13, 0:14, B),
- (1:4, 1:10, IT),
- (2:0, 2:2, B),
+// Errors.
+e "[f: , hi, * \"du\"]" => [
+ (0:4, 0:5, "expected value, found comma"),
+ (0:10, 0:11, "expected value, found invalid identifier"),
+]
+e "[f:, , ,]" => [
+ (0:3, 0:4, "expected value, found comma"),
+ (0:5, 0:6, "expected value, found comma"),
+ (0:7, 0:8, "expected value, found comma"),
+]
+e "[f:" => [(0:3, 0:3, "expected closing bracket")]
+e "[f: hi" => [(0:6, 0:6, "expected closing bracket")]
+e "[f: hey 12pt]" => [(0:7, 0:7, "expected comma")]
+e "[box: x=, false y=z=4" => [
+ (0:8, 0:9, "expected value, found comma"),
+ (0:15, 0:15, "expected comma"),
+ (0:19, 0:19, "expected comma"),
+ (0:19, 0:20, "expected value, found equals sign"),
+ (0:21, 0:21, "expected closing bracket"),
]
diff --git a/tests/src/parser.rs b/tests/src/parser.rs
index ecf1544c..b2aa01da 100644
--- a/tests/src/parser.rs
+++ b/tests/src/parser.rs
@@ -40,7 +40,7 @@ fn test(tests: Vec<(&str, Vec<Case>)>) {
Case::Okay => okay += 1,
Case::Failed { line, src, expected, found } => {
println!();
- println!(" - Case failed in file {}.rs in line {}.", file, line);
+ println!(" ❌ Case failed in file {}.rs in line {}.", file, line);
println!(" - Source: {:?}", src);
println!(" - Expected: {}", expected);
println!(" - Found: {}", found);
@@ -119,7 +119,11 @@ macro_rules! case {
});
(e $src:expr, [$($e:tt)*]) => ({
- let expected = ErrorMap { errors: list!([$($e)*]) };
+ let errors = list!([$($e)*]).into_iter()
+ .map(|s| s.map(|m| m.to_string()))
+ .collect();
+
+ let expected = ErrorMap { errors };
let found = parse($src, ParseContext { scope: &scope() }).2;
(expected == found, expected, found)
});
@@ -204,8 +208,10 @@ function! {
}
parse(header, body, ctx) {
+ let cloned = header.clone();
+ header.args.clear();
DebugFn {
- header: header.clone(),
+ header: cloned,
body: parse!(optional: body, ctx),
}
}