Skip to content

Commit

Permalink
Merge pull request #6 from translationCoreApps/feature-mcleanb-5051
Browse files Browse the repository at this point in the history
Feature 5051/Add support for nested verse Objects
  • Loading branch information
richmahn authored Oct 12, 2018
2 parents 84f24f9 + 47dfebc commit 6dca089
Show file tree
Hide file tree
Showing 18 changed files with 3,877 additions and 408 deletions.
26 changes: 26 additions & 0 deletions __tests__/AlignmentHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ describe("Merge Alignment into Verse Objects", () => {
it('handles 1 timothy 3-16', () => {
mergeTest('v_1ti3-16');
});
it('handles acts 1-11', () => {
mergeTest('acts-1-11');
});
it('handles acts 1-4', () => {
mergeTest('acts-1-4');
});
it('handles acts 19-41', () => {
mergeTest('acts-19-41');
});
it('handles acts-1-4-unaligned-nested', () => {
let fail = false;
try {
mergeTest('acts-1-4-unaligned-nested');
fail = false;
} catch (e) {
console.log(e);
fail = true;
}
expect(fail).toBeTruthy();
});
});

describe("UnMerge Alignment from Verse Objects", () => {
Expand Down Expand Up @@ -127,6 +147,12 @@ describe("UnMerge Alignment from Verse Objects", () => {
it('handles 1 timothy 3-16', () => {
unmergeTest('v_1ti3-16');
});
it('handles acts 1-11', () => {
unmergeTest('acts-1-11');
});
it('handles acts 1-4', () => {
unmergeTest('acts-1-4');
});
});

describe('wordaligner.generateBlankAlignments', () => {
Expand Down
97 changes: 69 additions & 28 deletions __tests__/ArrayHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,126 @@ import * as ArrayUtils from '../src/js/utils/array';
describe("groupConsecutiveNumbers", () => {
it('handles all consecutive numbers', () => {
const numbers = [1, 2, 3, 4];
const result = ArrayUtils.groupConsecutiveNumbers(numbers);
const a = [];
const wordMap = createWordMap(5, a);
const result = ArrayUtils.groupConsecutiveNumbers(numbers, wordMap);
const expected = [[1, 2, 3, 4]];
expect(result).toEqual(expected);
});
it('handles all non-consecutive numbers', () => {
const numbers = [1, 3, 5, 7];
const result = ArrayUtils.groupConsecutiveNumbers(numbers);
const a = [];
const wordMap = createWordMap(8, a);
const result = ArrayUtils.groupConsecutiveNumbers(numbers, wordMap);
const expected = [[1], [3], [5], [7]];
expect(result).toEqual(expected);
});
it('handles mixed consecutive and non-consecutive numbers', () => {
const numbers = [1, 2, 4, 3, 5, 6];
const result = ArrayUtils.groupConsecutiveNumbers(numbers);
const a = [];
const wordMap = createWordMap(7, a);
const result = ArrayUtils.groupConsecutiveNumbers(numbers, wordMap);
const expected = [[1, 2], [4], [3], [5, 6]];
expect(result).toEqual(expected);
});
it('handles out of order numbers', () => {
const numbers = [4, 3, 2, 1];
const result = ArrayUtils.groupConsecutiveNumbers(numbers);
const a = [];
const wordMap = createWordMap(7, a);
const result = ArrayUtils.groupConsecutiveNumbers(numbers, wordMap);
const expected = [[4], [3], [2], [1]];
expect(result).toEqual(expected);
});
it('handles all consecutive numbers with nested verseObjects', () => {
const numbers = [1, 2, 3, 4];
const a = [];
const b = [];
const wordMap = createWordMap(3, a).concat(createWordMap(3, b));
const result = ArrayUtils.groupConsecutiveNumbers(numbers, wordMap);
const expected = [[1, 2], [3, 4]];
expect(result).toEqual(expected);
});
});

describe("deleteIndices", () => {
it('handles deleting first', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [0];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [2, 3, 4];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 1}, {word: 2}, {word: 3}];
expect(result).toEqual(expected);
});
it('handles deleting last', () => {
const numbers = [1, 2, 3, 4];
const index = [numbers.length - 1];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [1, 2, 3];
const array = [];
const wordMap = createWordMap(4, array);
const index = [array.length - 1];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 0}, {word: 1}, {word: 2}];
expect(result).toEqual(expected);
});
it('handles deleting middle', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [1];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [1, 3, 4];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 0}, {word: 2}, {word: 3}];
expect(result).toEqual(expected);
});
it('handles deleting multiples', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [0, 2, 3];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [2];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 1}];
expect(result).toEqual(expected);
});
it('handles deleting all', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [0, 1, 2, 3];
const result = ArrayUtils.deleteIndices(numbers, index);
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [];
expect(result).toEqual(expected);
});
it('handles deleting none', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [1, 2, 3, 4];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 0}, {word: 1}, {word: 2}, {word: 3}];
expect(result).toEqual(expected);
});
it('handles deleting out of range', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [10];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [1, 2, 3, 4];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 0}, {word: 1}, {word: 2}, {word: 3}];
expect(result).toEqual(expected);
});
it('handles deleting out of range -1 if element not found', () => {
const numbers = [1, 2, 3, 4];
const array = [];
const wordMap = createWordMap(4, array);
const index = [-1];
const result = ArrayUtils.deleteIndices(numbers, index);
const expected = [1, 2, 3, 4];
const result = ArrayUtils.deleteIndices(array, index, wordMap);
const expected = [{word: 0}, {word: 1}, {word: 2}, {word: 3}];
expect(result).toEqual(expected);
});
});

