-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added snapshot tests for the serde feature
Added snapshot tests based on `insta` to both the rsonpath-syntax and rsonpath-lib serialization features. Ref: #624
- Loading branch information
Showing
17 changed files
with
616 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
crates/rsonpath-lib/tests/engine_serialization_snapshots.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use insta::assert_ron_snapshot; | ||
use rsonpath::engine::{Compiler, RsonpathEngine}; | ||
|
||
mod ron { | ||
use super::*; | ||
use std::error::Error; | ||
|
||
fn engine(string: &str) -> Result<RsonpathEngine, Box<dyn Error>> { | ||
let query = rsonpath_syntax::parse(string)?; | ||
let engine = RsonpathEngine::compile_query(&query)?; | ||
Ok(engine) | ||
} | ||
|
||
#[test] | ||
fn empty_query() -> Result<(), Box<dyn Error>> { | ||
assert_ron_snapshot!(&engine("$")?); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn readme_query() -> Result<(), Box<dyn Error>> { | ||
assert_ron_snapshot!(&engine("$.jsonpath[*]")?); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn jsonpath_example_query() -> Result<(), Box<dyn Error>> { | ||
assert_ron_snapshot!(&engine("$..phoneNumbers[*].number")?); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn real_life_query() -> Result<(), Box<dyn Error>> { | ||
assert_ron_snapshot!(&engine("$.personal.details.contact.information.phones.home")?); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn slice() -> Result<(), Box<dyn Error>> { | ||
assert_ron_snapshot!(&engine("$..entries[3:5:7]")?); | ||
Ok(()) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
crates/rsonpath-lib/tests/snapshots/engine_serialization_snapshots__ron__empty_query.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
source: crates/rsonpath-lib/tests/engine_serialization_snapshots.rs | ||
expression: "&engine(\"$\")?" | ||
snapshot_kind: text | ||
--- | ||
(V1, Automaton( | ||
states: [ | ||
StateTable( | ||
attributes: StateAttributes(2), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(1), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
], | ||
)) |
84 changes: 84 additions & 0 deletions
84
...path-lib/tests/snapshots/engine_serialization_snapshots__ron__jsonpath_example_query.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
source: crates/rsonpath-lib/tests/engine_serialization_snapshots.rs | ||
expression: "&engine(\"$..phoneNumbers[*].number\")?" | ||
snapshot_kind: text | ||
--- | ||
(V1, Automaton( | ||
states: [ | ||
StateTable( | ||
attributes: StateAttributes(2), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(0), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(2)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(1), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(0), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(4)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(3), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(8), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(2)), | ||
(StringPattern(JsonString( | ||
quoted: "\"number\"", | ||
)), State(6)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(1), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(8), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(4)), | ||
(StringPattern(JsonString( | ||
quoted: "\"number\"", | ||
)), State(5)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(3), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(9), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(2)), | ||
(StringPattern(JsonString( | ||
quoted: "\"number\"", | ||
)), State(6)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(1), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(1), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phoneNumbers\"", | ||
)), State(2)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(1), | ||
), | ||
], | ||
)) |
37 changes: 37 additions & 0 deletions
37
crates/rsonpath-lib/tests/snapshots/engine_serialization_snapshots__ron__readme_query.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
source: crates/rsonpath-lib/tests/engine_serialization_snapshots.rs | ||
expression: "&engine(\"$.jsonpath[*]\")?" | ||
snapshot_kind: text | ||
--- | ||
(V1, Automaton( | ||
states: [ | ||
StateTable( | ||
attributes: StateAttributes(2), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"jsonpath\"", | ||
)), State(2)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(8), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(3), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(1), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
], | ||
)) |
81 changes: 81 additions & 0 deletions
81
...es/rsonpath-lib/tests/snapshots/engine_serialization_snapshots__ron__real_life_query.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
source: crates/rsonpath-lib/tests/engine_serialization_snapshots.rs | ||
expression: "&engine(\"$.personal.details.contact.information.phones.home\")?" | ||
snapshot_kind: text | ||
--- | ||
(V1, Automaton( | ||
states: [ | ||
StateTable( | ||
attributes: StateAttributes(2), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"personal\"", | ||
)), State(2)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"details\"", | ||
)), State(3)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"contact\"", | ||
)), State(4)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"information\"", | ||
)), State(5)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(4), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"phones\"", | ||
)), State(6)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(12), | ||
member_transitions: [ | ||
(StringPattern(JsonString( | ||
quoted: "\"home\"", | ||
)), State(7)), | ||
], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
StateTable( | ||
attributes: StateAttributes(1), | ||
member_transitions: [], | ||
array_transitions: [], | ||
fallback_state: State(0), | ||
), | ||
], | ||
)) |
Oops, something went wrong.