]>
git.proxmox.com Git - rustc.git/blob - vendor/elasticlunr-rs/tests/test-compare.rs
2 extern crate serde_json
;
3 extern crate elasticlunr
;
9 const DOCS
: &'
static [[&'
static str; 2]] = &[
12 "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
16 "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad",
20 "minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex",
24 "ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate",
28 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat",
30 ["Chapter 6", "Spatiëring shouldn’t cause a panic."],
33 fn create_index() -> serde_json
::Value
{
34 let mut index
= Index
::new(&["title", "body"]);
37 for doc
in DOCS
.iter() {
38 index
.add_doc(&format
!("{}", i
), doc
);
44 #[cfg(feature = "ja")]
45 const DOCS_JA
: &'
static [[&'
static str; 2]] = &[
52 "どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。",
56 "吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。この書生というのは時々我々を捕えて煮て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始であろう。この時妙なものだと思った感じが今でも残っている。",
60 "第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶だ。その後猫にもだいぶ逢ったがこんな片輪には一度も出会わした事がない。のみならず顔の真中があまりに突起している。",
64 #[cfg(feature = "ja")]
65 fn create_index_ja() -> serde_json
::Value
{
66 let mut index
= Index
::with_language(Language
::Japanese
, &["title", "body"]);
69 for doc
in DOCS_JA
.iter() {
70 index
.add_doc(&format
!("{}", i
), doc
);
76 const GENERATE_FIXTURE
: bool
= false;
78 fn get_fixture() -> serde_json
::Value
{
80 let src
= create_index();
82 let dest
= Path
::new(env
!("CARGO_MANIFEST_DIR")).join("tests/searchindex_fixture.json");
83 let dest
= File
::create(&dest
).unwrap();
84 serde_json
::to_writer_pretty(dest
, &src
).unwrap();
88 let json
= include_str
!("searchindex_fixture.json");
89 serde_json
::from_str(json
).expect("Unable to deserialize the fixture")
93 #[cfg(feature = "ja")]
94 const GENERATE_FIXTURE_JA
: bool
= false;
96 #[cfg(feature = "ja")]
97 fn get_fixture_ja() -> serde_json
::Value
{
98 if GENERATE_FIXTURE_JA
{
99 let src
= create_index_ja();
101 let dest
= Path
::new(env
!("CARGO_MANIFEST_DIR")).join("tests/searchindex_fixture_ja.json");
102 let dest
= File
::create(&dest
).unwrap();
103 serde_json
::to_writer_pretty(dest
, &src
).unwrap();
107 let json
= include_str
!("searchindex_fixture_ja.json");
108 serde_json
::from_str(json
).expect("Unable to deserialize the fixture of Japanese")
113 fn search_index_hasnt_changed_accidentally() {
114 let new_index
= create_index();
115 let fixture_index
= get_fixture();
117 if new_index
!= fixture_index
{
118 panic
!("The search index has changed from the fixture");
122 #[cfg(feature = "ja")]
124 fn ja_search_index_hasnt_changed_accidentally() {
125 let new_index
= create_index_ja();
126 let fixture_index
= get_fixture_ja();
128 if new_index
!= fixture_index
{
129 panic
!("The search index has changed from the fixture of Japanese");