Skip to content

Commit

Permalink
Merge pull request #9 from translationCoreApps/bugfix-mcleanb-5063
Browse files Browse the repository at this point in the history
Bugfix 5063/Fixes for white space on USFM export
  • Loading branch information
richmahn authored Oct 23, 2018
2 parents 4b5acab + 2fd25f6 commit 7327a56
Show file tree
Hide file tree
Showing 13 changed files with 5,092 additions and 14 deletions.
35 changes: 34 additions & 1 deletion __tests__/AlignmentHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ describe("Merge Alignment into Verse Objects", () => {
it('handles matt 1-1', () => {
mergeTest('matt1-1');
});
it('handles mat-4-6', () => {
mergeTest('mat-4-6');
});
it('handles mat-4-6.whitespace', () => {
mergeTest('mat-4-6.whitespace');
});
it('handles noncontiguous', () => {
mergeTest('noncontiguous');
});
Expand Down Expand Up @@ -97,6 +103,12 @@ describe("UnMerge Alignment from Verse Objects", () => {
it('handles matt 1-1', () => {
unmergeTest('matt1-1');
});
it('handles mat-4-6', () => {
unmergeTest('mat-4-6');
});
it('handles mat-4-6.whitespace', () => {
unmergeTest('mat-4-6.whitespace');
});
it('handles noncontiguous', () => {
unmergeTest('noncontiguous');
});
Expand Down Expand Up @@ -133,6 +145,9 @@ describe("export USFM3 from Verse Objects", () => {
it('handles acts 1-4', () => {
exportTest('acts-1-4');
});
it('handles mat-4-6.whitespace', () => {
exportTest('mat-4-6.whitespace');
});
});

describe('wordaligner.generateBlankAlignments', () => {
Expand Down Expand Up @@ -282,6 +297,21 @@ const unmergeTest = (name = {}) => {
expect(output).toEqual({alignment, wordBank});
};

function normalizeAtributes(tag, source) {
let parts = source.split(tag);
const length = parts.length;
for (let i = 1; i < length; i++) {
const part = parts[i];
let lines = part.split('\n');
let attributes = lines[0].split(' ');
attributes = attributes.sort();
lines[0] = attributes.join(' ');
parts[i] = lines.join('\n');
}
const normalized = parts.join(tag);
return normalized;
}

/**
* Generator for testing merging of alignment into verseObjects
* @param {string} name - the name of the test files to use. e.g. `valid` will test `valid.usfm` to `valid.json`
Expand All @@ -306,6 +336,9 @@ const exportTest = (name = {}) => {
if (usfm.substr(0, 1) === ' ') {
usfm = usfm.substr(1);
}
expect(usfm).toEqual(expectedUsfm);
const tag = "\\zaln-s | ";
const outputNormal = normalizeAtributes(tag, usfm);
const expectedNormal = normalizeAtributes(tag, expectedUsfm);
expect(outputNormal).toEqual(expectedNormal);
};

Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,32 @@ describe("getWordListFromVerseObjectArray", () => {
const verseWords = VerseObjectUtils.mergeVerseData(results);
expect(verseWords).toEqual(expected);
});

it('handles en ULT', () => {
// given
const testFile = path.join('__tests__', 'fixtures', 'verseObjects', 'mat-4-6.json');
const testData = fs.readJSONSync(testFile);
const expected = "and said to him If you are the Son of God throw yourself down for it is written He will command his angels to take care of you and They will lift you up in their hands so that you will not hit your foot against a stone";

// when
const results = VerseObjectUtils.getWordListFromVerseObjectArray(testData);

// then
const verseWords = VerseObjectUtils.mergeVerseData(results);
expect(verseWords).toEqual(expected);
});
});

describe("getWordListForVerse", () => {
it('handles arrays with punctuation', () => {
// given
const testFile = path.join('__tests__', 'fixtures', 'verseObjects', 'heb-12-27.grc.json');
const testData = fs.readJSONSync(testFile);

// when
const results = VerseObjectUtils.getWordListForVerse(testData.verseObjects);

// then
expect(results).toEqual(testData.wordList);
});
});
Loading

0 comments on commit 7327a56

Please sign in to comment.