-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest.js
147 lines (127 loc) · 3.76 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
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
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import detectIndent from './index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const getFile = file => fs.readFileSync(path.join(__dirname, file), 'utf8');
test('detect the indent of a file with space indent', t => {
t.is(detectIndent(getFile('fixture/space.js')).indent, ' ');
});
test('return indentation stats for spaces', t => {
const stats = detectIndent(getFile('fixture/space.js'));
t.deepEqual(stats, {
amount: 4,
indent: ' ',
type: 'space',
});
});
test('return indentation stats for multiple tabs', t => {
const stats = detectIndent(getFile('fixture/tab-four.js'));
t.deepEqual(stats, {
amount: 4,
indent: '\t\t\t\t',
type: 'tab',
});
});
test('detect the indent of a file with tab indent', t => {
t.is(detectIndent(getFile('fixture/tab.js')).indent, '\t');
});
test('return indentation stats for tabs', t => {
const stats = detectIndent(getFile('fixture/tab.js'));
t.deepEqual(stats, {
amount: 1,
indent: '\t',
type: 'tab',
});
});
test('detect the indent of a file with equal tabs and spaces', t => {
t.is(detectIndent(getFile('fixture/mixed-tab.js')).indent, '\t');
});
test('return indentation stats for equal tabs and spaces', t => {
const indent = detectIndent(getFile('fixture/mixed-tab.js'));
t.deepEqual(indent, {
amount: 1,
indent: '\t',
type: 'tab',
});
});
test('detect the indent of a file with mostly spaces', t => {
const stats = detectIndent(getFile('fixture/mixed-space.js'));
t.is(stats.indent, ' ');
});
test('return indentation stats for mostly spaces', t => {
const stats = detectIndent(getFile('fixture/mixed-space.js'));
t.deepEqual(stats, {
amount: 4,
indent: ' ',
type: 'space',
});
});
test('detect the indent of a weirdly indented vendor prefixed CSS', t => {
const stats = detectIndent(getFile('fixture/vendor-prefixed-css.css'));
t.is(stats.indent, ' ');
});
test('return indentation stats for various spaces', t => {
const stats = detectIndent(getFile('fixture/vendor-prefixed-css.css'));
t.deepEqual(stats, {
amount: 4,
indent: ' ',
type: 'space',
});
});
test('return `0` when there is no indentation', t => {
t.is(detectIndent('<ul></ul>').amount, 0);
});
test('return indentation stats for no indentation', t => {
const stats = detectIndent('<ul></ul>');
t.deepEqual(stats, {
amount: 0,
indent: '',
type: undefined,
});
});
test('return indentation stats for fifty-fifty indented files with spaces first', t => {
const stats = detectIndent(getFile('fixture/fifty-fifty-space-first.js'));
t.deepEqual(stats, {
amount: 4,
indent: ' ',
type: 'space',
});
});
test('return indentation stats for fifty-fifty indented files with tabs first', t => {
const stats = detectIndent(getFile('fixture/fifty-fifty-tab-first.js'));
t.deepEqual(stats, {
amount: 1,
indent: ' ',
type: 'tab',
});
});
test('return indentation stats for indented files with spaces and tabs last', t => {
const stats = detectIndent(getFile('fixture/space-tab-last.js'));
t.deepEqual(stats, {
amount: 1,
indent: ' ',
type: 'tab',
});
});
test('detect the indent of a file with single line comments', t => {
const stats = detectIndent(getFile('fixture/single-space-ignore.js'));
t.deepEqual(stats, {
amount: 4,
indent: ' ',
type: 'space',
});
});
test('return indentations status for indented files with single spaces only', t => {
const stats = detectIndent(getFile('fixture/single-space-only.js'));
t.deepEqual(stats, {
amount: 1,
indent: ' ',
type: 'space',
});
});
test('detect the indent of a file with many repeats after a single indent', t => {
const stats = detectIndent(getFile('fixture/long-repeat.js'));
t.is(stats.amount, 4);
});