-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm_test.rs
127 lines (107 loc) · 2.77 KB
/
term_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use serde_json::json;
use os_query_builder_rs::model::Query;
use os_query_builder_rs::term::term::Term;
#[test]
fn term_test() {
let term = Term::new("brand_name", "FIAT");
let json_actual = json!(term);
let json_expected = json!({
"brand_name": {
"value": "FIAT",
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_test_with_value_is_int() {
let term = Term::new("brand_id", 1 as i64);
let json_actual = json!(term);
let json_expected = json!({
"brand_id": {
"value": 1,
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_test_with_value_is_float64() {
let term = Term::new("brand_id", 1.3211);
let json_actual = json!(term);
let json_expected = json!({
"brand_id": {
"value": 1.3211,
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_test_with_value_is_float32() {
let value = 24334.1232131 as f32;
let term = Term::new("brand_id", value);
let json_actual = json!(term);
let json_expected = json!({
"brand_id": {
"value": value,
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_with_boost_test() {
let term = Term::new("brand_name", "FIAT").boost(0.65);
let json_actual = json!(term);
let json_expected = json!({
"brand_name": {
"value": "FIAT",
"boost": 0.65
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_with_case_insensitive_test() {
let term = Term::new("brand_name", "FIAT").case_insensitive(true);
let json_actual = json!(term);
let json_expected = json!({
"brand_name": {
"value": "FIAT",
"case_insensitive": true
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn term_with_boost_and_case_insensitive_test() {
let term = Term::new("brand_name", "FIAT")
.case_insensitive(true)
.boost(0.6);
let json_actual = json!(term);
let json_expected = json!({
"brand_name": {
"value": "FIAT",
"case_insensitive": true,
"boost": 0.6
}
});
assert_eq!(json_expected, json_actual);
}
#[test]
fn query_term_with_boost_and_case_insensitive_test() {
let term = Term::new("article", "43935055")
.case_insensitive(true)
.boost(0.6);
let query = Query::new().query(term);
let json_actual = json!(query);
let json_expected = json!({
"query": {
"term": {
"article": {
"boost":0.6,
"case_insensitive":true,
"value":"43935055"
}
}
}
});
assert_eq!(json_expected, json_actual);
}