//
// helpers
//

function createWordMap(size, array) {
const wordMap = [];
for (let pos = 0; pos < size; pos++) {
wordMap.push({
array,
pos
});
array.push({word: pos});
}
return wordMap;
}
24 changes: 16 additions & 8 deletions __tests__/VerseObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('VerseObjectUtils.getWordsFromVerseObjects', () => {
describe("getOrderedVerseObjectsFromString", () => {
it('handles words without punctuation', () => {
const string = "hello world";
const json = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
const expected = [
{
tag: "w",
Expand All @@ -131,12 +130,13 @@ describe("getOrderedVerseObjectsFromString", () => {
occurrences: 1
}
];
expect(json).toEqual(expected);
const {newVerseObjects, wordMap} = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
expect(newVerseObjects).toEqual(expected);
expect(wordMap.length).toEqual(expected.length);
});

it('handles words with punctuation', () => {
const string = "hello, world.";
const json = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
const expected = [
{
tag: "w",
Expand All @@ -161,12 +161,14 @@ describe("getOrderedVerseObjectsFromString", () => {
text: "."
}
];
expect(json).toEqual(expected);
const expectedWordCount = expected.filter(item => (item.type === "word")).length;
const {newVerseObjects, wordMap} = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
expect(newVerseObjects).toEqual(expected);
expect(wordMap.length).toEqual(expectedWordCount);
});

it('handles multiple occurrences of words and punctuation', () => {
const string = "son of David, son of Abraham.";
const json = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
const expected = [
{
tag: "w",
Expand Down Expand Up @@ -219,12 +221,14 @@ describe("getOrderedVerseObjectsFromString", () => {
text: "."
}
];
expect(json).toEqual(expected);
const expectedWordCount = expected.filter(item => (item.type === "word")).length;
const {newVerseObjects, wordMap} = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
expect(newVerseObjects).toEqual(expected);
expect(wordMap.length).toEqual(expectedWordCount);
});

it('handles embeded markers like footnotes', () => {
const string = "son of David, son of Abraham. \\f Footnotes shouldn't be rendered as text but as content in their own object.\\f*";
const json = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
const expected = [
{
tag: "w",
Expand Down Expand Up @@ -279,10 +283,14 @@ describe("getOrderedVerseObjectsFromString", () => {
{
tag: "f",
type: "footnote",
endTag: "f*",
content: "Footnotes shouldn't be rendered as text but as content in their own object."
}
];
expect(json).toEqual(expected);
const expectedWordCount = expected.filter(item => (item.type === "word")).length;
const {newVerseObjects, wordMap} = VerseObjectUtils.getOrderedVerseObjectsFromString(string);
expect(newVerseObjects).toEqual(expected);
expect(wordMap.length).toEqual(expectedWordCount);
});
});

Expand Down
Loading

0 comments on commit 6dca089

Please sign in to comment.