diff --git a/crates/json-pawarser/src/grammar/array.rs b/crates/json-pawarser/src/grammar/array.rs index 18d4d2c..3ae1726 100644 --- a/crates/json-pawarser/src/grammar/array.rs +++ b/crates/json-pawarser/src/grammar/array.rs @@ -34,3 +34,19 @@ pub(super) fn array(p: &mut Parser) -> Option { array_start.complete(p, SyntaxKind::ARRAY) }) } + +#[cfg(test)] +mod tests { + use crate::grammar::{array::array, test_utils::gen_checks}; + + #[test] + fn array_basic() { + gen_checks! {array; + r#"[1,2,3]"# => r#"ROOT { ARRAY { BRACKET_OPEN "["; ELEMENT { NUMBER "1"; } COMMA ","; ELEMENT { NUMBER "2"; } COMMA ","; ELEMENT { NUMBER "3"; } BRACKET_CLOSE "]"; } }"#, + r#"[1,2,]"# => r#"ROOT { ARRAY { BRACKET_OPEN "["; ELEMENT { NUMBER "1"; } COMMA ","; ELEMENT { NUMBER "2"; } TRAILING_COMMA { COMMA ","; } BRACKET_CLOSE "]"; } }"#, + r#"[1,2"# => r#"ROOT { PARSE_ERR: UnclosedArray { BRACKET_OPEN "["; ELEMENT { NUMBER "1"; } COMMA ","; ELEMENT { NUMBER "2"; } } }"#, + r#"[1,2,"# => r#"ROOT { PARSE_ERR: UnclosedArray { BRACKET_OPEN "["; ELEMENT { NUMBER "1"; } COMMA ","; ELEMENT { NUMBER "2"; } TRAILING_COMMA { COMMA ","; } } }"#, + r#"[{"hello":"world""# => r#"ROOT { PARSE_ERR: UnclosedArray { BRACKET_OPEN "["; ELEMENT { PARSE_ERR: UnclosedObject { BRACE_OPEN "{"; MEMBER { MEMBER_NAME { STRING "\"hello\""; } COLON ":"; MEMBER_VALUE { STRING "\"world\""; } } } } } }"# + } + } +}