-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathgenerate-tree.test.ts
More file actions
164 lines (128 loc) · 3.21 KB
/
generate-tree.test.ts
File metadata and controls
164 lines (128 loc) · 3.21 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { generateTree } from './generate-tree';
import { mockInput } from './mock-input';
import { parseInput } from './parse-input';
describe('generateTree', () => {
it('returns an UTF-8 representation of the provided FileStructure object', () => {
const actual = generateTree(parseInput(mockInput));
const expected = `
.
├── my-app
│ ├── src
│ │ ├── index.html
│ │ ├── main.ts
│ │ └── main.scss
│ ├── build
│ │ ├── index.html
│ │ ├── main.js
│ │ └── main.css
│ ├── .prettierrc.json
│ ├── .gitlab-ci.yml
│ └── README.md
└── empty dir
`.trim();
expect(actual).toEqual(expected);
});
it('returns an ASCII representation of the provided FileStructure object', () => {
const actual = generateTree(parseInput(mockInput), { charset: 'ascii' });
const expected = `
.
|-- my-app
| |-- src
| | |-- index.html
| | |-- main.ts
| | \`-- main.scss
| |-- build
| | |-- index.html
| | |-- main.js
| | \`-- main.css
| |-- .prettierrc.json
| |-- .gitlab-ci.yml
| \`-- README.md
\`-- empty dir
`.trim();
expect(actual).toEqual(expected);
});
it('does not render lines for parent directories that have already printed all of their children', () => {
const input = `
grandparent
parent
child
parent
child
grandchild
`;
const actual = generateTree(parseInput(input));
const expected = `
.
└── grandparent
├── parent
│ └── child
└── parent
└── child
└── grandchild
`.trim();
expect(actual).toEqual(expected);
});
it('appends a trailing slash to directories if trailingDirSlash === true', () => {
const input = `
grandparent
parent/
child
parent//
child
grandchild
`;
const actual = generateTree(parseInput(input), { trailingDirSlash: true });
const expected = `
.
└── grandparent/
├── parent/
│ └── child
└── parent//
└── child/
└── grandchild
`.trim();
expect(actual).toEqual(expected);
});
it("prints each items' full path if fullPath === true", () => {
const input = `
grandparent
parent/
child
parent//
child
grandchild
`;
const actual = generateTree(parseInput(input), { fullPath: true });
const expected = `
.
└── ./grandparent
├── ./grandparent/parent/
│ └── ./grandparent/parent/child
└── ./grandparent/parent//
└── ./grandparent/parent//child
└── ./grandparent/parent//child/grandchild
`.trim();
expect(actual).toEqual(expected);
});
it('does not render the root dot if rootDot === false', () => {
const input = `
grandparent
parent
child
parent
child
grandchild
`;
const actual = generateTree(parseInput(input), { rootDot: false });
const expected = `
grandparent
├── parent
│ └── child
└── parent
└── child
└── grandchild
`.trim();
expect(actual).toEqual(expected);
});
});