-
Notifications
You must be signed in to change notification settings - Fork 3
/
string.rs
54 lines (49 loc) · 1.16 KB
/
string.rs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
use jsonlogic::apply;
use serde_json::{json, Value};
// in
#[test]
fn is_in() {
assert_eq!(
apply(&json!({"in":["Spring", "Springfield"]}), &Value::Null),
Ok(json!(true))
);
assert_eq!(
apply(&json!({"in":["spring", "Springfield"]}), &Value::Null),
Ok(json!(false))
);
}
// cat
#[test]
fn cat() {
assert_eq!(
apply(&json!({"cat": ["I love", " pie"]}), &Value::Null),
Ok(json!("I love pie"))
);
assert_eq!(
apply(
&json!({"cat": ["I love ", {"var":"filling"}, " pie"]}),
&json!({"filling":"apple", "temp":110})
),
Ok(json!("I love apple pie"))
);
}
// substr
#[test]
fn substr() {
assert_eq!(
apply(&json!({"substr": ["jsonlogic", 4]}), &Value::Null),
Ok(json!("logic"))
);
assert_eq!(
apply(&json!({"substr": ["jsonlogic", -5]}), &Value::Null),
Ok(json!("logic"))
);
assert_eq!(
apply(&json!({"substr": ["jsonlogic", 1, 3]}), &Value::Null),
Ok(json!("son"))
);
assert_eq!(
apply(&json!({"substr": ["jsonlogic", 4, -2]}), &Value::Null),
Ok(json!("log"))
);
}