blob: 7509ac72a5fdcab57657545daed3a68aa0d31d13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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());
}
|