tangled
alpha
login
or
join now
tbeseda.com
/
array-treeify
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
isolated issue in edge-cases.test.ts
tbeseda.com
11 months ago
eea7844a
924c8a67
+77
-51
3 changed files
expand all
collapse all
unified
split
src
edge-cases.test.ts
index.test.ts
readme-examples.test.ts
+23
src/edge-cases.test.ts
···
1
1
+
import assert from 'node:assert'
2
2
+
import { describe, test } from 'node:test'
3
3
+
import { treeify } from './index.js'
4
4
+
5
5
+
describe('edge cases', () => {
6
6
+
test('root with nested children and sibling', () => {
7
7
+
const input = [
8
8
+
'root',
9
9
+
['child1', ['grandchild1', 'grandchild2']],
10
10
+
'sibling',
11
11
+
]
12
12
+
const expected = `root
13
13
+
├─ child1
14
14
+
│ ├─ grandchild1
15
15
+
│ └─ grandchild2
16
16
+
└─ sibling`
17
17
+
18
18
+
const result = treeify(input)
19
19
+
console.log('\nRoot with nested children and sibling:')
20
20
+
console.log(result)
21
21
+
assert.strictEqual(result, expected)
22
22
+
})
23
23
+
})
-51
src/index.test.ts
···
132
132
console.log(`\n${treeify(input3)}`)
133
133
})
134
134
})
135
135
-
136
136
-
describe('readme examples', () => {
137
137
-
test('basic example', () => {
138
138
-
const eagan = [
139
139
-
'Kier Eagan',
140
140
-
['...', ['...', 'Jame Eagan', ['Helena Eagan']]],
141
141
-
'Ambrose Eagan',
142
142
-
]
143
143
-
const expected = `Kier Eagan
144
144
-
├─ ...
145
145
-
| ├─ ...
146
146
-
| └─ Jame Eagan
147
147
-
| └─ Helena Eagan
148
148
-
└─ Ambrose Eagan`
149
149
-
150
150
-
const result = treeify(eagan)
151
151
-
console.log('\nBasic example:')
152
152
-
console.log(result)
153
153
-
assert.strictEqual(result, expected)
154
154
-
})
155
155
-
156
156
-
test('nested example', () => {
157
157
-
const orgChart = [
158
158
-
'Lumon Industries',
159
159
-
[
160
160
-
'Board of Directors',
161
161
-
['Natalie (Representative)'],
162
162
-
'Department Heads',
163
163
-
[
164
164
-
'Cobel (MDR)',
165
165
-
['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']],
166
166
-
],
167
167
-
],
168
168
-
]
169
169
-
const expected = `Lumon Industries
170
170
-
├─ Board of Directors
171
171
-
│ └─ Natalie (Representative)
172
172
-
└─ Department Heads
173
173
-
└─ Cobel (MDR)
174
174
-
├─ Milchick
175
175
-
└─ Mark S.
176
176
-
├─ Dylan G.
177
177
-
├─ Irving B.
178
178
-
└─ Helly R.`
179
179
-
180
180
-
const result = treeify(orgChart)
181
181
-
console.log('\nNested example:')
182
182
-
console.log(result)
183
183
-
assert.strictEqual(result, expected)
184
184
-
})
185
185
-
})
+54
src/readme-examples.test.ts
···
1
1
+
import assert from 'node:assert'
2
2
+
import { describe, test } from 'node:test'
3
3
+
import { treeify } from './index.js'
4
4
+
5
5
+
describe('readme examples', () => {
6
6
+
test('basic example', () => {
7
7
+
const eagan = [
8
8
+
'Kier Eagan',
9
9
+
['...', ['...', 'Jame Eagan', ['Helena Eagan']]],
10
10
+
'Ambrose Eagan',
11
11
+
]
12
12
+
const expected = `Kier Eagan
13
13
+
├─ ...
14
14
+
| ├─ ...
15
15
+
| └─ Jame Eagan
16
16
+
| └─ Helena Eagan
17
17
+
└─ Ambrose Eagan`
18
18
+
19
19
+
const result = treeify(eagan)
20
20
+
console.log('\nBasic example:')
21
21
+
console.log(result)
22
22
+
assert.strictEqual(result, expected)
23
23
+
})
24
24
+
25
25
+
test('nested example', () => {
26
26
+
const orgChart = [
27
27
+
'Lumon Industries',
28
28
+
[
29
29
+
'Board of Directors',
30
30
+
['Natalie (Representative)'],
31
31
+
'Department Heads',
32
32
+
[
33
33
+
'Cobel (MDR)',
34
34
+
['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']],
35
35
+
],
36
36
+
],
37
37
+
]
38
38
+
const expected = `Lumon Industries
39
39
+
├─ Board of Directors
40
40
+
│ └─ Natalie (Representative)
41
41
+
└─ Department Heads
42
42
+
└─ Cobel (MDR)
43
43
+
├─ Milchick
44
44
+
└─ Mark S.
45
45
+
├─ Dylan G.
46
46
+
├─ Irving B.
47
47
+
└─ Helly R.`
48
48
+
49
49
+
const result = treeify(orgChart)
50
50
+
console.log('\nNested example:')
51
51
+
console.log(result)
52
52
+
assert.strictEqual(result, expected)
53
53
+
})
54
54
+
})