From de008263ca37ca78018520b1e2a674092f97493c Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Wed, 3 Apr 2024 00:28:45 +0200 Subject: [PATCH] lang: add test --- crates/lang/src/parser.rs | 109 +++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index b1034fa..10fa46e 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -125,10 +125,117 @@ mod tests { (5..32).into() )) ), - (0..0).into() + (0..32).into() ) )]) } ); } + + fn test_parse_multiple_top_level_complex() { + const INPUT: &str = r#"def main = meow + | uwu + [ foo: @bar + , hello: world @| test [ more: params ] | yay + ] + !| awa + @| nya + | rawr; + +def test = meow + [ hello: $foo + , world: @bar + ]; +"#; + assert_eq!( + parse(INPUT).unwrap(), + File { + decls: IndexMap::from_iter([ + ( + ("main", (4..8).into()), + ( + Expr::SimplePipe( + Box::new(Expr::Node(("meow", (11..15).into()), None)), + Box::new(Expr::NullPipe( + Box::new(Expr::Node( + ("uwu", (20..23).into()), + Some(( + IndexMap::from_iter([ + ( + ("foo", (29..32).into()), + Expr::InputVar(("bar", (34..38).into())) + ), + ( + ("hello", (44..49).into()), + Expr::MappingPipe( + Box::new(Expr::Node( + ("world", (51..56).into()), + None + )), + Box::new(Expr::SimplePipe( + Box::new(Expr::Node( + ("test", (60..64).into()), + Some(( + IndexMap::from_iter([( + ("more", (67..71).into()), + Expr::Node( + ( + "params", + (73..79).into() + ), + None + ) + )]), + (65..81).into() + )) + )), + Box::new(Expr::Node( + ("yay", (84..87).into()), + None + )) + )) + ) + ) + ]), + (27..92).into() + )) + )), + Box::new(Expr::MappingPipe( + Box::new(Expr::Node(("awa", (97..100).into()), None)), + Box::new(Expr::SimplePipe( + Box::new(Expr::Node(("nya", (106..109).into()), None)), + Box::new(Expr::Node(("rawr", (114..118).into()), None)) + )) + )) + )) + ), + (11..118).into() + ), + ), + ( + ("test", (125..129).into()), + ( + Expr::Node( + ("meow", (132..136).into()), + Some(( + IndexMap::from_iter([ + ( + ("hello", (141..146).into()), + Expr::Var(("foo", (148..152).into())) + ), + ( + ("world", (156..161).into()), + Expr::InputVar(("bar", (163..167).into())) + ) + ]), + (139..171).into() + )) + ), + (132..171).into() + ) + ) + ]) + } + ); + } }