|
1 | | -import { groupByCommonHead } from './string'; |
| 1 | +import { build } from './trie'; |
2 | 2 |
|
3 | | -describe('groupByCommonHead', () => { |
4 | | - it('returns empty object when no words', () => { |
5 | | - expect(groupByCommonHead([])).toEqual({}); |
| 3 | +describe('build', () => { |
| 4 | + it('returns empty trie when no words', () => { |
| 5 | + expect(build([])).toEqual({}); |
6 | 6 | }); |
7 | 7 |
|
8 | 8 | it('returns the entirety of words when no common head', () => { |
9 | 9 | const words = ['bar', 'foo']; |
10 | | - expect(groupByCommonHead(words)).toEqual({ |
| 10 | + expect(build(words)).toEqual({ |
11 | 11 | bar: {}, |
12 | 12 | foo: {}, |
13 | 13 | }); |
14 | 14 | }); |
15 | 15 |
|
16 | 16 | it('returns the entirety of repeated equal words', () => { |
17 | 17 | const words = ['foo', 'foo', 'foo', 'foo']; |
18 | | - expect(groupByCommonHead(words)).toEqual({ |
| 18 | + expect(build(words)).toEqual({ |
19 | 19 | foo: {}, |
20 | 20 | }); |
21 | 21 | }); |
22 | 22 |
|
23 | 23 | it('returns the entirety of multiple, repeated equal words', () => { |
24 | 24 | const words = ['bar', 'bar', 'bar', 'bar', 'foo', 'foo', 'foo', 'foo']; |
25 | | - expect(groupByCommonHead(words)).toEqual({ |
| 25 | + expect(build(words)).toEqual({ |
26 | 26 | bar: {}, |
27 | 27 | foo: {}, |
28 | 28 | }); |
29 | 29 | }); |
30 | 30 |
|
31 | 31 | it('returns an empty string for partial words', () => { |
32 | 32 | const words = ['foo', 'foobar']; |
33 | | - expect(groupByCommonHead(words)).toEqual({ |
| 33 | + expect(build(words)).toEqual({ |
34 | 34 | foo: { '': {}, bar: {} }, |
35 | 35 | }); |
36 | 36 | }); |
37 | 37 |
|
38 | 38 | it('returns the common head of two words', () => { |
39 | 39 | const words = ['bar', 'baz']; |
40 | | - expect(groupByCommonHead(words)).toEqual({ |
| 40 | + expect(build(words)).toEqual({ |
41 | 41 | ba: { r: {}, z: {} }, |
42 | 42 | }); |
43 | 43 | }); |
44 | 44 |
|
45 | 45 | it('returns multiple depths of partial words', () => { |
46 | 46 | const words = ['foo', 'foobar', 'foobaz']; |
47 | | - expect(groupByCommonHead(words)).toEqual({ |
| 47 | + expect(build(words)).toEqual({ |
48 | 48 | foo: { '': {}, ba: { r: {}, z: {} } }, |
49 | 49 | }); |
50 | 50 | }); |
51 | 51 |
|
52 | 52 | it('returns the common head of multiple words', () => { |
53 | 53 | const words = ['bar', 'baz', 'quux', 'quuz']; |
54 | | - expect(groupByCommonHead(words)).toEqual({ |
| 54 | + expect(build(words)).toEqual({ |
55 | 55 | ba: { r: {}, z: {} }, |
56 | 56 | quu: { x: {}, z: {} }, |
57 | 57 | }); |
58 | 58 | }); |
59 | 59 |
|
60 | 60 | it('preserves leading whitespace', () => { |
61 | 61 | const words = [' foo', 'foo']; |
62 | | - expect(groupByCommonHead(words)).toEqual({ |
| 62 | + expect(build(words)).toEqual({ |
63 | 63 | ' foo': {}, |
64 | 64 | foo: {}, |
65 | 65 | }); |
66 | 66 | }); |
67 | 67 |
|
68 | 68 | it('preserves trailing whitespace', () => { |
69 | 69 | const words = ['foo ', 'foo']; |
70 | | - expect(groupByCommonHead(words)).toEqual({ |
| 70 | + expect(build(words)).toEqual({ |
71 | 71 | foo: { '': {}, ' ': {} }, |
72 | 72 | }); |
73 | 73 | }); |
74 | 74 |
|
75 | 75 | it('preserves mid-word whitespace', () => { |
76 | 76 | const words = ['foo bar', 'foobar']; |
77 | | - expect(groupByCommonHead(words)).toEqual({ |
| 77 | + expect(build(words)).toEqual({ |
78 | 78 | foo: { ' bar': {}, bar: {} }, |
79 | 79 | }); |
80 | 80 | }); |
81 | 81 |
|
82 | 82 | it('is case-sensitive with string heads', () => { |
83 | 83 | const words = ['Foo', 'foo']; |
84 | | - expect(groupByCommonHead(words)).toEqual({ |
| 84 | + expect(build(words)).toEqual({ |
85 | 85 | Foo: {}, |
86 | 86 | foo: {}, |
87 | 87 | }); |
88 | 88 | }); |
89 | 89 |
|
90 | 90 | it('is case-sensitive with string tails', () => { |
91 | 91 | const words = ['foo', 'foO']; |
92 | | - expect(groupByCommonHead(words)).toEqual({ |
| 92 | + expect(build(words)).toEqual({ |
93 | 93 | fo: { o: {}, O: {} }, |
94 | 94 | }); |
95 | 95 | }); |
|
0 commit comments