-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bb4bde
commit 807fbfe
Showing
2 changed files
with
41 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
import test from 'tape' | ||
import nlp from './_lib.js' | ||
|
||
// Duration ranges | ||
const durArr = [ | ||
{ | ||
text: ['2 to 4 days', '2-4 days', 'two to four days'], | ||
duration: { years: 0, months: 0, days: 3, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['1 to 2 weeks', '1-2 weeks', 'one to two weeks'], | ||
duration: { years: 0, months: 0, days: 14, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['1 to 5 months', '1-5 months', 'one to five months'], | ||
duration: { years: 0, months: 5, days: 0, hours: 0, minutes: 0 }, | ||
}, | ||
{ | ||
text: ['2 to 4 years', '2-4 years', 'two to four years'], | ||
duration: { years: 3, months: 0, days: 0, hours: 0, minutes: 0 }, | ||
}, | ||
] | ||
|
||
const context = { | ||
today: '2024-01-01', | ||
today: '2024-09-24', | ||
} | ||
|
||
test('future duration-ranges', function (t) { | ||
durArr.forEach(obj => { | ||
obj.text.forEach(str => { | ||
let text = `in ${str}` | ||
const doc = nlp(text) | ||
const { duration, start, end } = doc.dates(context).get()[0] | ||
t.deepEqual(duration, obj.duration, text) | ||
t.ok(start > context.today, 'start date') | ||
t.ok(end > start, 'end date') | ||
}) | ||
}) | ||
t.end() | ||
}) | ||
let arr = [ | ||
{ str: 'in 2 to 4 days', start: '2024-09-26', end: '2024-09-28' }, | ||
{ str: 'in 2-4 days', start: '2024-09-26', end: '2024-09-28' }, | ||
{ str: 'in two to four days', start: '2024-09-26', end: '2024-09-28' }, | ||
{ str: '2 to 4 days ago', start: '2024-09-20', end: '2024-09-22' }, | ||
{ str: '2-4 days ago', start: '2024-09-20', end: '2024-09-22' }, | ||
{ str: 'two to four days ago', start: '2024-09-20', end: '2024-09-22' }, | ||
|
||
{ str: 'in 1 to 2 weeks', start: '2024-10-01', end: '2024-10-07' }, | ||
{ str: 'in 1-2 weeks', start: '2024-10-01', end: '2024-10-07' }, | ||
{ str: 'in one to two weeks', start: '2024-10-01', end: '2024-10-07' }, | ||
{ str: '1 to 2 weeks ago', start: '2024-09-10', end: '2024-09-17' }, | ||
{ str: '1-2 weeks ago', start: '2024-09-10', end: '2024-09-17' }, | ||
{ str: 'one to two weeks ago', start: '2024-09-10', end: '2024-09-17' }, | ||
|
||
test('past duration-ranges', function (t) { | ||
durArr.forEach(obj => { | ||
obj.text.forEach(str => { | ||
let text = `${str} ago` | ||
const doc = nlp(text) | ||
const { duration, start, end } = doc.dates(context).get()[0] | ||
t.deepEqual(duration, obj.duration, text) | ||
t.ok(start < context.today, 'start date') | ||
t.ok(end > start, 'end date') | ||
}) | ||
{ str: 'in 1 to 5 months', start: '2024-10-24', end: '2025-02-24' }, | ||
{ str: 'in 1-5 months', start: '2024-10-24', end: '2025-02-24' }, | ||
{ str: 'in one to five months', start: '2024-10-24', end: '2025-02-24' }, | ||
{ str: '1 to 5 months ago', start: '2024-04-24', end: '2024-08-24' }, | ||
{ str: '1-5 months ago', start: '2024-04-24', end: '2024-08-24' }, | ||
{ str: 'one to five months ago', start: '2024-04-24', end: '2024-08-24' }, | ||
|
||
{ str: 'in 2 to 4 years', start: '2026-09-24', end: '2028-09-24' }, | ||
{ str: 'in 2-4 years', start: '2026-09-24', end: '2028-09-24' }, | ||
{ str: 'in two to four years', start: '2026-09-24', end: '2028-09-24' }, | ||
{ str: '2 to 4 years ago', start: '2020-09-24', end: '2022-09-24' }, | ||
{ str: '2-4 years ago', start: '2020-09-24', end: '2022-09-24' }, | ||
{ str: 'two to four years ago', start: '2020-09-24', end: '2022-09-24' }, | ||
] | ||
|
||
|
||
test('duration-ranges', function (t) { | ||
arr.forEach(obj => { | ||
const doc = nlp(obj.str) | ||
const { start, end } = doc.dates(context).get()[0] | ||
t.equal(start.replace(/T.*/, ''), obj.start, obj.str + ':start') | ||
t.equal(end.replace(/T.*/, ''), obj.end, obj.str + ':end') | ||
}) | ||
t.end() | ||
}) | ||
|