Skip to content

Commit 4725f14

Browse files
committed
Unit test parameters
1 parent 3c2311b commit 4725f14

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/query_tests.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,43 @@ fn partial_index() {
172172
assert!(index.is_none());
173173
});
174174
}
175+
176+
#[test]
177+
fn parameters() {
178+
utils::with_db(|db| {
179+
let mut doc = Document::new_with_id("id1");
180+
let mut props = doc.mutable_properties();
181+
props.at("bool").put_bool(true);
182+
props.at("f64").put_f64(3.1);
183+
props.at("i64").put_i64(3);
184+
props.at("string").put_string("allo");
185+
db.save_document_with_concurency_control(&mut doc, ConcurrencyControl::FailOnConflict)
186+
.expect("save");
187+
188+
let query = Query::new(
189+
db,
190+
QueryLanguage::N1QL,
191+
"SELECT _.* FROM _ \
192+
WHERE _.bool=$bool \
193+
AND _.f64=$f64 \
194+
AND _.i64=$i64 \
195+
AND _.string=$string",
196+
)
197+
.expect("create query");
198+
199+
let mut params = MutableDict::new();
200+
params.at("bool").put_bool(true);
201+
params.at("f64").put_f64(3.1);
202+
params.at("i64").put_i64(3);
203+
params.at("string").put_string("allo");
204+
query.set_parameters(&params);
205+
206+
let params = query.parameters();
207+
assert_eq!(params.get("bool").as_bool(), Some(true));
208+
assert_eq!(params.get("f64").as_f64(), Some(3.1));
209+
assert_eq!(params.get("i64").as_i64(), Some(3));
210+
assert_eq!(params.get("string").as_string(), Some("allo"));
211+
212+
assert_eq!(query.execute().unwrap().count(), 1);
213+
});
214+
}

0 commit comments

Comments
 (0)