diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/jsonpath_lib/tests/precompile.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/jsonpath_lib/tests/precompile.rs')
-rw-r--r-- | vendor/jsonpath_lib/tests/precompile.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/jsonpath_lib/tests/precompile.rs b/vendor/jsonpath_lib/tests/precompile.rs new file mode 100644 index 000000000..7509ac72a --- /dev/null +++ b/vendor/jsonpath_lib/tests/precompile.rs @@ -0,0 +1,41 @@ +#[macro_use] +extern crate serde_json; +extern crate jsonpath_lib; + +use common::{setup}; +use jsonpath_lib::Compiled; +use serde_json::Value; + +mod common; + +#[test] +fn precompile_test() { + setup(); + + let json = json!({ + "foo": {"bar": "baz"} + }); + + // compile once + + let compiled = Compiled::compile("$.foo.bar"); + + assert!(compiled.is_ok()); + + let compiled = compiled.unwrap(); + + // re-use + + //let result = compiled(&json).unwrap(); + assert_eq!(compiled.select(&json).unwrap().clone(), vec![&Value::String("baz".into())]); + assert_eq!(compiled.select(&json).unwrap().clone(), vec![&Value::String("baz".into())]); +} + +#[test] +fn precompile_failure() { + setup(); + + let compiled = Compiled::compile(""); + + assert!(compiled.is_err()); +}
\ No newline at end of file |