UNPKG

swordjs

Version:

swordjs - access modules from crosswire.org/sword in JS

670 lines (598 loc) 209 kB
bcv_parser = require("../../js/en_bcv_parser.js").bcv_parser describe "Pre-parsing", -> p = {} beforeEach -> p = new bcv_parser it "should be defined", -> expect(p).toBeDefined it "should have book regexps", -> expect(p.regexps.books[0].osis).toEqual ["Gen"] expect(p.regexps.escaped_passage).toBeDefined it "should reset itself", -> p.s = "string" p.entities = [1] p.options.book_alone_strategy = "hi" p.reset() expect(p.s).toEqual "" expect(p.entities).toEqual [] expect(p.passage.books).toEqual [] expect(p.passage.indices).toEqual {} expect(p.options.book_alone_strategy).toEqual "hi" #options don't get reset it "should reset itself when creating a new object", -> p.s = "string" p.entities = [1] p.options.book_alone_strategy = "hi" p.options.nonexistent_option = "hi" p = new bcv_parser expect(p.s).toEqual "" expect(p.entities).toEqual [] expect(p.passage).toEqual null expect(p.options.book_alone_strategy).not.toEqual "hi" expect(p.options.nonexistent_option).toBeUndefined() it "should handle resetting options", -> p.options.book_alone_strategy = "hi" p.options.nonexistent_option = "hi" p = new bcv_parser p.set_options {book_alone_strategy: "hi", nonexistent_option: "hi"} expect(p.options.book_alone_strategy).toEqual "hi" expect(p.options.nonexistent_option).toEqual "hi" p = new bcv_parser expect(p.options.book_alone_strategy).not.toEqual "hi" expect(p.options.nonexistent_option).toBeUndefined() it "should allow setting whether to include the Apocrypha via `set_options`", -> expect(p.options.include_apocrypha).toBeFalsy() p.set_options {include_apocrypha: "unknown"} expect(p.options.include_apocrypha).toBeFalsy() p.set_options {include_apocrypha: true} expect(p.options.include_apocrypha).toBeTruthy() it "should allow setting whether to include the Apocrypha via `include_apocrypha()`", -> expect(p.options.include_apocrypha).toBeFalsy() p.include_apocrypha "unknown" expect(p.options.include_apocrypha).toBeFalsy() p.include_apocrypha true expect(p.options.include_apocrypha).toBeTruthy() it "shouldn't allow changing to an unknown versification system", -> p.versification_system "unknown" expect(p.options.versification_system).toEqual "default" it "should allow changing to the `vulgate` versification system and back again", -> p.set_options versification_system: "vulgate" expect(p.options.versification_system).toEqual "vulgate" expect(p.translations.default.chapters.Ps[118]).toEqual 7 expect(p.parse("Ps 118:176").osis()).toEqual "Ps.118.176" expect(p.parse("Ps 119:176").osis()).toEqual "" expect(p.parse("Ps 151:1").osis()).toEqual "" p.set_options versification_system: "default" expect(p.options.versification_system).toEqual "default" expect(p.translations.default.chapters.Ps[118]).toEqual 176 expect(p.parse("Ps 118:176").osis()).toEqual "" expect(p.parse("Ps 119:176").osis()).toEqual "Ps.119.176" expect(p.parse("Ps 151:1").osis()).toEqual "" it "should allow the `vulgate` versification system to work with the Apocrypha", -> p.set_options versification_system: "vulgate", include_apocrypha: true expect(p.options.versification_system).toEqual "vulgate" expect(p.translations.default.chapters.Ps[118]).toEqual 7 expect(p.parse("Ps 118:176").osis()).toEqual "Ps.118.176" expect(p.parse("Ps 119:176").osis()).toEqual "" expect(p.parse("Ps 151:1").osis()).toEqual "Ps.151.1" p.set_options versification_system: "default" expect(p.options.versification_system).toEqual "default" expect(p.translations.default.chapters.Ps[118]).toEqual 176 expect(p.parse("Ps 118:176").osis()).toEqual "" expect(p.parse("Ps 119:176").osis()).toEqual "Ps.119.176" expect(p.parse("Ps 151:1").osis()).toEqual "Ps.151.1" it "should handle inline alternate versification systems", -> expect(p.parse("Matt 15 ESV, Matt 15 NIV, Matt 15").osis_and_translations()).toEqual [["Matt.15", "ESV"], ["Matt.15", "NIV"], ["Matt.15", ""]] expect(p.parse("Third John 15 ESV, Third John 15 NIV, Third John 15").osis_and_translations()).toEqual [["3John.1.15", "ESV"], ["3John.1.15", ""]] expect(p.parse("Third John 15 ESV, NIV, KJV").osis_and_translations()).toEqual [["3John.1.15", "ESV,NIV,KJV"]] expect(p.parse("Third John 15 NIV, KJV, ESV, ").osis_and_translations()).toEqual [["3John.1.15", "NIV,KJV,ESV"]] expect(p.parse("Third John 15 NIV, ESV, KJV").osis_and_translations()).toEqual [["3John.1.15", "NIV,ESV,KJV"]] it "should create (promote) start books based on the default translation when a translation doesn't explicitly define them", -> expect(p.parse("Num 14-Deut 6 KJV").osis_and_translations()).toEqual [["Num.14-Deut.6", "KJV"]] p.set_options versification_system: "kjv" expect(p.parse("Joshua 14:2-Judges 6 CEB").osis_and_translations()).toEqual [["Josh.14.2-Judg.6.40", "CEB"]] it "should reset versification systems properly when switching among several systems", -> expect(p.parse("Ps 118:176").osis()).toEqual "" expect(p.parse("Ps 119:176").osis()).toEqual "Ps.119.176" expect(p.parse("3 John 15").osis()).toEqual "3John.1.15" p.set_options versification_system: "vulgate" expect(p.parse("Ps 118:176").osis()).toEqual "Ps.118.176" expect(p.parse("Ps 119:176").osis()).toEqual "" expect(p.parse("3 John 15").osis()).toEqual "3John.1.15" p.set_options versification_system: "kjv" expect(p.parse("Ps 118:176").osis()).toEqual "" expect(p.parse("Ps 119:176").osis()).toEqual "Ps.119.176" expect(p.parse("3 John 15").osis()).toEqual "" it "should allow adding a new versification system", -> # In real life, `order` should always contain all books; things will break if it doesn't. p.translations.new_system = order: Ps: 1 Matt: 2 chapters: Ps: [3,4,5] Matt: [6,7,8] p.set_options versification_system: "new_system" expect(p.options.versification_system).toEqual "new_system" expect(p.parse("Ps 1:3").osis()).toEqual "Ps.1.3" expect(p.parse("Ps 1:4").osis()).toEqual "" expect(p.parse("Ps 2ff").osis()).toEqual "Ps.2-Ps.3" expect(p.parse("Proverbs 2:3").osis()).toEqual "" expect(p.parse("Ps 3-Proverbs 2:3").osis()).toEqual "Ps.3" expect(p.parse("Ps 3\u2014Matt 2:7").osis()).toEqual "Ps.3-Matt.2" expect(p.parse("Ps 3-Matt 2:8").osis()).toEqual "Ps.3-Matt.2" expect(p.parse("Ps 3-Matt 4").osis()).toEqual "Ps.3-Matt.3" it "should handle two translations in a row", -> expect(p.parse("Matt 1,4 ESV 2-3 NIV").osis_and_indices()).toEqual [{osis: "Matt.1,Matt.4", translations: ["ESV"], indices: [0, 12]}, {osis: "Matt.2-Matt.3", translations: ["NIV"], indices: [13, 20]}] expect(p.parse("3 Jn 15 ESV 15 NIV").osis_and_indices()).toEqual [{osis: "3John.1.15", translations: ["ESV"], indices: [0, 11]}] expect(p.parse("3 Jn 15 NIV 15 ESV").osis_and_indices()).toEqual [{osis: "3John.1.15", translations: ["ESV"], indices: [12, 18]}] # This is actually testing the opposite of what the description says. Ideally, a new object would be totally new, but I don't think it's worth the overhead. it "should delete the previously added new versification system when creating a new object", -> expect(p.translations.new_system).toBeDefined() it "should handle control characters", -> expect(p.replace_control_characters(" hi ").length).toEqual 4 test_string = " \x1ehi\x1e \r\n \x1f0\x1f\n\r\u00a0\x00\u001e\u2014\xa0\x1f\x1f" match_string = " hi \r\n 0 \n\r\u00a0\x00 \u2014\xa0 " replaced_string = p.replace_control_characters(test_string) expect(replaced_string.length).toEqual test_string.length expect(escape(replaced_string)).toEqual escape(match_string) it "should handle non-Latin digits when asked", -> expect(p.parse("2 Peter \u0662:\u0663-\u0664").osis()).toEqual "" p.set_options non_latin_digits_strategy: "replace" expect(p.parse("2 Peter \u0662:\u0663-\u0664").osis()).toEqual "2Pet.2.3-2Pet.2.4" it "should match basic books", -> [s, books] = p.match_books "Jeremiah, Genesisjer (NIV)" expect(books.length).toEqual 2 expect(books[0]).toEqual value: "Jeremiah", parsed: ["Jer"], type: "book", start_index: 0 expect(books[1]).toEqual value: "NIV", parsed: "niv", type: "translation", start_index: 22 expect(s).toEqual "\x1f0\x1f, Genesisjer (\x1e1\x1e)" it "should match passage sequences", -> sequences = [ ["\x1f0\x1f", "R"] ["\x1f0\x1f 1:2, 3:4; see also 5:6-7 and compare cf. 8.9ff (\x1e1\x1e)", "R"] ["see \x1f0\x1f", "seeR"] ["see \"\x1f999\x1f\" ", "see R"] ["\x1f0\x1f and me.", "Rme."] ["my\x1f0\x1f and .", "my\x1f0\x1f and ."] [" \x1f0\x1f and . then \x1f1\x1f 2-3ff for\x1f1\x1f 3", "RthenRfor\x1f1\x1f 3"] ["1\x1f0\x1f2", "1\x1f0\x1f2"] ["\x1f0\x1f2\x1f1\x1f3", "R"] ["\x1f\x1f \x1fa\x1f 2", "\x1f\x1f \x1fa\x1f 2"] #no number; shouldn't happen ] for [s, post] in sequences s = s.replace p.regexps.escaped_passage, (match, $1, $2) -> "R" expect(s).toEqual post it "should handle consecutive checking", -> p.reset() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 2}, "default")).toBeTruthy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 2}, {b: "Gen", c: 1, v: 1}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 3}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 31}, {b: "Gen", c: 2, v: 1}, "default")).toBeTruthy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 30}, {b: "Gen", c: 1, v: 2}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 31}, {b: "Gen", c: 1, v: 2}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 1, v: 31}, {b: "Gen", c: 2, v: 2}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 50, v: 26}, {b: "Exod", c: 1, v: 1}, "default")).toBeTruthy() expect(p.is_verse_consecutive({b: "Gen", c: 50, v: 25}, {b: "Exod", c: 1, v: 1}, "default")).toBeFalsy() expect(p.is_verse_consecutive({b: "Gen", c: 50, v: 26}, {b: "Exod", c: 1, v: 2}, "default")).toBeFalsy() it "should identify being followed by a book", -> p.reset() expect(p.starts_with_book(type: "bc")).toBeTruthy() expect(p.starts_with_book(type: "cv")).toBeFalsy() expect(p.starts_with_book(type: "range", start: {type: "bcv"})).toBeTruthy() expect(p.starts_with_book(type: "range", start: {type: "integer"})).toBeFalsy() it "should turn on/off the Apocrypha", -> p.reset() p.include_apocrypha(true) expect(p.translations.default.chapters.Ps[150]).toEqual 7 expect(p.translations.default.order.Tob).toEqual 67 expect(p.options.include_apocrypha).toBeTruthy() p.include_apocrypha(false) expect(p.translations.default.chapters.Ps[150]).not.toBeDefined() expect(p.options.include_apocrypha).toBeFalsy() it "should handle case-sensitivity", -> p.reset() test_string = "heb 12, ex 3, i macc2" expect(p.parse(test_string).osis()).toEqual "Heb.12,Exod.3" p.set_options case_sensitive: "unknown" expect(p.parse(test_string).osis()).toEqual "Heb.12,Exod.3" p.set_options case_sensitive: "books" expect(p.parse(test_string).osis()).toEqual "" # Set it equal to what it already is. p.set_options case_sensitive: "books" expect(p.parse(test_string).osis()).toEqual "" p.set_options include_apocrypha: true expect(p.parse(test_string).osis()).toEqual "" p.set_options case_sensitive: "none" expect(p.parse(test_string).osis()).toEqual "Heb.12,Exod.3,1Macc.2" it "should replace ends correctly", -> expect(p.replace_match_end "\x1f0\x1f 3b").toEqual "\x1f0\x1f 3b" expect(p.replace_match_end "\x1f0\x1f 3b.").toEqual "\x1f0\x1f 3b" expect(p.replace_match_end "\x1f0\x1f 3chapter").toEqual "\x1f0\x1f 3" expect(p.replace_match_end "\x1f0\x1f 3ff. ").toEqual "\x1f0\x1f 3ff." expect(p.replace_match_end "\x1f0\x1f go").toEqual "\x1f0\x1f" expect(p.replace_match_end "\x1f0\x1f 3.").toEqual "\x1f0\x1f 3" expect(p.replace_match_end "(\x1e0\x1e)").toEqual "(\x1e0\x1e)" expect(p.replace_match_end "[\x1e0\x1e]").toEqual "[\x1e0\x1e]" it "should pluck null passages", -> p.parse("Jonah 2") expect(p.passage.pluck("none", [])).toEqual null expect(p.passage.pluck("none", [{type: "b"}])).toEqual null describe "OSIS parsing strategies", -> p = {} translation = {} beforeEach -> p = new bcv_parser p.reset() translation = "default" p.options.book_alone_strategy = "ignore" it "should return OSIS for b-b with various parsing strategies", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen-Rev" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen-Rev" p.options.book_alone_strategy = "full" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen.1-Gen.50" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen.1-Rev.22" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen.1-Rev.22" p.options.book_alone_strategy = "full" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen.1.1-Gen.50.26" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen.1.1-Rev.22.21" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen"}, {b: "Gen"}, translation).toEqual "Gen.1.1-Gen.1.31" expect(p.to_osis {b: "Gen"}, {b: "Rev"}, translation).toEqual "Gen.1.1-Rev.22.21" it "should return OSIS for bc-b with various parsing strategies", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen-Rev" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen-Rev" p.options.book_alone_strategy = "full" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen.1-Gen.50" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen.1-Rev.22" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen.1-Gen.50" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen.1-Rev.22" p.options.book_alone_strategy = "full" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen.1.1-Gen.50.26" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen.1.1-Rev.22.21" p.options.book_alone_strategy = "first_chapter" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen"}, translation).toEqual "Gen.1.1-Gen.50.26" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev"}, translation).toEqual "Gen.1.1-Rev.22.21" it "should return OSIS for bcv-b with various parsing strategies", -> p.options.osis_compaction_strategy = "b" # Don't need to check the book alone strategy; the previous test handles it expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen"}, translation).toEqual "Gen" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev"}, translation).toEqual "Gen-Rev" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen"}, translation).toEqual "Gen.1-Gen.50" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev"}, translation).toEqual "Gen.1-Rev.22" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen"}, translation).toEqual "Gen.1.1-Gen.50.26" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev"}, translation).toEqual "Gen.1.1-Rev.22.21" it "should return OSIS for b-bc with various parsing strategies", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1}, translation).toEqual "Gen.1-Rev.1" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 22}, translation).toEqual "Gen-Rev" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1}, translation).toEqual "Gen.1-Rev.1" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 22}, translation).toEqual "Gen.1-Rev.22" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1}, translation).toEqual "Gen.1.1-Gen.1.31" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2}, translation).toEqual "Gen.1.1-Gen.2.25" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1}, translation).toEqual "Gen.1.1-Rev.1.20" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 22}, translation).toEqual "Gen.1.1-Rev.22.21" it "should return OSIS for b-bcv with various parsing strategies", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2, v: 1}, translation).toEqual "Gen.1.1-Gen.2.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1.1-Gen.1.31" expect(p.to_osis {b: "Gen"}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1.1-Gen.2.25" expect(p.to_osis {b: "Gen"}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" it "should return OSIS for bcs", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 2, v: 1}, translation).toEqual "Gen.1.1-Gen.2.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1.1-Gen.1.31" expect(p.to_osis {b: "Gen", c: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1.1-Gen.2.25" expect(p.to_osis {b: "Gen", c: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" it "should return OSIS for bcvs", -> p.options.osis_compaction_strategy = "b" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 2, v: 1}, translation).toEqual "Gen.1.1-Gen.2.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bc" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1-Gen.2" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" p.options.osis_compaction_strategy = "bcv" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 1}, translation).toEqual "Gen.1.1" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 1, v: 31}, translation).toEqual "Gen.1.1-Gen.1.31" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Gen", c: 2, v: 25}, translation).toEqual "Gen.1.1-Gen.2.25" expect(p.to_osis {b: "Gen", c: 1, v: 1}, {b: "Rev", c: 1, v: 1}, translation).toEqual "Gen.1.1-Rev.1.1" describe "Basic passage parsing", -> p = new bcv_parser psg = {} translation_obj = translation: "default", osis: "", alias: "default" beforeEach -> p = new bcv_parser p.reset() psg = p.passage it "should handle start indices", -> psg.books = [{start_index: 0, value: "Genesis"}, {start_index: 12, value: "N"}] # Genesis 2:3 expect(psg.calculate_indices "\x1f0\x1f 2:3", 0).toEqual [{start:0, end:1, index:0}, {start:2, end:6, index:4}] # Genesis 2:3-N 5 expect(psg.calculate_indices "\x1f0\x1f 2:3-\x1e1\x1e 5", 0).toEqual [{start:0, end:1, index:0}, {start:2, end:9, index:4}, {start:10, end:12, index:2}] psg.books = [{start_index: 3, value: "Genesis"}, {start_index: 15, value: "N"}] # preGenesis 2:3 expect(psg.calculate_indices "pre\x1f0\x1f 2:3", "0").toEqual [{start:0, end:4, index:0}, {start:5, end:9, index:4}] # preGenesis 2:3-N 5 expect(psg.calculate_indices "pre\x1f0\x1f 2:3-\x1e1\x1e 5", 0).toEqual [{start:0, end:4, index:0}, {start:5, end:12, index:4}, {start:13, end:15, index:2}] psg.books = [{start_index: 8, value: "Genesis"}, {start_index: 15, value: "Exodus"}] #GenesisExodus 6 expect(psg.calculate_indices "\x1f0\x1f\x1f1\x1f 6", "08").toEqual [{start:0, end:1, index:8}, {start:2, end:4, index:12}, {start:5, end:7, index:15}] it "should match absolute indices", -> psg.indices = [{start:1, end:2, index:1}, {start:3, end:4, index:6}] expect(psg.get_absolute_indices [1, 2]).toEqual [2, 4] expect(psg.get_absolute_indices [2, 3]).toEqual [3, 10] expect(psg.get_absolute_indices [0, 4]).toEqual [null, 11] expect(psg.get_absolute_indices [3, 5]).toEqual [9, null] it "should validate refs with starts only", -> expect(psg.validate_ref null, {b: "Gen", c: 1}).toEqual {valid: true, messages: {}} expect(psg.validate_ref null, {b: "gen", c: 1}).toEqual {valid: false, messages: {start_book_not_exist: true}} expect(psg.validate_ref null, {b: "Gen", c: 51}).toEqual {valid: false, messages: {start_chapter_not_exist: 50}} expect(psg.validate_ref null, {b: "Gen", c: 0}).toEqual {valid: false, messages: {start_chapter_is_zero: 1}} expect(psg.validate_ref null, {b: "Gen", c: 1, v: "31"}).toEqual {valid: true, messages: {}} expect(psg.validate_ref null, {b: "Gen", c: 1, v: 0}).toEqual {valid: false, messages: {start_verse_is_zero: 1}} expect(psg.validate_ref null, {b: "Gen", c: 1, v: 32}).toEqual {valid: false, messages: {start_verse_not_exist: 31}} expect(psg.validate_ref null, {b: "Gen", c: "none"}).toEqual {valid: false, messages: {start_chapter_not_numeric: true}} expect(psg.validate_ref null, {b: "Gen", c: 1, v: "none"}).toEqual {valid: false, messages: {start_verse_not_numeric: true}} expect(psg.validate_ref null, {b: "Phlm", c: 2}).toEqual {valid: false, messages: {start_chapter_not_exist_in_single_chapter_book: 1}} it "should validate refs with starts and ends", -> expect(psg.validate_ref null, {b: "Matt"}, {b: "Phlm"}).toEqual {valid: true, messages: {}} expect(psg.validate_ref null, {b: "Matt"}, {b: "Matt"}).toEqual {valid: true, messages: {}} expect(psg.validate_ref null, {b: "Matt"}, {b: "Mal"}).toEqual {valid: false, messages: {end_book_before_start: true}} expect(psg.validate_ref null, {b: "Matt", c: "five"}, {b: "Phlm", c: "one"}).toEqual {valid: false, messages: {start_chapter_not_numeric: true, end_chapter_not_numeric: true}} expect(psg.validate_ref null, {b: "Matt", c: 5, v: "six"}, {b: "Phlm", c: 2}).toEqual {valid: false, messages: {start_verse_not_numeric: true, end_chapter_not_exist_in_single_chapter_book: 1}} expect(psg.validate_ref null, {b: "Matt", c: 50, v: 12}, {b: "Matt", c: 2}).toEqual {valid: false, messages: {start_chapter_not_exist: 28, end_chapter_before_start: true}} it "should validate start refs", -> expect(psg.validate_start_ref "default", {b: "Matt"}, {}).toEqual [true, {}] expect(psg.validate_start_ref "default", {b: "Matt", c: 5}, {}).toEqual [true, {}] expect(psg.validate_start_ref "default", {}, {}).toEqual [false, {start_book_not_exist: true}] expect(psg.validate_start_ref "default", {b: "Matt", c: "five"}, {}).toEqual [false, {start_chapter_not_numeric: true}] expect(psg.validate_start_ref "default", {b: "Matt", c: 5, v: 10}, {}).toEqual [true, {}] expect(psg.validate_start_ref "default", {b: "Matt", c: 5, v: "ten"}, {}).toEqual [false, {start_verse_not_numeric: true}] expect(psg.validate_start_ref "default", {b: "Matt", c: "five", v: "ten"}, {}).toEqual [false, {start_chapter_not_numeric: true}] expect(psg.validate_start_ref "default", {b: "Matt", v: 10}, {}).toEqual [true, {}] expect(psg.validate_start_ref "default", {b: "Matt", v: "ten"}, {}).toEqual [false, {start_verse_not_numeric: true}] expect(psg.validate_start_ref "default", {b: "Matt", c: 5, v: 100}, {}).toEqual [false, {start_verse_not_exist: 48}] expect(psg.validate_start_ref "default", {b: "Matt", c: 100, v: 100}, {}).toEqual [false, {start_chapter_not_exist: 28}] expect(psg.validate_start_ref "default", {b: "None", c: 2, v: 1}, {}).toEqual [false, {start_book_not_exist: true}] it "should validate end refs", -> expect(psg.validate_end_ref "default", {b: "Matt"}, {b: "Mark"}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Mark"}, {b: "Matt"}, true, {}).toEqual [false, {end_book_before_start: true}] expect(psg.validate_end_ref "default", {b: "Mark", c: 4}, {b: "Matt", c: 5}, true, {}).toEqual [false, {end_book_before_start: true}] # When called through validate_ref, as in the next example, it's invalid expect(psg.validate_end_ref "default", {b: "None", c: 5}, {b: "Mark", c: 4}, true, {}).toEqual [true, {}] expect(psg.validate_ref null, {b: "None", c: 5}, {b: "Mark", c: 4}).toEqual valid: false, messages: {start_book_not_exist: true} expect(psg.validate_end_ref "default", {b: "Matt", c: 5}, {b: "Matt", c: 6}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 10}, {b: "Matt", c: 4, v: 10}, true, {}).toEqual [false, {end_chapter_before_start: true}] expect(psg.validate_end_ref "default", {b: "Matt"}, {b: "Matt", c: 4}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: 1}, {b: "Matt", c: 0}, true, {}).toEqual [false, {end_chapter_is_zero: 1, end_chapter_before_start: true}] expect(psg.validate_end_ref "default", {b: "Matt"}, {b: "Matt", c: 0}, true, {}).toEqual [false, {end_chapter_is_zero: 1, end_chapter_before_start: true}] expect(psg.validate_end_ref "default", {b: "Matt", c: 2}, {b: "Matt", c: "four"}, true, {}).toEqual [false, {end_chapter_not_numeric: true}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5}, {b: "Matt", c: 5, v: 4}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 4}, {b: "Matt", c: 5, v: 4}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 4}, {b: "Matt", c: 5, v: 6}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 4}, {b: "Matt", c: 5, v: 1000}, true, {}).toEqual [true, {end_verse_not_exist: 48}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 4}, {b: "Matt", c: 5, v: 3}, true, {}).toEqual [false, {end_verse_before_start: true}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 7}, {b: "Matt", c: 5, v: "eight"}, true, {}).toEqual [false, {end_verse_not_numeric: true}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: "seven"}, {b: "Matt", c: 5, v: "eight"}, true, {}).toEqual [false, {end_verse_not_numeric: true}] expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: 7}, {b: "Matt", c: 5, v: 100}, true, {}).toEqual [true, {end_verse_not_exist: 48}] # The following are really undefined cases that would be caught if called through `validate_ref` expect(psg.validate_end_ref "default", {b: "Matt", c: 5, v: "seven"}, {b: "Matt", c: 5, v: 8}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: "four", v: "seven"}, {b: "Matt", c: 5, v: 8}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt", c: null, v: 7}, {b: "Matt", c: null, v: 8}, true, {}).toEqual [true, {}] expect(psg.validate_end_ref "default", {b: "Matt"}, {b: "Exod", c: "one", v: "two"}, true, {}).toEqual [false, {end_book_before_start: true, end_chapter_not_numeric: true, end_verse_not_numeric: true}] it "should handle translations", -> expect(psg.validate_ref [{translation: "default", osis: "", alias: "default"}, {translation: "niv", alias: "default"}], {b: "1Pet", c: 3}).toEqual valid: true, messages: {} # No `translation`, so use the default translation expect(psg.validate_ref [{no_key: "none"}], {b: "Obad", c: 1}).toEqual valid: true, messages: {} expect(psg.validate_ref null, {b: "Obad", c: 1, "translations": null}).toEqual valid: true, messages: {} # Given a string instead of an array, it iterates over each character. Since there's no `String.translation` object (i.e., the `translation` object is invalid), it uses the default and doesn't set `alias`. In practice, this won't hapepen. expect(psg.validate_ref "12", {b: "Obad", c: 1}).toEqual valid: false, messages: {translation_invalid: ["1", "2"]} # Given a number, it converts it to a "default" translation object. expect(psg.validate_ref 12, {b: "Obad", c: 1}).toEqual valid: true, messages: {} expect(psg.validate_ref [12], {b: "Obad", c: 1}).toEqual valid: false, messages: {translation_invalid: [12]} expect(psg.validate_ref [], {b: "Obad", c: 1}).toEqual valid: true, messages: {} expect(() -> psg.validate_ref [null], {b: "Obad", c: 1}).toThrow() it "should handle bvs posing as bcs", -> psg.books[0] = parsed: ["Phlm"] expect(psg.bc {absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 2}]}]}, [], {b: "Gen", c: 6, v: 6}).toEqual [[{absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 2}]}], start_context: {b:"Gen",c:6,v:6}, passages: [{start: {b: "Phlm", c: 1, v: 2}, end: {b: "Phlm", c: 1, v: 2}, valid: {valid: true, messages: {start_chapter_not_exist_in_single_chapter_book: 1}}}]}], {b: "Phlm", c: 1, v: 2}] expect(psg.bc {absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 7}]}]}, [], {b: "Gen", c: 6, v: 6}).toEqual [[{absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 7}]}], start_context: {b:"Gen",c:6,v:6}, passages: [{start: {b: "Phlm", c: 1, v: 7}, end: {b: "Phlm", c: 1, v: 7}, valid: {valid: true, messages: {start_chapter_not_exist_in_single_chapter_book: 1}}}]}], {b: "Phlm", c: 1, v: 7}] psg.books[0] = parsed: ["Phlm", "Phil"] expect(psg.bc {absolute_indices: [0, 6], value: [{type: "b", value: 0}, {type: "c", value: [{type: "integer", value: 2}]}]}, [], {translations: [{translation: "niv", osis: "NIV", alias: "default"},{translation: "kjv", osis: "KJV", alias: "default"}]}).toEqual [[{absolute_indices:[0,6],value:[{type:"b",value:0},{type:"c",value:[{type:"integer",value:2}]}],start_context:{translations:[{translation:"niv",osis:"NIV",alias:"default"},{translation:"kjv",osis:"KJV",alias:"default"}]},passages:[{start:{b:"Phlm",c:1,v:2},end:{b:"Phlm",c:1,v:2},valid:{valid:true,messages:{start_chapter_not_exist_in_single_chapter_book: 1}},alternates:[{start:{b:"Phil",c:2},end:{b:"Phil",c:2},valid:{valid:true,messages:{}}}], translations:[{translation:"niv",osis:"NIV",alias:"default"},{ translation:"kjv",osis:"KJV",alias:"default"}]}]}], {b:"Phlm",c:1,v:2,translations : [ { translation : "niv", osis : "NIV", alias : "default" }, { translation : "kjv", osis : "KJV", alias : "default" }]}] expect(psg.bc {absolute_indices: [0, 6], value: [{type: "b", value: 0}, {type: "c", value: [{type: "integer", value: 7}]}]}, [], {translations: [{translation: "niv", osis: "NIV", alias: "default"},{translation: "kjv", osis: "KJV", alias: "default"}]}).toEqual [[{absolute_indices:[0,6],value:[{type:"b",value:0},{type:"c",value:[{type:"integer",value:7}]}],start_context:{translations:[{translation:"niv",osis:"NIV",alias:"default"},{translation:"kjv",osis:"KJV",alias:"default"}]},passages:[{start:{b:"Phlm",c:1,v:7},end:{b:"Phlm",c:1,v:7},valid:{valid:true,messages:{start_chapter_not_exist_in_single_chapter_book: 1}},alternates:[{start:{b:"Phil",c:7},end:{b:"Phil",c:7},valid:{valid:false,messages:{start_chapter_not_exist:4}}}], translations:[{translation:"niv",osis:"NIV",alias:"default"},{ translation:"kjv",osis:"KJV",alias:"default"}]}]}], {b:"Phlm",c:1,v:7,translations : [ { translation : "niv", osis : "NIV", alias : "default" }, { translation : "kjv", osis : "KJV", alias : "default" }]}] psg.books[0] = parsed: ["Phil", "Phlm"] expect(psg.bc {absolute_indices: [0, 6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", value: [{type: "integer",absolute_indices:[5,6], value: 2}]}]},[],{}).toEqual [[{absolute_indices:[0,6],value:[{type:"b",absolute_indices:[0,3],value:0},{type:"c",value:[{type:"integer",absolute_indices:[5,6],value:2}]}],start_context:{},passages:[{start:{b:"Phil",c:2},end:{b:"Phil",c:2},valid:{valid:true,messages:{}},alternates:[{start:{b:"Phlm",c:1,v:2},end:{b:"Phlm",c:1,v:2},valid:{valid:true,messages:{start_chapter_not_exist_in_single_chapter_book: 1}}}]}]}],{b:"Phil",c:2}] expect(psg.bc {absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 7}]}]}, [], {b: "Gen", c: 6, v: 6}).toEqual [[{absolute_indices: [0,6], value: [{type: "b", absolute_indices: [0,3], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 7}]}], start_context: {b:"Gen",c:6,v:6}, passages: [{start: {b: "Phlm", c: 1, v: 7}, end: {b: "Phlm", c: 1, v: 7}, valid: {valid: true, messages: {start_chapter_not_exist_in_single_chapter_book: 1}},alternates:[{start:{b:"Phil",c:7},end:{b:"Phil",c:7},valid:{valid:false,messages:{start_chapter_not_exist:4}}}]}]}], {b: "Phlm", c: 1, v: 7}] # Psalm7 title (where "Psalm" could be interpreted different ways). it "should handle `bc_title`s", -> psg.books[0].parsed = ["Phil", "Phlm", "Ps"] expect(psg.bc_title {type:"bc_title", indices: [0,10],absolute_indices: [0,12], value:[{type: "bc", absolute_indices:[0,6], value: [{type: "b", absolute_indices: [0,5], value: 0}, {type: "c", absolute_indices: [5,6], value: [{type: "integer", absolute_indices:[5,6], value: 7}]}]}, {type:"title", value:["title"], indices:[5,9]}]}, [], {}).toEqual [[{type:"bcv",indices:[0,10],absolute_indices:[0,12],value:[{type:"bc",absolute_indices:[0,6],value:[{type:"b",absolute_indices:[0,5],value:0},{type:"c",absolute_indices:[5,6],value:[{type:"integer",absolute_indices:[5,6],value:7}]}],start_context:{},passages:[{start:{b:"Ps",c:7},end:{b:"Ps",c:7},valid:{valid:true,messages:{}}}]},{type:"v",value:[{type:"integer",value:1,indices:[5,9]}],indices:[5,9]}],start_context:{},passages:[{start:{b:"Ps",c:7,v:1},end:{b:"Ps",c:7,v:1},valid:{valid:true,messages:{}}}]}],{b:"Ps",c:7,v:1}] it "should adjust `RegExp.lastIndex` correctly", -> expect(p.adjust_regexp_end([], 10, 10)).toEqual 0 expect(p.adjust_regexp_end([], 10, 9)).toEqual 1 expect(p.adjust_regexp_end([{},{indices:[0,5]}], 10, 10)).toEqual 4 expect(p.adjust_regexp_end([{},{indices:[0,9]}], 10, 10)).toEqual 0 describe "Parsing with context", -> p = {} beforeEach -> p = new bcv_parser p.options.osis_compaction_strategy = "b" p.options.sequence_combination_strategy = "combine" it "should handle book context", -> expect(p.parse_with_context("2", "Gen").osis_and_indices()).toEqual [osis: "Gen.2", translations: [""], indices: [0, 1]] expect(p.parse_with_context("2:3", "Gen").osis_and_indices()).toEqual [osis: "Gen.2.3", translations: [""], indices: [0, 3]] expect(p.parse_with_context("2ff", "Gen").osis_and_indices()).toEqual [osis: "Gen.2-Gen.50", translations: [""], indices: [0, 3]] expect(p.parse_with_context("verse 2", "Gen").osis_and_indices()).toEqual [osis: "Gen.1.2", translations: [""], indices: [0, 7]] expect(p.parse_with_context("ch. 2-10", "Gen").osis_and_indices()).toEqual [osis: "Gen.2-Gen.10", translations: [""], indices: [0, 8]] expect(p.parse_with_context("chapter 6", "Gen").osis_and_indices()).toEqual [osis: "Gen.6", translations: [""], indices: [0, 9]] expect(p.parse_with_context("and 6 KJV", "Gen").osis_and_indices()).toEqual [osis: "Gen.6", translations: ["KJV"], indices: [4, 9]] it "should handle chapter context", -> expect(p.parse_with_context("2", "Gen 1").osis_and_indices()).toEqual [osis: "Gen.2", translations: [""], indices: [0, 1]] expect(p.parse_with_context("2:3", "Gen 1").osis_and_indices()).toEqual [osis: "Gen.2.3", translations: [""], indices: [0, 3]] expect(p.parse_with_context("2ff", "Gen 1").osis_and_indices()).toEqual [osis: "Gen.2-Gen.50", translations: [""], indices: [0, 3]] expect(p.parse_with_context("verse 16", "John 3").osis_and_indices()).toEqual [osis: "John.3.16", translations: [""], indices: [0, 8]] expect(p.parse_with_context("ch. 2-10", "Gen 8").osis_and_indices()).toEqual [osis: "Gen.2-Gen.10", translations: [""], indices: [0, 8]] expect(p.parse_with_context("chapter 6", "Gen 1").osis_and_indices()).toEqual [osis: "Gen.6", translations: [""], indices: [0, 9]] expect(p.parse_with_context("and 6 KJV", "Gen 5").osis_and_indices()).toEqual [osis: "Gen.6", translations: ["KJV"], indices: [4, 9]] expect(p.parse_with_context("verse 2", "Genesis 3").osis()).toEqual "Gen.3.2" it "should handle verse context", -> expect(p.parse_with_context("2", "Gen 1:5").osis_and_indices()).toEqual [osis: "Gen.1.2", translations: [""], indices: [0, 1]] expect(p.parse_with_context("2:3", "Gen 1:6").osis_and_indices()).toEqual [osis: "Gen.2.3", translations: [""], indices: [0, 3]] expect(p.parse_with_context("2ff", "Gen 1:8").osis_and_indices()).toEqual [osis: "Gen.1.2-Gen.1.31", translations: [""], indices: [0, 3]] expect(p.parse_with_context("verse 16", "John 3:2").osis_and_indices()).toEqual [osis: "John.3.16", translations: [""], indices: [0, 8]] expect(p.parse_with_context("ch. 2-10", "Gen 1:5").osis_and_indices()).toEqual [osis: "Gen.2-Gen.10", translations: [""], indices: [0, 8]] expect(p.parse_with_context("chapter 6", "Gen 1:7").osis_and_indices()).toEqual [osis: "Gen.6", translations: [""], indices: [0, 9]] expect(p.parse_with_context("and 6 KJV", "Gen 17:5").osis_and_indices()).toEqual [osis: "Gen.17.6", translations: ["KJV"], indices: [4, 9]] it "should handle sequences", -> expect(p.parse_with_context("19-80,4,5,20:6-10", "Gen 17:5").osis_and_indices()).toEqual [osis: "Gen.17.19-Gen.17.27,Gen.17.4-Gen.17.5,Gen.20.6-Gen.20.10", translations: [""], indices: [0, 17]] expect(p.parse_with_context("19:2-80,4,5,20:6-10", "Gen 17:5").osis_and_indices()).toEqual [osis: "Gen.19.2-Gen.19.38,Gen.19.4-Gen.19.5,Gen.20.6-Gen.20.10", translations: [""], indices: [0, 19]] it "should handle translations", -> expect(p.parse_with_context("15", "3 John 14 NIV").osis_and_indices()).toEqual [{osis: "3John.1.15", translations: [""], indices: [0, 2]}] expect(p.parse_with_context("15 NIV", "3 John 14 NIV").osis_and_indices()).toEqual [] it "should handle unusual cases", -> expect(p.parse_with_context("-16", "Gen 14").osis_and_indices()).toEqual [{osis: "Gen.16", translations: [""], indices: [1, 3]}] expect(p.parse_with_context("Exodus 22", "Gen 14").osis_and_indices()).toEqual [{osis: "Exod.22", translations: [""], indices: [0, 9]}] it "should handle lack of context", -> expect(p.parse_with_context("16", "none").osis_and_indices()).toEqual [] # It shouldn't handle null contexts--it expects a string. expect( () -> p.parse_with_context("16", null).osis_and_indices() ).toThrow() expect(p.parse_with_context("chapter 22", "see").osis_and_indices()).toEqual [] it "should not find matches in a few places", -> expect(p.parse_with_context("ff", "Gen 17").osis_and_indices()).toEqual [] expect(p.parse_with_context("a", "Gen 17:4").osis_and_indices()).toEqual [] expect(p.parse_with_context("and", "Gen 17:5").osis_and_indices()).toEqual [] describe "Parsing", -> p = {} beforeEach -> p = new bcv_parser p.options.osis_compaction_strategy = "b" p.options.sequence_combination_strategy = "combine" it "should handle books", -> p.options.book_alone_strategy = "full" expect(p.parse("Genesis").osis_and_indices()).toEqual [{osis: "Gen", indices: [0,7], translations: [""]}] expect(p.parse("1\u00a0Cor").osis_and_indices()).toEqual [{osis: "1Cor", indices: [0,5], translations: [""]}] it "should handle bcs", -> expect(p.parse("Genesis ch 3 (NIV, ESV)").osis_and_indices()).toEqual [{osis: "Gen.3", translations: ["NIV", "ESV"], indices: [0, 23]}] expect(p.parse("Genesis 1:2-ch 7").osis_and_indices()).toEqual [{osis: "Gen.1.2-Gen.7.24", translations: [""], indices: [0, 16]}] expect(p.parse("and Gen 1 5, Jere 2-3 see my Genesis ch 6 (NIV, ESV)").osis_and_indices()).toEqual [{osis: "Gen.1.5,Jer.2-Jer.3", translations: [""], indices: [4, 21]}, {osis: "Gen.6", translations: ["NIV","ESV"], indices: [29, 52]}] expect(p.parse("Jer.5.ESV").osis_and_indices()).toEqual [{osis:"Jer.5",indices:[0,9],translations:["ESV"]}] expect(p.parse("Matt 1 ESV, Matt 2 NIV").osis_and_indices()).toEqual [{osis:"Matt.1",indices:[0,10],translations:["ESV"]},{osis:"Matt.2",indices:[12,22],translations:["NIV"]}] expect(p.parse("Matt 1 1st to see").osis_and_indices()).toEqual [{osis:"Matt.1",indices:[0,6],translations:[""]}] it "should handle bvs", -> expect(p.parse("Genesis verse 2").osis()).toEqual "Gen.1.2" expect(p.parse("Philemon verse 3").osis()).toEqual "Phlm.1.3" expect(p.parse("Philemon 4").osis()).toEqual "Phlm.1.4" expect(p.parse("Philemon 5-6").osis()).toEqual "Phlm.1.5-Phlm.1.6" expect(p.parse("Genesis verse 7-8").osis()).toEqual "Gen.1.7-Gen.1.8" expect(p.parse("Philemon verse9- Philemon verse 10").osis()).toEqual "Phlm.1.9-Phlm.1.10" expect(p.parse("Philemon verse 11, Philemon verse 12").osis()).toEqual "Phlm.1.11-Phlm.1.12" expect(p.parse("Genesis 13a").osis()).toEqual "Gen.13" it "should handle ranges", -> expect(p.parse("Genesis 1-2").osis_and_indices()).toEqual [{osis: "Gen.1-Gen.2", translations: [""], indices: [0, 11]}] expect(p.parse("Genesis 1-2 ESV, NIV").osis_and_indices()).toEqual [{osis: "Gen.1-Gen.2", translations: ["ESV", "NIV"], indices: [0, 20]}] expect(p.parse("Genesis 1-2 [ESV, NIV]").osis_and_indices()).toEqual [{osis: "Gen.1-Gen.2", translations: ["ESV", "NIV"], indices: [0, 22]}] expect(p.parse("(Genesis 1-2 (ESV, NIV))").osis_and_indices()).toEqual [{osis: "Gen.1-Gen.2", translations: ["ESV", "NIV"], indices: [1, 23]}] expect(p.parse("Genesis 1-Jeremiah 2").osis_and_indices()).toEqual [{osis: "Gen.1-Jer.2", translations: [""], indices: [0, 20]}] expect(p.parse("Genesis 1-Jeremiah 2:5").osis_and_indices()).toEqual [{osis: "Gen.1.1-Jer.2.5", translations: [""], indices: [0, 22]}] expect(p.parse("Genesis 1-Jeremiah 2:100").osis_and_indices()).toEqual [{osis: "Gen.1-Jer.2", translations: [""], indices: [0, 24]}] expect(p.parse("Genesis 1-1:2").osis_and_indices()).toEqual [{osis: "Gen.1.1-Gen.1.2", translations: [""], indices: [0, 13]}] expect(p.parse("Genesis 1-2:1").osis_and_indices()).toEqual [{osis: "Gen.1.1-Gen.2.1", translations: [""], indices: [0, 13]}] expect(p.parse("Genesis 1-2:100").osis_and_indices()).toEqual [{osis: "Gen.1-Gen.2", translations: [""], indices: [0, 15]}] expect(p.parse("Philemon 1").osis_and_indices()).toEqual [{osis: "Phlm", translations: [""], indices: [0, 10]}] expect(p.parse("Philemon 1-10").osis_and_indices()).toEqual [{osis: "Phlm.1.1-Phlm.1.10", translations: [""], indices: [0, 13]}] expect(p.parse("Philemon 2-10").osis_and_indices()).toEqual [{osis: "Phlm.1.2-Phlm.1.10", translations: [""], indices: [0, 13]}] expect(p.parse("Philemon 1-1:10").osis_and_indices()).toEqual [{osis: "Phlm.1.1-Phlm.1.10", translations: [""], indices: [0, 15]}] expect(p.parse("Philemon 2-100").osis_and_indices()).toEqual [{osis: "Phlm.1.2-Phlm.1.25", translations: [""], indices: [0, 14]}] expect(p.parse("Philemon 1-68").osis_and_indices()).toEqual [{osis: "Phlm", translations: [""], indices: [0, 13]}] expect(p.parse("Genesis 2-Philemon 2").osis_and_indices()).toEqual [{osis: "Gen.2.1-Phlm.1.2", translations: [""], indices: [0, 20]}] expect(p.parse("Genesis 2-Philemon 1").osis_and_indices()).toEqual [{osis: "Gen.2-Phlm.1", translations: [""], indices: [0, 20]}] expect(p.parse("Genesis 1:2-Philemon 2").osis_and_indices()).toEqual [{osis: "Gen.1.2-Phlm.1.2", translations: [""], indices: [0, 22]}] expect(p.parse("Philemon 2-Hebrews 2").osis_and_indices()).toEqual [{osis: "Phlm.1.2-Heb.2.18", translations: [""], indices: [0, 20]}] expect(p.parse("Philem 1-Hebrews 2").osis_and_indices()).toEqual [{osis: "Phlm.1-Heb.2", translations: [""], indices: [0, 18]}] expect(p.parse("jo 1-2").osis_and_indices()).toEqual [{osis: "John.1-John.2", translations: [""], indices: [0, 6]}] expect(p.parse("Jeremiah 2-Genesis 1").osis_and_indices()).toEqual [{osis: "Jer.2,Gen.1", translations: [""], indices: [0, 20]}] expect(p.parse("Genesis 51-Jeremiah 6").osis_and_indices()).toEqual [{osis: "Jer.6", translations: [""], indices: [11, 21]}] expect(p.parse("Devotions: John 10:22-42 vs 27 \"My sheep hear my voice").osis_and_indices()).toEqual [{osis:"John.10.22-John.21.25", translations:[""], indices:[11,31]}] it "should match integers correctly", -> expect(p.parse("Zechariah 2").osis()).toEqual "Zech.2" expect(p.parse("Zechariah 12").osis()).toEqual "Zech.12" expect(p.parse("Zechariah 12").osis()).toEqual "Zech.12" expect(p.parse("Zechariah 120").osis()).toEqual "" expect(p.parse("Zechariah 1000").osis()).toEqual "" expect(p.parse("Zechariah 1,000").osis()).toEqual "" expect(p.parse("Zechariah 12,000").osis()).toEqual "" expect(p.parse("Zechariah 120,000").osis()).toEqual "" it "should handle book ranges with an `ignore` `book_sequence_strategy` and an `ignore` `book_range_strategy`", -> p.options.book_alone_strategy = "ignore" p.options.book_sequence_strategy = "ignore" p.options.book_range_strategy = "ignore" expect(p.parse("Gen-Jeremiah").osis()).toEqual "" expect(p.parse("Genesis 1-Jeremiah").osis_and_indices()).toEqual [{osis: "Gen.1", translations: [""], indices: [0, 9]}] expect(p.parse("Genesis 2-Jeremiah").osis_and_indices()).toEqual [{osis: "Gen.2", translations: [""], indices: [0, 9]}] expect(p.parse("Jeremiah-Isaiah").osis()).toEqual "" expect(p.parse("Genesis-Philemon").osis()).toEqual "" expect(p.parse("Genesis-Philemon 1").osis_and_indices()).toEqual [{osis: "Phlm", translations: [""], indices: [8, 18]}] expect(p.parse("Genesis 1-Genesis").osis_and_indices()).toEqual [{osis: "Gen.1", translations: [""], indices: [0, 9]}] expect(p.parse("Genesis 2-Genesis").osis_and_indices()).toEqual [{osis: "Gen.2", translations: [""], indices: [0, 9]}] expect(p.parse("Genesis 2-Philemon").osis_and_indices()).toEqual [{osis: "Gen.2", translations: [""], indices: [0, 9]}] expect(p.parse("Genesis-Philemon 2").osis_and_indices()).toEqual [{osis: "Phlm.1.2", translations: [""], indices: [8, 18]}] expect(p.parse("Luke-Acts").osis()).toEqual "" expect(p.parse("Gen-Exodus 2 (NIV)").osis_and_indices()).toEqual [{osis: "Exod.2", translations: ["NIV"], indices: [4, 18]}] expect(p.parse("Gen 2-Exodus (NIV)").osis_and_indices()).toEqual [{osis: "Gen.2", translations: ["NIV"], indices: [0, 18]}] it "should handle book ranges with an `ignore` `book_sequence_strategy` and an `include` `book_range_strategy`", -> p.options.book_alone_strategy = "ignore" p.options.book_sequence_strategy = "ignore" p.options.book_range_strategy = "include" expect(p.parse("Gen-Jeremiah").osis()).toEqual "Gen-Jer" expect(p.parse("Genesis 1-Jeremiah").osis_and_indices()).toEqual [{osis: "Gen-Jer", translations: [""], indices: [0, 18]}] ex