From 5b01b641bd25abf6c061a2c103fb8042e96a674b Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Sat, 3 Feb 2024 12:23:23 -0600 Subject: [PATCH] Update syntax tests --- Cargo.lock | 27 ++++- Cargo.toml | 1 - runtime/tests/exit.rs | 14 +++ syntax/Cargo.toml | 2 +- syntax/tests/parser.rs | 6 +- syntax/tests/parser/block-named-params.toml | 49 -------- syntax/tests/parser/block-named-params.yaml | 47 ++++++++ syntax/tests/parser/block-syntax.toml | 107 ------------------ syntax/tests/parser/block-syntax.yaml | 105 +++++++++++++++++ syntax/tests/parser/block-varargs.toml | 46 -------- syntax/tests/parser/block-varargs.yaml | 44 +++++++ syntax/tests/parser/import.toml | 22 ---- syntax/tests/parser/import.yaml | 20 ++++ .../interpolation/complex-substitution.toml | 62 ---------- .../interpolation/complex-substitution.yaml | 60 ++++++++++ .../interpolation/double-quoted-string.toml | 32 ------ .../interpolation/double-quoted-string.yaml | 30 +++++ .../parser/interpolation/substitution.toml | 37 ------ .../parser/interpolation/substitution.yaml | 35 ++++++ syntax/tests/parser/list-literal.toml | 56 --------- syntax/tests/parser/list-literal.yaml | 54 +++++++++ syntax/tests/parser/nested-blocks.toml | 76 ------------- syntax/tests/parser/nested-blocks.yaml | 74 ++++++++++++ .../tests/parser/nested-function-calls.toml | 70 ------------ .../tests/parser/nested-function-calls.yaml | 68 +++++++++++ syntax/tests/parser/newline-escapes.toml | 27 ----- syntax/tests/parser/newline-escapes.yaml | 25 ++++ syntax/tests/parser/number-literals.toml | 65 ----------- syntax/tests/parser/number-literals.yaml | 63 +++++++++++ syntax/tests/parser/simple-pipeline.toml | 26 ----- syntax/tests/parser/simple-pipeline.yaml | 24 ++++ .../parser/single-quoted-string-literal.toml | 26 ----- .../parser/single-quoted-string-literal.yaml | 24 ++++ syntax/tests/parser/string-escapes.toml | 38 ------- syntax/tests/parser/string-escapes.yaml | 36 ++++++ syntax/tests/parser/substitution/bare.toml | 28 ----- syntax/tests/parser/substitution/bare.yaml | 26 +++++ syntax/tests/parser/substitution/format.toml | 31 ----- syntax/tests/parser/substitution/format.yaml | 29 +++++ .../tests/parser/substitution/pipeline.toml | 35 ------ .../tests/parser/substitution/pipeline.yaml | 33 ++++++ syntax/tests/parser/table-literal.toml | 56 --------- syntax/tests/parser/table-literal.yaml | 54 +++++++++ syntax/tests/parser/variable-paths.toml | 71 ------------ syntax/tests/parser/variable-paths.yaml | 69 +++++++++++ 45 files changed, 964 insertions(+), 966 deletions(-) delete mode 100644 syntax/tests/parser/block-named-params.toml create mode 100644 syntax/tests/parser/block-named-params.yaml delete mode 100644 syntax/tests/parser/block-syntax.toml create mode 100644 syntax/tests/parser/block-syntax.yaml delete mode 100644 syntax/tests/parser/block-varargs.toml create mode 100644 syntax/tests/parser/block-varargs.yaml delete mode 100644 syntax/tests/parser/import.toml create mode 100644 syntax/tests/parser/import.yaml delete mode 100644 syntax/tests/parser/interpolation/complex-substitution.toml create mode 100644 syntax/tests/parser/interpolation/complex-substitution.yaml delete mode 100644 syntax/tests/parser/interpolation/double-quoted-string.toml create mode 100644 syntax/tests/parser/interpolation/double-quoted-string.yaml delete mode 100644 syntax/tests/parser/interpolation/substitution.toml create mode 100644 syntax/tests/parser/interpolation/substitution.yaml delete mode 100644 syntax/tests/parser/list-literal.toml create mode 100644 syntax/tests/parser/list-literal.yaml delete mode 100644 syntax/tests/parser/nested-blocks.toml create mode 100644 syntax/tests/parser/nested-blocks.yaml delete mode 100644 syntax/tests/parser/nested-function-calls.toml create mode 100644 syntax/tests/parser/nested-function-calls.yaml delete mode 100644 syntax/tests/parser/newline-escapes.toml create mode 100644 syntax/tests/parser/newline-escapes.yaml delete mode 100644 syntax/tests/parser/number-literals.toml create mode 100644 syntax/tests/parser/number-literals.yaml delete mode 100644 syntax/tests/parser/simple-pipeline.toml create mode 100644 syntax/tests/parser/simple-pipeline.yaml delete mode 100644 syntax/tests/parser/single-quoted-string-literal.toml create mode 100644 syntax/tests/parser/single-quoted-string-literal.yaml delete mode 100644 syntax/tests/parser/string-escapes.toml create mode 100644 syntax/tests/parser/string-escapes.yaml delete mode 100644 syntax/tests/parser/substitution/bare.toml create mode 100644 syntax/tests/parser/substitution/bare.yaml delete mode 100644 syntax/tests/parser/substitution/format.toml create mode 100644 syntax/tests/parser/substitution/format.yaml delete mode 100644 syntax/tests/parser/substitution/pipeline.toml create mode 100644 syntax/tests/parser/substitution/pipeline.yaml delete mode 100644 syntax/tests/parser/table-literal.toml create mode 100644 syntax/tests/parser/table-literal.yaml delete mode 100644 syntax/tests/parser/variable-paths.toml create mode 100644 syntax/tests/parser/variable-paths.yaml diff --git a/Cargo.lock b/Cargo.lock index 8609895..367731d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1019,9 +1019,9 @@ dependencies = [ "pest_derive", "regex", "serde", + "serde_yaml", "stderrlog", "test-generator", - "toml", ] [[package]] @@ -1057,6 +1057,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + [[package]] name = "scopeguard" version = "1.2.0" @@ -1092,6 +1098,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1418,6 +1437,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 3287454..028ba1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [workspace] resolver = "2" members = ["runtime", "shell", "stdlib", "syntax"] -default-members = ["shell"] [workspace.package] version = "0.2.0" diff --git a/runtime/tests/exit.rs b/runtime/tests/exit.rs index 89e94f6..a4ce10b 100644 --- a/runtime/tests/exit.rs +++ b/runtime/tests/exit.rs @@ -14,3 +14,17 @@ async fn exit_throws_unrecoverable_exception() { Err(e) => assert_eq!(e.message(), 1f64), } } +#[tokio::test] +async fn early_return() { + let result = riptide_runtime::eval(r#" + $test = { + return "early" + + "normal" + } + + test + "#).await; + + assert_eq!(result.unwrap(), "early"); +} diff --git a/syntax/Cargo.toml b/syntax/Cargo.toml index 5bf9b7b..3658e2b 100644 --- a/syntax/Cargo.toml +++ b/syntax/Cargo.toml @@ -16,8 +16,8 @@ difference = "2.0" glob = "0.3" log.workspace = true stderrlog = "0.6" +serde_yaml = "0.9" test-generator = "0.3" -toml = "0.8" [dev-dependencies.serde] workspace = true diff --git a/syntax/tests/parser.rs b/syntax/tests/parser.rs index d411e78..f197f25 100644 --- a/syntax/tests/parser.rs +++ b/syntax/tests/parser.rs @@ -21,15 +21,15 @@ struct ParserTest { impl ParserTest { fn load(path: impl AsRef) -> Result> { - Ok(toml::from_str(&fs::read_to_string(path)?)?) + Ok(serde_yaml::from_str(&fs::read_to_string(path)?)?) } fn save(&self, path: impl AsRef) -> Result<(), Box> { - Ok(fs::write(path, toml::to_string_pretty(self)?)?) + Ok(fs::write(path, serde_yaml::to_string(self)?)?) } } -#[test_generator::test_resources("syntax/tests/parser/**/*.toml")] +#[test_generator::test_resources("syntax/tests/parser/**/*.yaml")] fn parser_test(path: &str) { let path = &path[7..]; let mut test = ParserTest::load(path).unwrap(); diff --git a/syntax/tests/parser/block-named-params.toml b/syntax/tests/parser/block-named-params.toml deleted file mode 100644 index 2167311..0000000 --- a/syntax/tests/parser/block-named-params.toml +++ /dev/null @@ -1,49 +0,0 @@ -source = ''' -call { - println -} -''' -ast = ''' -Block { - span: Some( - Span(4:1, 4:35), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "call", - args: [ - Expr( - Block { - span: Some( - Span(4:6, 4:34), - ), - named_params: Some( - [ - "left", - "right", - ], - ), - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/block-named-params.yaml b/syntax/tests/parser/block-named-params.yaml new file mode 100644 index 0000000..48be063 --- /dev/null +++ b/syntax/tests/parser/block-named-params.yaml @@ -0,0 +1,47 @@ +source: | + call { + println + } +ast: |- + Block { + span: Some( + Span(3:1, 4:36), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "call", + args: [ + Expr( + Block { + span: Some( + Span(3:6, 3:35), + ), + named_params: Some( + [ + "left", + "right", + ], + ), + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/block-syntax.toml b/syntax/tests/parser/block-syntax.toml deleted file mode 100644 index 69d470c..0000000 --- a/syntax/tests/parser/block-syntax.toml +++ /dev/null @@ -1,107 +0,0 @@ -source = ''' -# One-liner -call { println } - -# With newlines -call { - println -} - -# Scrunched up -call{println} -''' -ast = ''' -Block { - span: Some( - Span(11:1, 11:98), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "call", - args: [ - Expr( - Block { - span: Some( - Span(11:18, 11:29), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "call", - args: [ - Expr( - Block { - span: Some( - Span(11:52, 11:67), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "call", - args: [ - Expr( - Block { - span: Some( - Span(11:88, 11:97), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/block-syntax.yaml b/syntax/tests/parser/block-syntax.yaml new file mode 100644 index 0000000..9fd582a --- /dev/null +++ b/syntax/tests/parser/block-syntax.yaml @@ -0,0 +1,105 @@ +source: | + # One-liner + call { println } + + # With newlines + call { + println + } + + # Scrunched up + call{println} +ast: |- + Block { + span: Some( + Span(6:1, 11:98), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "call", + args: [ + Expr( + Block { + span: Some( + Span(6:18, 6:29), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "call", + args: [ + Expr( + Block { + span: Some( + Span(6:52, 9:67), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "call", + args: [ + Expr( + Block { + span: Some( + Span(11:88, 11:97), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/block-varargs.toml b/syntax/tests/parser/block-varargs.toml deleted file mode 100644 index 27c0fbd..0000000 --- a/syntax/tests/parser/block-varargs.toml +++ /dev/null @@ -1,46 +0,0 @@ -source = ''' -call <...args> { - println -} -''' -ast = ''' -Block { - span: Some( - Span(4:1, 4:32), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "call", - args: [ - Expr( - Block { - span: Some( - Span(4:6, 4:31), - ), - named_params: None, - vararg_param: Some( - "args", - ), - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/block-varargs.yaml b/syntax/tests/parser/block-varargs.yaml new file mode 100644 index 0000000..a85c352 --- /dev/null +++ b/syntax/tests/parser/block-varargs.yaml @@ -0,0 +1,44 @@ +source: | + call <...args> { + println + } +ast: |- + Block { + span: Some( + Span(3:1, 4:32), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "call", + args: [ + Expr( + Block { + span: Some( + Span(3:6, 3:31), + ), + named_params: None, + vararg_param: Some( + "args", + ), + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/import.toml b/syntax/tests/parser/import.toml deleted file mode 100644 index a5c0d78..0000000 --- a/syntax/tests/parser/import.toml +++ /dev/null @@ -1,22 +0,0 @@ -source = ''' -import 'std/lang' for println -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:31), - ), - named_params: None, - vararg_param: None, - statements: [ - ImportStatement { - path: "std/lang", - clause: Items( - [ - "println", - ], - ), - }, - ], -} -''' diff --git a/syntax/tests/parser/import.yaml b/syntax/tests/parser/import.yaml new file mode 100644 index 0000000..46ee95b --- /dev/null +++ b/syntax/tests/parser/import.yaml @@ -0,0 +1,20 @@ +source: | + import 'std/lang' for println +ast: |- + Block { + span: Some( + Span(2:1, 2:31), + ), + named_params: None, + vararg_param: None, + statements: [ + ImportStatement { + path: "std/lang", + clause: Items( + [ + "println", + ], + ), + }, + ], + } diff --git a/syntax/tests/parser/interpolation/complex-substitution.toml b/syntax/tests/parser/interpolation/complex-substitution.toml deleted file mode 100644 index 12e10b2..0000000 --- a/syntax/tests/parser/interpolation/complex-substitution.toml +++ /dev/null @@ -1,62 +0,0 @@ -source = ''' -println "hello $({ - whoami -})" -''' -ast = ''' -Block { - span: Some( - Span(4:1, 4:35), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - InterpolatedString( - [ - String( - "hello ", - ), - Substitution( - Pipeline( - Pipeline( - [ - Unnamed { - function: Block { - span: Some( - Span(4:18, 4:32), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "whoami", - args: [], - }, - ], - ), - ], - }, - args: [], - }, - ], - ), - ), - ), - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/interpolation/complex-substitution.yaml b/syntax/tests/parser/interpolation/complex-substitution.yaml new file mode 100644 index 0000000..19a662b --- /dev/null +++ b/syntax/tests/parser/interpolation/complex-substitution.yaml @@ -0,0 +1,60 @@ +source: | + println "hello $({ + whoami + })" +ast: |- + Block { + span: Some( + Span(3:1, 4:35), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + InterpolatedString( + [ + String( + "hello ", + ), + Substitution( + Pipeline( + Pipeline( + [ + Unnamed { + function: Block { + span: Some( + Span(3:18, 3:32), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "whoami", + args: [], + }, + ], + ), + ], + }, + args: [], + }, + ], + ), + ), + ), + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/interpolation/double-quoted-string.toml b/syntax/tests/parser/interpolation/double-quoted-string.toml deleted file mode 100644 index 7ae9535..0000000 --- a/syntax/tests/parser/interpolation/double-quoted-string.toml +++ /dev/null @@ -1,32 +0,0 @@ -source = ''' -println "hello world" -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:23), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - InterpolatedString( - [ - String( - "hello world", - ), - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/interpolation/double-quoted-string.yaml b/syntax/tests/parser/interpolation/double-quoted-string.yaml new file mode 100644 index 0000000..a2bc862 --- /dev/null +++ b/syntax/tests/parser/interpolation/double-quoted-string.yaml @@ -0,0 +1,30 @@ +source: | + println "hello world" +ast: |- + Block { + span: Some( + Span(2:1, 2:23), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + InterpolatedString( + [ + String( + "hello world", + ), + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/interpolation/substitution.toml b/syntax/tests/parser/interpolation/substitution.toml deleted file mode 100644 index 17c36d4..0000000 --- a/syntax/tests/parser/interpolation/substitution.toml +++ /dev/null @@ -1,37 +0,0 @@ -source = ''' -println "hello $foo" -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:22), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - InterpolatedString( - [ - String( - "hello ", - ), - Substitution( - Variable( - "foo", - ), - ), - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/interpolation/substitution.yaml b/syntax/tests/parser/interpolation/substitution.yaml new file mode 100644 index 0000000..7eb6d2f --- /dev/null +++ b/syntax/tests/parser/interpolation/substitution.yaml @@ -0,0 +1,35 @@ +source: | + println "hello $foo" +ast: |- + Block { + span: Some( + Span(2:1, 2:22), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + InterpolatedString( + [ + String( + "hello ", + ), + Substitution( + Variable( + "foo", + ), + ), + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/list-literal.toml b/syntax/tests/parser/list-literal.toml deleted file mode 100644 index a4c7d4c..0000000 --- a/syntax/tests/parser/list-literal.toml +++ /dev/null @@ -1,56 +0,0 @@ -source = ''' -println [a b c] - -println [ - 1 - 2 - 3 -] -''' -ast = ''' -Block { - span: Some( - Span(8:1, 8:48), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - ListLiteral( - [ - "a", - "b", - "c", - ], - ), - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - ListLiteral( - [ - 1.0, - 2.0, - 3.0, - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/list-literal.yaml b/syntax/tests/parser/list-literal.yaml new file mode 100644 index 0000000..1957e55 --- /dev/null +++ b/syntax/tests/parser/list-literal.yaml @@ -0,0 +1,54 @@ +source: | + println [a b c] + + println [ + 1 + 2 + 3 + ] +ast: |- + Block { + span: Some( + Span(5:1, 8:48), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + ListLiteral( + [ + "a", + "b", + "c", + ], + ), + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + ListLiteral( + [ + 1.0, + 2.0, + 3.0, + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/nested-blocks.toml b/syntax/tests/parser/nested-blocks.toml deleted file mode 100644 index d310809..0000000 --- a/syntax/tests/parser/nested-blocks.toml +++ /dev/null @@ -1,76 +0,0 @@ -source = ''' -{ - { - { - println - } - } -} -''' -ast = ''' -Block { - span: Some( - Span(8:1, 8:57), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Unnamed { - function: Block { - span: Some( - Span(8:1, 8:56), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Unnamed { - function: Block { - span: Some( - Span(8:7, 8:54), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Unnamed { - function: Block { - span: Some( - Span(8:17, 8:48), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [], - }, - ], - ), - ], - }, - args: [], - }, - ], - ), - ], - }, - args: [], - }, - ], - ), - ], - }, - args: [], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/nested-blocks.yaml b/syntax/tests/parser/nested-blocks.yaml new file mode 100644 index 0000000..828a78b --- /dev/null +++ b/syntax/tests/parser/nested-blocks.yaml @@ -0,0 +1,74 @@ +source: | + { + { + { + println + } + } + } +ast: |- + Block { + span: Some( + Span(5:1, 8:57), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Unnamed { + function: Block { + span: Some( + Span(5:1, 7:56), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Unnamed { + function: Block { + span: Some( + Span(5:7, 7:54), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Unnamed { + function: Block { + span: Some( + Span(5:17, 5:48), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [], + }, + ], + ), + ], + }, + args: [], + }, + ], + ), + ], + }, + args: [], + }, + ], + ), + ], + }, + args: [], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/nested-function-calls.toml b/syntax/tests/parser/nested-function-calls.toml deleted file mode 100644 index 4368755..0000000 --- a/syntax/tests/parser/nested-function-calls.toml +++ /dev/null @@ -1,70 +0,0 @@ -source = ''' -println hello ({read} THE) (uppercase World) -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:46), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - "hello", - ), - Expr( - Pipeline( - [ - Unnamed { - function: Block { - span: Some( - Span(2:16, 2:22), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "read", - args: [], - }, - ], - ), - ], - }, - args: [ - Expr( - "THE", - ), - ], - }, - ], - ), - ), - Expr( - Pipeline( - [ - Named { - function: "uppercase", - args: [ - Expr( - "World", - ), - ], - }, - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/nested-function-calls.yaml b/syntax/tests/parser/nested-function-calls.yaml new file mode 100644 index 0000000..3086f69 --- /dev/null +++ b/syntax/tests/parser/nested-function-calls.yaml @@ -0,0 +1,68 @@ +source: | + println hello ({read} THE) (uppercase World) +ast: |- + Block { + span: Some( + Span(2:1, 2:46), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + "hello", + ), + Expr( + Pipeline( + [ + Unnamed { + function: Block { + span: Some( + Span(2:16, 2:22), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "read", + args: [], + }, + ], + ), + ], + }, + args: [ + Expr( + "THE", + ), + ], + }, + ], + ), + ), + Expr( + Pipeline( + [ + Named { + function: "uppercase", + args: [ + Expr( + "World", + ), + ], + }, + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/newline-escapes.toml b/syntax/tests/parser/newline-escapes.toml deleted file mode 100644 index 13ba816..0000000 --- a/syntax/tests/parser/newline-escapes.toml +++ /dev/null @@ -1,27 +0,0 @@ -source = ''' -println \ - foo -''' -ast = ''' -Block { - span: Some( - Span(3:1, 3:19), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - "foo", - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/newline-escapes.yaml b/syntax/tests/parser/newline-escapes.yaml new file mode 100644 index 0000000..29f2a5e --- /dev/null +++ b/syntax/tests/parser/newline-escapes.yaml @@ -0,0 +1,25 @@ +source: | + println \ + foo +ast: |- + Block { + span: Some( + Span(2:1, 3:19), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + "foo", + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/number-literals.toml b/syntax/tests/parser/number-literals.toml deleted file mode 100644 index dcbccde..0000000 --- a/syntax/tests/parser/number-literals.toml +++ /dev/null @@ -1,65 +0,0 @@ -source = ''' -println 100 -println 102.5 -println .25 -println -255 -''' -ast = ''' -Block { - span: Some( - Span(5:1, 5:52), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - 100.0, - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - 102.5, - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - 0.25, - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - -255.0, - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/number-literals.yaml b/syntax/tests/parser/number-literals.yaml new file mode 100644 index 0000000..d1b0acc --- /dev/null +++ b/syntax/tests/parser/number-literals.yaml @@ -0,0 +1,63 @@ +source: | + println 100 + println 102.5 + println .25 + println -255 +ast: |- + Block { + span: Some( + Span(3:1, 5:52), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + 100.0, + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + 102.5, + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + 0.25, + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + -255.0, + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/simple-pipeline.toml b/syntax/tests/parser/simple-pipeline.toml deleted file mode 100644 index d611d77..0000000 --- a/syntax/tests/parser/simple-pipeline.toml +++ /dev/null @@ -1,26 +0,0 @@ -source = ''' -hello | world -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:15), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "hello", - args: [], - }, - Named { - function: "world", - args: [], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/simple-pipeline.yaml b/syntax/tests/parser/simple-pipeline.yaml new file mode 100644 index 0000000..1ab3229 --- /dev/null +++ b/syntax/tests/parser/simple-pipeline.yaml @@ -0,0 +1,24 @@ +source: | + hello | world +ast: |- + Block { + span: Some( + Span(2:1, 2:15), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "hello", + args: [], + }, + Named { + function: "world", + args: [], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/single-quoted-string-literal.toml b/syntax/tests/parser/single-quoted-string-literal.toml deleted file mode 100644 index 3b72df0..0000000 --- a/syntax/tests/parser/single-quoted-string-literal.toml +++ /dev/null @@ -1,26 +0,0 @@ -source = ''' -println 'hello world' -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:23), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - "hello world", - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/single-quoted-string-literal.yaml b/syntax/tests/parser/single-quoted-string-literal.yaml new file mode 100644 index 0000000..9127704 --- /dev/null +++ b/syntax/tests/parser/single-quoted-string-literal.yaml @@ -0,0 +1,24 @@ +source: | + println 'hello world' +ast: |- + Block { + span: Some( + Span(2:1, 2:23), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + "hello world", + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/string-escapes.toml b/syntax/tests/parser/string-escapes.toml deleted file mode 100644 index 7f5e437..0000000 --- a/syntax/tests/parser/string-escapes.toml +++ /dev/null @@ -1,38 +0,0 @@ -source = ''' -println foo 'bar\'' "baz' a \" b" -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:35), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - "foo", - ), - Expr( - "bar\'", - ), - Expr( - InterpolatedString( - [ - String( - "baz\' a \" b", - ), - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/string-escapes.yaml b/syntax/tests/parser/string-escapes.yaml new file mode 100644 index 0000000..f5944cb --- /dev/null +++ b/syntax/tests/parser/string-escapes.yaml @@ -0,0 +1,36 @@ +source: | + println foo 'bar\'' "baz' a \" b" +ast: |- + Block { + span: Some( + Span(2:1, 2:35), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + "foo", + ), + Expr( + "bar'", + ), + Expr( + InterpolatedString( + [ + String( + "baz' a \" b", + ), + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/substitution/bare.toml b/syntax/tests/parser/substitution/bare.toml deleted file mode 100644 index 3e0b55f..0000000 --- a/syntax/tests/parser/substitution/bare.toml +++ /dev/null @@ -1,28 +0,0 @@ -source = ''' -println $foo -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:14), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - Variable( - "foo", - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/substitution/bare.yaml b/syntax/tests/parser/substitution/bare.yaml new file mode 100644 index 0000000..8dfa10b --- /dev/null +++ b/syntax/tests/parser/substitution/bare.yaml @@ -0,0 +1,26 @@ +source: | + println $foo +ast: |- + Block { + span: Some( + Span(2:1, 2:14), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + Variable( + "foo", + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/substitution/format.toml b/syntax/tests/parser/substitution/format.toml deleted file mode 100644 index 93ff489..0000000 --- a/syntax/tests/parser/substitution/format.toml +++ /dev/null @@ -1,31 +0,0 @@ -source = ''' -println ${foo:.2} -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:19), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - Format( - "foo", - Some( - ".2", - ), - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/substitution/format.yaml b/syntax/tests/parser/substitution/format.yaml new file mode 100644 index 0000000..3aaebe2 --- /dev/null +++ b/syntax/tests/parser/substitution/format.yaml @@ -0,0 +1,29 @@ +source: | + println ${foo:.2} +ast: |- + Block { + span: Some( + Span(2:1, 2:19), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + Format( + "foo", + Some( + ".2", + ), + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/substitution/pipeline.toml b/syntax/tests/parser/substitution/pipeline.toml deleted file mode 100644 index 20b7424..0000000 --- a/syntax/tests/parser/substitution/pipeline.toml +++ /dev/null @@ -1,35 +0,0 @@ -source = ''' -println $(foo) -''' -ast = ''' -Block { - span: Some( - Span(2:1, 2:16), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - Pipeline( - Pipeline( - [ - Named { - function: "foo", - args: [], - }, - ], - ), - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/substitution/pipeline.yaml b/syntax/tests/parser/substitution/pipeline.yaml new file mode 100644 index 0000000..946c9aa --- /dev/null +++ b/syntax/tests/parser/substitution/pipeline.yaml @@ -0,0 +1,33 @@ +source: | + println $(foo) +ast: |- + Block { + span: Some( + Span(2:1, 2:16), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + Pipeline( + Pipeline( + [ + Named { + function: "foo", + args: [], + }, + ], + ), + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/table-literal.toml b/syntax/tests/parser/table-literal.toml deleted file mode 100644 index 9599389..0000000 --- a/syntax/tests/parser/table-literal.toml +++ /dev/null @@ -1,56 +0,0 @@ -source = ''' -println [:] - -println [ - foo: bar - baz: 1234 -] -''' -ast = ''' -Block { - span: Some( - Span(7:1, 7:53), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - TableLiteral( - [], - ), - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - TableLiteral( - [ - TableEntry { - key: "foo", - value: "bar", - }, - TableEntry { - key: "baz", - value: 1234.0, - }, - ], - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/table-literal.yaml b/syntax/tests/parser/table-literal.yaml new file mode 100644 index 0000000..d915481 --- /dev/null +++ b/syntax/tests/parser/table-literal.yaml @@ -0,0 +1,54 @@ +source: | + println [:] + + println [ + foo: bar + baz: 1234 + ] +ast: |- + Block { + span: Some( + Span(4:1, 7:53), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + TableLiteral( + [], + ), + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + TableLiteral( + [ + TableEntry { + key: "foo", + value: "bar", + }, + TableEntry { + key: "baz", + value: 1234.0, + }, + ], + ), + ), + ], + }, + ], + ), + ], + } diff --git a/syntax/tests/parser/variable-paths.toml b/syntax/tests/parser/variable-paths.toml deleted file mode 100644 index 30e30f3..0000000 --- a/syntax/tests/parser/variable-paths.toml +++ /dev/null @@ -1,71 +0,0 @@ -source = ''' -$lang->ext->panic 'hello world' - -println $mytable -println $mytable->'key with spaces'->bar -''' -ast = ''' -Block { - span: Some( - Span(5:1, 5:92), - ), - named_params: None, - vararg_param: None, - statements: [ - Pipeline( - [ - Unnamed { - function: MemberAccess( - MemberAccess( - Variable( - "lang", - ), - "ext", - ), - "panic", - ), - args: [ - Expr( - "hello world", - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - Variable( - "mytable", - ), - ), - ], - }, - ], - ), - Pipeline( - [ - Named { - function: "println", - args: [ - Expr( - MemberAccess( - MemberAccess( - Variable( - "mytable", - ), - "key with spaces", - ), - "bar", - ), - ), - ], - }, - ], - ), - ], -} -''' diff --git a/syntax/tests/parser/variable-paths.yaml b/syntax/tests/parser/variable-paths.yaml new file mode 100644 index 0000000..847e04e --- /dev/null +++ b/syntax/tests/parser/variable-paths.yaml @@ -0,0 +1,69 @@ +source: | + $lang->ext->panic 'hello world' + + println $mytable + println $mytable->'key with spaces'->bar +ast: |- + Block { + span: Some( + Span(3:1, 5:92), + ), + named_params: None, + vararg_param: None, + statements: [ + Pipeline( + [ + Unnamed { + function: MemberAccess( + MemberAccess( + Variable( + "lang", + ), + "ext", + ), + "panic", + ), + args: [ + Expr( + "hello world", + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + Variable( + "mytable", + ), + ), + ], + }, + ], + ), + Pipeline( + [ + Named { + function: "println", + args: [ + Expr( + MemberAccess( + MemberAccess( + Variable( + "mytable", + ), + "key with spaces", + ), + "bar", + ), + ), + ], + }, + ], + ), + ], + }