From 53ad1fc068889bf4a789a53596928146f89000b7 Mon Sep 17 00:00:00 2001 From: qdequele Date: Wed, 18 Sep 2019 16:58:51 +0200 Subject: [PATCH] chore: split tests into multiples files --- meilidb-data/tests/common.rs | 16 ++++++++ meilidb-data/tests/custom_settings_index.rs | 42 +++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 meilidb-data/tests/common.rs create mode 100644 meilidb-data/tests/custom_settings_index.rs diff --git a/meilidb-data/tests/common.rs b/meilidb-data/tests/common.rs new file mode 100644 index 000000000..dc6b22579 --- /dev/null +++ b/meilidb-data/tests/common.rs @@ -0,0 +1,16 @@ + +use meilidb_data::{Database}; +use meilidb_data::Index; +use meilidb_schema::{SchemaBuilder, DISPLAYED, INDEXED}; + +pub fn simple_index() -> Index { + let tmp_dir = tempfile::tempdir().unwrap(); + let database = Database::open(&tmp_dir).unwrap(); + + let mut builder = SchemaBuilder::with_identifier("objectId"); + builder.new_attribute("objectId", DISPLAYED | INDEXED); + builder.new_attribute("title", DISPLAYED | INDEXED); + let schema = builder.build(); + + database.create_index("hello", schema).unwrap() +} diff --git a/meilidb-data/tests/custom_settings_index.rs b/meilidb-data/tests/custom_settings_index.rs new file mode 100644 index 000000000..2f06a7e00 --- /dev/null +++ b/meilidb-data/tests/custom_settings_index.rs @@ -0,0 +1,42 @@ +mod common; +#[macro_use] extern crate maplit; + +use big_s::S; +use meilidb_data::{RankingOrdering}; + +#[test] +fn stop_words() { + let index = common::simple_index(); + let stop_words = hashset!{ S("le"), S("la"), S("les"), }; + index.custom_settings().set_stop_words(&stop_words).unwrap(); + let ret_stop_words = index.custom_settings().get_stop_words().unwrap().unwrap(); + assert_eq!(ret_stop_words, stop_words); +} + +#[test] +fn ranking_order() { + let index = common::simple_index(); + let ranking_order = vec![S("SumOfTypos"), S("NumberOfWords"), S("WordsProximity"), S("SumOfWordsAttribute"), S("SumOfWordsPosition"), S("Exact"), S("DocumentId")]; + index.custom_settings().set_ranking_order(&ranking_order).unwrap(); + let ret_ranking_orderer = index.custom_settings().get_ranking_order().unwrap().unwrap(); + assert_eq!(ret_ranking_orderer, ranking_order); +} + +#[test] +fn distinct_field() { + let index = common::simple_index(); + let distinct_field = S("title"); + index.custom_settings().set_distinct_field(&distinct_field).unwrap(); + let ret_distinct_field = index.custom_settings().get_distinct_field().unwrap().unwrap(); + assert_eq!(ret_distinct_field, distinct_field); +} + +#[test] +fn ranking_rules() { + let index = common::simple_index(); + let ranking_rules = hashmap!{ S("objectId") => RankingOrdering::Asc }; + index.custom_settings().set_ranking_rules(&ranking_rules).unwrap(); + let ret_ranking_rules = index.custom_settings().get_ranking_rules().unwrap().unwrap(); + assert_eq!(ret_ranking_rules, ranking_rules); +} +