Skip to content

Commit

Permalink
NEW: allow characters adjacent to brackets within words (#18)
Browse files Browse the repository at this point in the history
closes #18
  • Loading branch information
dwhieb authored Jul 7, 2020
1 parent 9ebcd2f commit 9e47c1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion alignWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function alignWords(lines, options = {}) {

const [leftBracket, rightBracket] = groupWith.trim().split(``);

let wordRegExp = /(?<bracketed>\[.*?\])|(?<unbracketed>[^\s]+)/gu;
let wordRegExp = /(?<bracketed>\S*\[.*?\]\S*)|(?<unbracketed>\S+)/gu;

if (groupWith !== `[]`) {

Expand Down
18 changes: 10 additions & 8 deletions alignWords.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe(`alignWords`, function() {

});

it.only(`aligns by character length`, function() {
it(`aligns by character length`, function() {

const lines = [
`cafȩ́ word t̓aatn̓a ʔunaakʔaɬ`,
Expand All @@ -55,22 +55,24 @@ describe(`alignWords`, function() {

});

it(`groups words with [brackets]`, function() {
it.only(`groups words with [brackets]`, function() {

const lines = [
`waxdungu qasi [qapx cuyi]`,
`waxt-qungu qasi [qapx cuy-i]`,
`day-one man he.came`,
`word word [word word] [stem]-suffix prefix-[word word] [word word],`,
`m-m m [m m-m] [m]-m m-[m m] [m m]`,
`gl-gl gl gl gl-gl gl-[gl gl] gl`,
];

const expectedResult = [
`waxdungu qasi [qapx cuyi]`,
`waxt-qungu qasi [qapx cuy-i]`,
`day-one man he.came`,
`word word [word word] [stem]-suffix prefix-[word word] [word word],`,
`m-m m [m m-m] [m]-m m-[m m] [m m]`,
`gl-gl gl gl gl-gl gl-[gl gl] gl`,
];

const aligned = alignWords(lines);

console.log(JSON.stringify(aligned, null, 2));

aligned.forEach((line, i) => {

expect(line).to.be(expectedResult[i]);
Expand Down

0 comments on commit 9e47c1d

Please sign in to comment.