swordjs
Version:
swordjs - access modules from crosswire.org/sword in JS
1,956 lines (1,951 loc) • 275 kB
JavaScript
// Generated by CoffeeScript 1.9.1
(function() {
var bcv_parser;
bcv_parser = require("../../js/en_bcv_parser.js").bcv_parser;
describe("Pre-parsing", function() {
var p;
p = {};
beforeEach(function() {
return p = new bcv_parser;
});
it("should be defined", function() {
return expect(p).toBeDefined;
});
it("should have book regexps", function() {
expect(p.regexps.books[0].osis).toEqual(["Gen"]);
return expect(p.regexps.escaped_passage).toBeDefined;
});
it("should reset itself", function() {
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({});
return expect(p.options.book_alone_strategy).toEqual("hi");
});
it("should reset itself when creating a new object", function() {
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");
return expect(p.options.nonexistent_option).toBeUndefined();
});
it("should handle resetting options", function() {
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");
return expect(p.options.nonexistent_option).toBeUndefined();
});
it("should allow setting whether to include the Apocrypha via `set_options`", function() {
expect(p.options.include_apocrypha).toBeFalsy();
p.set_options({
include_apocrypha: "unknown"
});
expect(p.options.include_apocrypha).toBeFalsy();
p.set_options({
include_apocrypha: true
});
return expect(p.options.include_apocrypha).toBeTruthy();
});
it("should allow setting whether to include the Apocrypha via `include_apocrypha()`", function() {
expect(p.options.include_apocrypha).toBeFalsy();
p.include_apocrypha("unknown");
expect(p.options.include_apocrypha).toBeFalsy();
p.include_apocrypha(true);
return expect(p.options.include_apocrypha).toBeTruthy();
});
it("shouldn't allow changing to an unknown versification system", function() {
p.versification_system("unknown");
return expect(p.options.versification_system).toEqual("default");
});
it("should allow changing to the `vulgate` versification system and back again", function() {
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");
return expect(p.parse("Ps 151:1").osis()).toEqual("");
});
it("should allow the `vulgate` versification system to work with the Apocrypha", function() {
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");
return expect(p.parse("Ps 151:1").osis()).toEqual("Ps.151.1");
});
it("should handle inline alternate versification systems", function() {
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"]]);
return 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", function() {
expect(p.parse("Num 14-Deut 6 KJV").osis_and_translations()).toEqual([["Num.14-Deut.6", "KJV"]]);
p.set_options({
versification_system: "kjv"
});
return 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", function() {
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");
return expect(p.parse("3 John 15").osis()).toEqual("");
});
it("should allow adding a new versification system", function() {
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");
return expect(p.parse("Ps 3-Matt 4").osis()).toEqual("Ps.3-Matt.3");
});
it("should handle two translations in a row", function() {
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]
}
]);
return expect(p.parse("3 Jn 15 NIV 15 ESV").osis_and_indices()).toEqual([
{
osis: "3John.1.15",
translations: ["ESV"],
indices: [12, 18]
}
]);
});
it("should delete the previously added new versification system when creating a new object", function() {
return expect(p.translations.new_system).toBeDefined();
});
it("should handle control characters", function() {
var match_string, replaced_string, test_string;
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);
return expect(escape(replaced_string)).toEqual(escape(match_string));
});
it("should handle non-Latin digits when asked", function() {
expect(p.parse("2 Peter \u0662:\u0663-\u0664").osis()).toEqual("");
p.set_options({
non_latin_digits_strategy: "replace"
});
return expect(p.parse("2 Peter \u0662:\u0663-\u0664").osis()).toEqual("2Pet.2.3-2Pet.2.4");
});
it("should match basic books", function() {
var books, ref, s;
ref = p.match_books("Jeremiah, Genesisjer (NIV)"), s = ref[0], books = ref[1];
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
});
return expect(s).toEqual("\x1f0\x1f, Genesisjer (\x1e1\x1e)");
});
it("should match passage sequences", function() {
var j, len, post, ref, results, s, 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"]];
results = [];
for (j = 0, len = sequences.length; j < len; j++) {
ref = sequences[j], s = ref[0], post = ref[1];
s = s.replace(p.regexps.escaped_passage, function(match, $1, $2) {
return "R";
});
results.push(expect(s).toEqual(post));
}
return results;
});
it("should handle consecutive checking", function() {
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();
return 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", function() {
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();
return expect(p.starts_with_book({
type: "range",
start: {
type: "integer"
}
})).toBeFalsy();
});
it("should turn on/off the Apocrypha", function() {
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();
return expect(p.options.include_apocrypha).toBeFalsy();
});
it("should handle case-sensitivity", function() {
var test_string;
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("");
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"
});
return expect(p.parse(test_string).osis()).toEqual("Heb.12,Exod.3,1Macc.2");
});
it("should replace ends correctly", function() {
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)");
return expect(p.replace_match_end("[\x1e0\x1e]")).toEqual("[\x1e0\x1e]");
});
return it("should pluck null passages", function() {
p.parse("Jonah 2");
expect(p.passage.pluck("none", [])).toEqual(null);
return expect(p.passage.pluck("none", [
{
type: "b"
}
])).toEqual(null);
});
});
describe("OSIS parsing strategies", function() {
var p, translation;
p = {};
translation = {};
beforeEach(function() {
p = new bcv_parser;
p.reset();
translation = "default";
return p.options.book_alone_strategy = "ignore";
});
it("should return OSIS for b-b with various parsing strategies", function() {
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");
return 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", function() {
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");
return 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", function() {
p.options.osis_compaction_strategy = "b";
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");
return 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", function() {
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");
return 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", function() {
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");
return 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", function() {
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");
return expect(p.to_osis({
b: "Gen",
c: 1
}, {
b: "Rev",
c: 1,
v: 1
}, translation)).toEqual("Gen.1.1-Rev.1.1");
});
return it("should return OSIS for bcvs", function() {
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");
return 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", function() {
var p, psg, translation_obj;
p = new bcv_parser;
psg = {};
translation_obj = {
translation: "default",
osis: "",
alias: "default"
};
beforeEach(function() {
p = new bcv_parser;
p.reset();
return psg = p.passage;
});
it("should handle start indices", function() {
psg.books = [
{
start_index: 0,
value: "Genesis"
}, {
start_index: 12,
value: "N"
}
];
expect(psg.calculate_indices("\x1f0\x1f 2:3", 0)).toEqual([
{
start: 0,
end: 1,
index: 0
}, {
start: 2,
end: 6,
index: 4
}
]);
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"
}
];
expect(psg.calculate_indices("pre\x1f0\x1f 2:3", "0")).toEqual([
{
start: 0,
end: 4,
index: 0
}, {
start: 5,
end: 9,
index: 4
}
]);
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"
}
];
return 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", function() {
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]);
return expect(psg.get_absolute_indices([3, 5])).toEqual([9, null]);
});
it("should validate refs with starts only", function() {
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
}
});
return 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", function() {
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
}
});
return 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", function() {
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
}
]);
return expect(psg.validate_start_ref("default", {
b: "None",
c: 2,
v: 1
}, {})).toEqual([
false, {
start_book_not_exist: true
}
]);
});
it("should validate end refs", function() {
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
}
]);
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
}
]);
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, {}]);
return 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", function() {
expect(psg.validate_ref([
{
translation: "default",
osis: "",
alias: "default"
}, {
translation: "niv",
alias: "default"
}
], {
b: "1Pet",
c: 3
})).toEqual({
valid: true,
messages: {}
});
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: {}
});
expect(psg.validate_ref("12", {
b: "Obad",
c: 1
})).toEqual({
valid: false,
messages: {
translation_invalid: ["1", "2"]
}
});
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: {}
});
return expect(function() {
return psg.validate_ref([null], {
b: "Obad",
c: 1
});
}).toThrow();
});
it("should handle bvs posing as bcs", function() {
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: [
{