Skip to content

Commit

Permalink
update snapshot format to ron
Browse files Browse the repository at this point in the history
  • Loading branch information
39555 committed Nov 8, 2024
1 parent 1ef459e commit 0ff9cce
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 80 deletions.
20 changes: 19 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion brush-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ criterion = { version = "0.5.1", features = ["html_reports"] }
expect-test = "1.5.0"
pretty_assertions = { version = "1.4.1", features = ["unstable"] }
serde = { version = "1.0.214", features = ["derive"] }
serde_yaml = "0.9.34"
ron = "0.8"

[target.'cfg(unix)'.dev-dependencies]
pprof = { version = "0.13.0", features = ["criterion", "flamegraph"] }
Expand Down
56 changes: 35 additions & 21 deletions brush-parser/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::ast::{self, SeparatorOperator};
use crate::error;
use crate::tokenizer::{Token, TokenEndReason, Tokenizer, TokenizerOptions, Tokens};
Expand Down Expand Up @@ -1095,12 +1094,21 @@ for f in A B C; do
Ok(result)
}

fn serialize(p: ast::Program) -> Result<String> {
let c = ron::ser::PrettyConfig::new()
.compact_arrays(true)
.indentor(" ".into())
.separate_tuple_members(false)
.struct_names(true);
Ok(ron::ser::to_string_pretty(&p, c)?)
}

fn check_file(actual: ast::Program, expect: ExpectFile) -> Result<()> {
expect.assert_eq(&serde_yaml::to_string(&actual)?);
expect.assert_eq(&serialize(actual)?);
Ok(())
}
fn check(actual: ast::Program, expect: Expect) -> Result<()> {
expect.assert_eq(&serde_yaml::to_string(&actual)?);
expect.assert_eq(&serialize(actual)?);
Ok(())
}

Expand All @@ -1121,28 +1129,34 @@ for f in A B C; do
"#,
)?;
check_file(r, expect_file!["./snapshots/basic.yaml"])?;
check_file(r, expect_file!["./snapshots/basic.ron"])?;
Ok(())
}

#[test]
fn test_noop() -> Result<()> {
let r = parse(
r#":;"#,
let r = parse(r#":;"#)?;
check(
r,
expect![[r#"
Program(
complete_commands: [CompoundList([CompoundListItem(AndOrList(
first: Pipeline(
bang: false,
seq: [{
"Simple": SimpleCommand(
prefix: None,
word_or_name: Some(Word(
value: ":",
)),
suffix: None,
),
}],
),
additional: [],
), Sequence)])],
)"#]],
)?;
check(r, expect![[r#"
complete_commands:
- - - first:
bang: false
seq:
- Simple:
prefix: null
word_or_name:
value: ':'
suffix: null
additional: []
- Sequence
"#]])?;
Ok(())
}

Expand All @@ -1158,13 +1172,13 @@ for f in A B C; do
stringify!($parser),
"_",
stringify!($case),
".yaml"
".ron"
)],
)?;
Ok(())
}
};
}

case![basic2(parser("echo hello; echo world;"))];
case![basic2(parser("echo helo; echo world;"))];
}
47 changes: 47 additions & 0 deletions brush-parser/src/snapshots/basic.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Program(
complete_commands: [CompoundList([CompoundListItem(AndOrList(
first: Pipeline(
bang: false,
seq: [{
"Compound": [{
"ForClause": {
"variable_name": "f",
"values": [{
"value": "A",
}, {
"value": "B",
}, {
"value": "C",
}],
"body": [[{
"first": {
"bang": false,
"seq": [{
"Simple": {
"prefix": (),
"word_or_name": {
"value": "echo",
},
"suffix": [{
"Word": {
"value": "\"${f@L}\"",
},
}, {
"IoRedirect": {
"File": [(), "DuplicateOutput", {
"Fd": 2,
}],
},
}],
},
}],
},
"additional": [],
}, "Sequence"]],
},
}, ()],
}],
),
additional: [],
), Sequence)])],
)
32 changes: 0 additions & 32 deletions brush-parser/src/snapshots/basic.yaml

This file was deleted.

39 changes: 39 additions & 0 deletions brush-parser/src/snapshots/parser_basic2.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Program(
complete_commands: [CompoundList([CompoundListItem(AndOrList(
first: Pipeline(
bang: false,
seq: [{
"Simple": SimpleCommand(
prefix: None,
word_or_name: Some(Word(
value: "echo",
)),
suffix: Some(CommandSuffix([{
"Word": Word(
value: "helo",
),
}])),
),
}],
),
additional: [],
), Sequence), CompoundListItem(AndOrList(
first: Pipeline(
bang: false,
seq: [{
"Simple": SimpleCommand(
prefix: None,
word_or_name: Some(Word(
value: "echo",
)),
suffix: Some(CommandSuffix([{
"Word": Word(
value: "world",
),
}])),
),
}],
),
additional: [],
), Sequence)])],
)
25 changes: 0 additions & 25 deletions brush-parser/src/snapshots/parser_basic2.yaml

This file was deleted.

0 comments on commit 0ff9cce

Please sign in to comment.