From e94078cc9cefd7798f6b37d76b4af0622a702ccb Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Wed, 13 Jun 2018 15:15:58 -0500 Subject: [PATCH] Fix tests --- tests/rendered_output.rs | 32 ++- tests/searchindex_fixture.json | 427 +++++++++++++++++---------------- 2 files changed, 242 insertions(+), 217 deletions(-) diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index a6549ed0..16abcdac 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -426,25 +426,39 @@ mod search { let index = read_book_index(temp.path()); + let doc_urls = index["doc_urls"].as_array().unwrap(); + let get_doc_ref = |url: &str| -> String { + doc_urls.iter() + .position(|s| s == url) + .unwrap() + .to_string() + }; + + let first_chapter = get_doc_ref("first/index.html#first-chapter"); + let introduction = get_doc_ref("intro.html#introduction"); + let some_section = get_doc_ref("first/index.html#some-section"); + let summary = get_doc_ref("first/includes.html#summary"); + let conclusion = get_doc_ref("conclusion.html#conclusion"); + let bodyidx = &index["index"]["index"]["body"]["root"]; let textidx = &bodyidx["t"]["e"]["x"]["t"]; assert_eq!(textidx["df"], 2); - assert_eq!(textidx["docs"]["first/index.html#first-chapter"]["tf"], 1.0); - assert_eq!(textidx["docs"]["intro.html#introduction"]["tf"], 1.0); + assert_eq!(textidx["docs"][&first_chapter]["tf"], 1.0); + assert_eq!(textidx["docs"][&introduction]["tf"], 1.0); let docs = &index["index"]["documentStore"]["docs"]; - assert_eq!(docs["first/index.html#first-chapter"]["body"], "more text."); - assert_eq!(docs["first/index.html#some-section"]["body"], ""); + assert_eq!(docs[&first_chapter]["body"], "more text."); + assert_eq!(docs[&some_section]["body"], ""); assert_eq!( - docs["first/includes.html#summary"]["body"], + docs[&summary]["body"], "Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Conclusion" ); assert_eq!( - docs["first/includes.html#summary"]["breadcrumbs"], + docs[&summary]["breadcrumbs"], "First Chapter » Summary" ); assert_eq!( - docs["conclusion.html#conclusion"]["body"], + docs[&conclusion]["body"], "I put <HTML> in here!" ); } @@ -452,7 +466,7 @@ mod search { // Setting this to `true` may cause issues with `cargo watch`, // since it may not finish writing the fixture before the tests // are run again. - const GENERATE_FIXTURE: bool = true; + const GENERATE_FIXTURE: bool = false; fn get_fixture() -> serde_json::Value { if GENERATE_FIXTURE { @@ -481,7 +495,7 @@ mod search { // // If you're pretty sure you haven't broken anything, change `GENERATE_FIXTURE` // above to `true`, and run `cargo test` to generate a new fixture. Then - // change it back to `false`. Include the changed `searchindex_fixture.json` in your commit. + // **change it back to `false`**. Include the changed `searchindex_fixture.json` in your commit. #[test] fn search_index_hasnt_changed_accidentally() { let temp = DummyBook::new().build().unwrap(); diff --git a/tests/searchindex_fixture.json b/tests/searchindex_fixture.json index aa9493bd..8e2f082e 100644 --- a/tests/searchindex_fixture.json +++ b/tests/searchindex_fixture.json @@ -1,107 +1,118 @@ { + "doc_urls": [ + "intro.html#introduction", + "first/index.html#first-chapter", + "first/index.html#some-section", + "first/nested.html#nested-chapter", + "first/nested.html#some-section", + "first/includes.html#includes", + "first/includes.html#summary", + "second.html#second-chapter", + "conclusion.html#conclusion" + ], "index": { "documentStore": { "docInfo": { - "conclusion.html#conclusion": { + "0": { "body": 3, "breadcrumbs": 1, "title": 1 }, - "first/includes.html#includes": { - "body": 0, - "breadcrumbs": 3, - "title": 1 - }, - "first/includes.html#summary": { - "body": 10, - "breadcrumbs": 3, - "title": 1 - }, - "first/index.html#first-chapter": { + "1": { "body": 2, "breadcrumbs": 2, "title": 2 }, - "first/index.html#some-section": { + "2": { "body": 0, "breadcrumbs": 1, "title": 1 }, - "first/nested.html#nested-chapter": { + "3": { "body": 4, "breadcrumbs": 4, "title": 2 }, - "first/nested.html#some-section": { + "4": { "body": 0, "breadcrumbs": 3, "title": 1 }, - "intro.html#introduction": { - "body": 3, - "breadcrumbs": 1, + "5": { + "body": 0, + "breadcrumbs": 3, "title": 1 }, - "second.html#second-chapter": { + "6": { + "body": 10, + "breadcrumbs": 3, + "title": 1 + }, + "7": { "body": 20, "breadcrumbs": 2, "title": 2 + }, + "8": { + "body": 3, + "breadcrumbs": 1, + "title": 1 } }, "docs": { - "conclusion.html#conclusion": { - "body": "I put <HTML> in here!", - "breadcrumbs": "Conclusion", - "id": "conclusion.html#conclusion", - "title": "Conclusion" - }, - "first/includes.html#includes": { - "body": "", - "breadcrumbs": "First Chapter » Includes", - "id": "first/includes.html#includes", - "title": "Includes" - }, - "first/includes.html#summary": { - "body": "Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Conclusion", - "breadcrumbs": "First Chapter » Summary", - "id": "first/includes.html#summary", - "title": "Summary" - }, - "first/index.html#first-chapter": { - "body": "more text.", - "breadcrumbs": "First Chapter", - "id": "first/index.html#first-chapter", - "title": "First Chapter" - }, - "first/index.html#some-section": { - "body": "", - "breadcrumbs": "Some Section", - "id": "first/index.html#some-section", - "title": "Some Section" - }, - "first/nested.html#nested-chapter": { - "body": "This file has some testable code. assert!(true);", - "breadcrumbs": "First Chapter » Nested Chapter", - "id": "first/nested.html#nested-chapter", - "title": "Nested Chapter" - }, - "first/nested.html#some-section": { - "body": "", - "breadcrumbs": "First Chapter » Some Section", - "id": "first/nested.html#some-section", - "title": "Some Section" - }, - "intro.html#introduction": { + "0": { "body": "Here's some interesting text...", "breadcrumbs": "Introduction", - "id": "intro.html#introduction", + "id": "0", "title": "Introduction" }, - "second.html#second-chapter": { + "1": { + "body": "more text.", + "breadcrumbs": "First Chapter", + "id": "1", + "title": "First Chapter" + }, + "2": { + "body": "", + "breadcrumbs": "Some Section", + "id": "2", + "title": "Some Section" + }, + "3": { + "body": "This file has some testable code. assert!(true);", + "breadcrumbs": "First Chapter » Nested Chapter", + "id": "3", + "title": "Nested Chapter" + }, + "4": { + "body": "", + "breadcrumbs": "First Chapter » Some Section", + "id": "4", + "title": "Some Section" + }, + "5": { + "body": "", + "breadcrumbs": "First Chapter » Includes", + "id": "5", + "title": "Includes" + }, + "6": { + "body": "Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Conclusion", + "breadcrumbs": "First Chapter » Summary", + "id": "6", + "title": "Summary" + }, + "7": { "body": "This makes sure you can insert runnable Rust files. fn main() { println!(\"Hello World!\");\n#\n# // You can even hide lines! :D\n# println!(\"I am hidden! Expand the code snippet to see me\");\n}", "breadcrumbs": "Second Chapter", - "id": "second.html#second-chapter", + "id": "7", "title": "Second Chapter" + }, + "8": { + "body": "I put <HTML> in here!", + "breadcrumbs": "Conclusion", + "id": "8", + "title": "Conclusion" } }, "length": 9, @@ -144,7 +155,7 @@ "u": { "df": 1, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 } } @@ -182,16 +193,16 @@ "r": { "df": 4, "docs": { - "first/includes.html#summary": { + "1": { + "tf": 1.0 + }, + "3": { + "tf": 1.0 + }, + "6": { "tf": 1.7320508075688773 }, - "first/index.html#first-chapter": { - "tf": 1.0 - }, - "first/nested.html#nested-chapter": { - "tf": 1.0 - }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -210,10 +221,10 @@ "e": { "df": 2, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -234,10 +245,10 @@ "s": { "df": 2, "docs": { - "conclusion.html#conclusion": { + "6": { "tf": 1.0 }, - "first/includes.html#summary": { + "8": { "tf": 1.0 } } @@ -253,7 +264,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -272,7 +283,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -290,7 +301,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -316,10 +327,10 @@ "e": { "df": 2, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -334,10 +345,10 @@ "t": { "df": 2, "docs": { - "first/includes.html#summary": { + "1": { "tf": 1.0 }, - "first/index.html#first-chapter": { + "6": { "tf": 1.0 } } @@ -348,7 +359,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -367,14 +378,14 @@ "'": { "df": 1, "docs": { - "intro.html#introduction": { + "0": { "tf": 1.0 } } }, "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -392,7 +403,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -404,7 +415,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -428,10 +439,10 @@ "d": { "df": 2, "docs": { - "first/includes.html#includes": { + "5": { "tf": 1.0 }, - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -455,7 +466,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -481,7 +492,7 @@ "t": { "df": 1, "docs": { - "intro.html#introduction": { + "0": { "tf": 1.0 } } @@ -504,10 +515,10 @@ "t": { "df": 2, "docs": { - "first/includes.html#summary": { + "0": { "tf": 1.0 }, - "intro.html#introduction": { + "6": { "tf": 1.0 } } @@ -536,7 +547,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -566,7 +577,7 @@ "t": { "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -594,7 +605,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -606,7 +617,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -624,7 +635,7 @@ "e": { "df": 1, "docs": { - "first/index.html#first-chapter": { + "1": { "tf": 1.0 } } @@ -644,10 +655,10 @@ "t": { "df": 2, "docs": { - "first/includes.html#summary": { + "3": { "tf": 1.0 }, - "first/nested.html#nested-chapter": { + "6": { "tf": 1.0 } } @@ -694,7 +705,7 @@ "o": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -706,7 +717,7 @@ "i": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -732,7 +743,7 @@ "t": { "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -755,7 +766,7 @@ "s": { "df": 1, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -780,7 +791,7 @@ "l": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -799,7 +810,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -821,10 +832,10 @@ "d": { "df": 2, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -845,10 +856,10 @@ "n": { "df": 2, "docs": { - "first/index.html#some-section": { + "2": { "tf": 1.0 }, - "first/nested.html#some-section": { + "4": { "tf": 1.0 } } @@ -862,7 +873,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -886,7 +897,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -912,7 +923,7 @@ "i": { "df": 1, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -929,7 +940,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -954,7 +965,7 @@ "l": { "df": 1, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 } } @@ -973,10 +984,10 @@ "t": { "df": 2, "docs": { - "first/index.html#first-chapter": { + "0": { "tf": 1.0 }, - "intro.html#introduction": { + "1": { "tf": 1.0 } } @@ -997,7 +1008,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1041,7 +1052,7 @@ "u": { "df": 1, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 } } @@ -1079,22 +1090,22 @@ "r": { "df": 6, "docs": { - "first/includes.html#includes": { - "tf": 1.0 - }, - "first/includes.html#summary": { - "tf": 2.0 - }, - "first/index.html#first-chapter": { + "1": { "tf": 1.4142135623730952 }, - "first/nested.html#nested-chapter": { + "3": { "tf": 1.7320508075688773 }, - "first/nested.html#some-section": { + "4": { "tf": 1.0 }, - "second.html#second-chapter": { + "5": { + "tf": 1.0 + }, + "6": { + "tf": 2.0 + }, + "7": { "tf": 1.4142135623730952 } } @@ -1113,10 +1124,10 @@ "e": { "df": 2, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1137,11 +1148,11 @@ "s": { "df": 2, "docs": { - "conclusion.html#conclusion": { - "tf": 1.4142135623730952 - }, - "first/includes.html#summary": { + "6": { "tf": 1.0 + }, + "8": { + "tf": 1.4142135623730952 } } } @@ -1156,7 +1167,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1175,7 +1186,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1193,7 +1204,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1219,10 +1230,10 @@ "e": { "df": 2, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1237,20 +1248,20 @@ "t": { "df": 5, "docs": { - "first/includes.html#includes": { - "tf": 1.0 - }, - "first/includes.html#summary": { + "1": { "tf": 1.4142135623730952 }, - "first/index.html#first-chapter": { + "3": { + "tf": 1.0 + }, + "4": { + "tf": 1.0 + }, + "5": { + "tf": 1.0 + }, + "6": { "tf": 1.4142135623730952 - }, - "first/nested.html#nested-chapter": { - "tf": 1.0 - }, - "first/nested.html#some-section": { - "tf": 1.0 } } } @@ -1260,7 +1271,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1279,14 +1290,14 @@ "'": { "df": 1, "docs": { - "intro.html#introduction": { + "0": { "tf": 1.0 } } }, "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -1304,7 +1315,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1316,7 +1327,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1340,10 +1351,10 @@ "d": { "df": 2, "docs": { - "first/includes.html#includes": { + "5": { "tf": 1.4142135623730952 }, - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -1367,7 +1378,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1393,7 +1404,7 @@ "t": { "df": 1, "docs": { - "intro.html#introduction": { + "0": { "tf": 1.0 } } @@ -1416,11 +1427,11 @@ "t": { "df": 2, "docs": { - "first/includes.html#summary": { - "tf": 1.0 - }, - "intro.html#introduction": { + "0": { "tf": 1.4142135623730952 + }, + "6": { + "tf": 1.0 } } } @@ -1448,7 +1459,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1478,7 +1489,7 @@ "t": { "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -1506,7 +1517,7 @@ "n": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1518,7 +1529,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1536,7 +1547,7 @@ "e": { "df": 1, "docs": { - "first/index.html#first-chapter": { + "1": { "tf": 1.0 } } @@ -1556,11 +1567,11 @@ "t": { "df": 2, "docs": { - "first/includes.html#summary": { - "tf": 1.0 - }, - "first/nested.html#nested-chapter": { + "3": { "tf": 1.4142135623730952 + }, + "6": { + "tf": 1.0 } } } @@ -1606,7 +1617,7 @@ "o": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1618,7 +1629,7 @@ "i": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1644,7 +1655,7 @@ "t": { "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -1667,7 +1678,7 @@ "s": { "df": 1, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -1692,7 +1703,7 @@ "l": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1711,7 +1722,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1733,10 +1744,10 @@ "d": { "df": 2, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.4142135623730952 } } @@ -1757,10 +1768,10 @@ "n": { "df": 2, "docs": { - "first/index.html#some-section": { + "2": { "tf": 1.4142135623730952 }, - "first/nested.html#some-section": { + "4": { "tf": 1.4142135623730952 } } @@ -1774,7 +1785,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1798,7 +1809,7 @@ "t": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1824,7 +1835,7 @@ "i": { "df": 1, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.4142135623730952 } } @@ -1841,7 +1852,7 @@ "e": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1866,7 +1877,7 @@ "l": { "df": 1, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 } } @@ -1885,10 +1896,10 @@ "t": { "df": 2, "docs": { - "first/index.html#first-chapter": { + "0": { "tf": 1.0 }, - "intro.html#introduction": { + "1": { "tf": 1.0 } } @@ -1909,7 +1920,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1943,13 +1954,13 @@ "r": { "df": 3, "docs": { - "first/index.html#first-chapter": { + "1": { "tf": 1.0 }, - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 }, - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -1977,7 +1988,7 @@ "s": { "df": 1, "docs": { - "conclusion.html#conclusion": { + "8": { "tf": 1.0 } } @@ -2007,7 +2018,7 @@ "t": { "df": 1, "docs": { - "first/index.html#first-chapter": { + "1": { "tf": 1.0 } } @@ -2030,7 +2041,7 @@ "d": { "df": 1, "docs": { - "first/includes.html#includes": { + "5": { "tf": 1.0 } } @@ -2059,7 +2070,7 @@ "t": { "df": 1, "docs": { - "intro.html#introduction": { + "0": { "tf": 1.0 } } @@ -2088,7 +2099,7 @@ "t": { "df": 1, "docs": { - "first/nested.html#nested-chapter": { + "3": { "tf": 1.0 } } @@ -2110,7 +2121,7 @@ "d": { "df": 1, "docs": { - "second.html#second-chapter": { + "7": { "tf": 1.0 } } @@ -2131,10 +2142,10 @@ "n": { "df": 2, "docs": { - "first/index.html#some-section": { + "2": { "tf": 1.0 }, - "first/nested.html#some-section": { + "4": { "tf": 1.0 } } @@ -2162,7 +2173,7 @@ "i": { "df": 1, "docs": { - "first/includes.html#summary": { + "6": { "tf": 1.0 } } @@ -2186,11 +2197,11 @@ "ref": "id", "version": "0.9.5" }, - "resultsoptions": { + "results_options": { "limit_results": 30, "teaser_word_count": 30 }, - "searchoptions": { + "search_options": { "bool": "OR", "expand": true, "fields": {