-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
84 lines (76 loc) · 2.79 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import assert from 'node:assert/strict'
import test from 'node:test'
import structuredClone from '@ungap/structured-clone'
import {ParseEnglish} from 'parse-english'
import retextPos from 'retext-pos'
import {unified} from 'unified'
import {u} from 'unist-builder'
import {removePosition} from 'unist-util-remove-position'
test('retext-pos', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('retext-pos')).sort(), [
'default'
])
})
await t.test('should work', async function () {
const tree = new ParseEnglish().parse(
'I went to the store, to buy 5.2 gallons of milk.'
)
await unified().use(retextPos).run(tree)
removePosition(tree, {force: true})
assert.deepEqual(
tree,
u('RootNode', [
u('ParagraphNode', [
u('SentenceNode', [
u('WordNode', {data: {partOfSpeech: 'PRP'}}, [u('TextNode', 'I')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'VBD'}}, [
u('TextNode', 'went')
]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'TO'}}, [u('TextNode', 'to')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'DT'}}, [u('TextNode', 'the')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'NN'}}, [
u('TextNode', 'store')
]),
u('PunctuationNode', ','),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'TO'}}, [u('TextNode', 'to')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'VB'}}, [u('TextNode', 'buy')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'CD'}}, [
u('TextNode', '5'),
u('PunctuationNode', '.'),
u('TextNode', '2')
]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'NNS'}}, [
u('TextNode', 'gallons')
]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'IN'}}, [u('TextNode', 'of')]),
u('WhiteSpaceNode', ' '),
u('WordNode', {data: {partOfSpeech: 'NN'}}, [
u('TextNode', 'milk')
]),
u('PunctuationNode', '.')
])
])
])
)
})
await t.test('should support an empty sentence', async function () {
const tree = u('RootNode', [
u('ParagraphNode', [
u('SentenceNode', [u('SymbolNode', '&'), u('PunctuationNode', '.')])
])
])
const expected = structuredClone(tree)
await unified().use(retextPos).run(tree)
assert.deepEqual(tree, expected)
})
})