-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathparse-input.test.ts
More file actions
146 lines (127 loc) · 3.72 KB
/
parse-input.test.ts
File metadata and controls
146 lines (127 loc) · 3.72 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
import { FileStructure } from './FileStructure';
import { mockInput } from './mock-input';
import { parseInput, splitInput } from './parse-input';
describe('parse-input', () => {
it('parses plain text input into a FileStructure object', () => {
const actual = parseInput(mockInput);
const root: FileStructure = {
name: '.',
children: [],
indentCount: -1,
parent: null,
};
const myApp: FileStructure = {
name: 'my-app',
children: [],
indentCount: 0,
parent: root,
};
root.children.push(myApp);
const src: FileStructure = {
name: 'src',
children: [],
indentCount: 2,
parent: myApp,
};
myApp.children.push(src);
const srcIndexHtml: FileStructure = {
name: 'index.html',
children: [],
indentCount: 4,
parent: src,
};
src.children.push(srcIndexHtml);
const mainTs: FileStructure = {
name: 'main.ts',
children: [],
indentCount: 4,
parent: src,
};
src.children.push(mainTs);
const mainScss: FileStructure = {
name: 'main.scss',
children: [],
indentCount: 3,
parent: src,
};
src.children.push(mainScss);
const build: FileStructure = {
name: 'build',
children: [],
indentCount: 2,
parent: myApp,
};
myApp.children.push(build);
const buildIndexHtml: FileStructure = {
name: 'index.html',
children: [],
indentCount: 4,
parent: build,
};
build.children.push(buildIndexHtml);
const mainJs: FileStructure = {
name: 'main.js',
children: [],
indentCount: 4,
parent: build,
};
build.children.push(mainJs);
const mainCss: FileStructure = {
name: 'main.css',
children: [],
indentCount: 4,
parent: build,
};
build.children.push(mainCss);
const prettierRcJson: FileStructure = {
name: '.prettierrc.json',
children: [],
indentCount: 2,
parent: myApp,
};
myApp.children.push(prettierRcJson);
const gitlabCiYml: FileStructure = {
name: '.gitlab-ci.yml',
children: [],
indentCount: 2,
parent: myApp,
};
myApp.children.push(gitlabCiYml);
const readmeMd: FileStructure = {
name: 'README.md',
children: [],
indentCount: 2,
parent: myApp,
};
myApp.children.push(readmeMd);
const emptyDir: FileStructure = {
name: 'empty dir',
children: [],
indentCount: 0,
parent: root,
};
root.children.push(emptyDir);
expect(actual).toEqual(root);
});
});
describe('splitInput', () => {
it('splits plain text into an array of File Structure objects', () => {
const actual = splitInput(mockInput);
const expected = [
{ name: 'my-app', children: [], indentCount: 0, parent: null },
{ name: 'src', children: [], indentCount: 2, parent: null },
{ name: 'index.html', children: [], indentCount: 4, parent: null },
{ name: 'main.ts', children: [], indentCount: 4, parent: null },
{ name: 'main.scss', children: [], indentCount: 3, parent: null },
{ name: 'build', children: [], indentCount: 2, parent: null },
{ name: 'index.html', children: [], indentCount: 4, parent: null },
{ name: 'main.js', children: [], indentCount: 4, parent: null },
{ name: 'main.css', children: [], indentCount: 4, parent: null },
{ name: '.prettierrc.json', children: [], indentCount: 2, parent: null },
{ name: '.gitlab-ci.yml', children: [], indentCount: 2, parent: null },
{ name: 'README.md', children: [], indentCount: 2, parent: null },
{ name: 'empty dir', children: [], indentCount: 0, parent: null },
];
expect(actual).toEqual(expected);
});
});