diff --git a/src/parse/tests.rs b/src/parse/tests.rs index a8e9dc256..bb102476d 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -168,18 +168,6 @@ macro_rules! Array { }; } -macro_rules! Dict { - (@$($name:expr => $expr:expr),* $(,)?) => { - vec![$(Named { - name: into!($name).map(|s: &str| Ident(s.into())), - expr: into!($expr) - }),*] - }; - ($($tts:tt)*) => { - Expr::Dict(Dict![@$($tts)*]) - }; -} - macro_rules! Template { (@$($node:expr),* $(,)?) => { vec![$(into!($node)),*] @@ -395,85 +383,6 @@ fn test_parse_arguments() { errors: [S(3..6, "expected identifier")]); } -#[test] -fn test_parse_arrays() { - // Empty array. - t!("{()}" Block!(Array![])); - - // Array with one item and trailing comma + spans. - t!("{-(1,)}" - nodes: [S(0..7, Block!(Unary( - S(1..2, Neg), - S(2..6, Array![S(3..4, Int(1))]) - )))], - spans: true); - - // Array with three items and trailing comma. - t!(r#"{("one", 2, #003,)}"# Block!(Array![ - Str("one"), - Int(2), - Color(RgbaColor::new(0, 0, 0x33, 0xff)) - ])); - - // Unclosed. - t!("{(}" - nodes: [Block!(Array![])], - errors: [S(2..2, "expected closing paren")]); - - // Missing comma + invalid token. - t!("{(1*/2)}" - nodes: [Block!(Array![Int(1), Int(2)])], - errors: [S(3..5, "expected expression, found end of block comment"), - S(3..3, "expected comma")]); - - // Invalid token. - t!("{(1, 1u 2)}" - nodes: [Block!(Array![Int(1), Int(2)])], - errors: [S(5..7, "expected expression, found invalid token")]); - - // Coerced to expression with leading comma. - t!("{(,1)}" - nodes: [Block!(Group(Int(1)))], - errors: [S(2..3, "expected expression, found comma")]); - - // Missing expression after name makes this an array. - t!("{(a:)}" - nodes: [Block!(Array![])], - errors: [S(4..4, "expected expression")]); - - // Expected expression, found named pair. - t!("{(1, b: 2)}" - nodes: [Block!(Array![Int(1)])], - errors: [S(5..9, "expected expression, found named pair")]); -} - -#[test] -fn test_parse_dictionaries() { - // Empty dictionary. - t!("{(:)}" Block!(Dict![])); - - // Dictionary with two pairs + spans. - t!("{(one: 1, two: 2)}" - nodes: [S(0..18, Block!(Dict![ - S(2..5, "one") => S(7..8, Int(1)), - S(10..13, "two") => S(15..16, Int(2)), - ]))], - spans: true); - - // Expected named pair, found expression. - t!("{(a: 1, b)}" - nodes: [Block!(Dict!["a" => Int(1)])], - errors: [S(8..9, "expected named pair, found expression")]); - - // Dictionary marker followed by more stuff. - t!("{(:1 b:[], true::)}" - nodes: [Block!(Dict!["b" => Template![]])], - errors: [S(3..4, "expected named pair, found expression"), - S(4..4, "expected comma"), - S(11..15, "expected identifier"), - S(16..17, "expected expression, found colon")]); -} - #[test] fn test_parse_expressions() { // Parentheses. diff --git a/tests/ref/arrays.png b/tests/ref/arrays.png new file mode 100644 index 000000000..4a95278c0 Binary files /dev/null and b/tests/ref/arrays.png differ diff --git a/tests/ref/dictionaries.png b/tests/ref/dictionaries.png new file mode 100644 index 000000000..a34b45e07 Binary files /dev/null and b/tests/ref/dictionaries.png differ diff --git a/tests/typ/arrays.typ b/tests/typ/arrays.typ new file mode 100644 index 000000000..adab2ad93 --- /dev/null +++ b/tests/typ/arrays.typ @@ -0,0 +1,37 @@ +// Empty. +{()} + +// One item and trailing comma. +{(-1,)} + +// No trailing comma. +{(true, false)} + +// Multiple lines and items and trailing comma. +{("one" + , 2 + , #003 + ,)} + +--- +// Test errors. +// +// error: 2:3-2:3 expected closing paren +// error: 4:4-4:6 expected expression, found end of block comment +// error: 4:4-4:4 expected comma +// error: 6:6-6:8 expected expression, found invalid token +// error: 8:3-8:4 expected expression, found comma +// error: 10:5-10:5 expected expression +// error: 12:6-12:10 expected expression, found named pair + +{(} + +{(1*/2)} + +{(1, 1u 2)} + +{(,1)} + +{(a:)} + +{(1, b: 2)} diff --git a/tests/typ/dictionaries.typ b/tests/typ/dictionaries.typ new file mode 100644 index 000000000..51e3eb3c2 --- /dev/null +++ b/tests/typ/dictionaries.typ @@ -0,0 +1,18 @@ +// Empty +{(:)} + +// Two pairs. +{(one: 1, two: 2)} + +--- +// Test errors. +// +// error: 2:9-2:10 expected named pair, found expression +// error: 4:4-4:5 expected named pair, found expression +// error: 4:5-4:5 expected comma +// error: 4:12-4:16 expected identifier +// error: 4:17-4:18 expected expression, found colon + +{(a: 1, b)} + +{(:1 b:[], true::)}