-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathexamples.test.ts
116 lines (112 loc) · 3.46 KB
/
examples.test.ts
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
import { describe, test, expect } from 'vitest'
import fs from 'fs'
import path from 'path'
import run from '../src/run.js'
import { options } from './prepare.js'
const parsePosition = (str, index) => {
const rows = str.split('\n')
const rowLengthList = rows.map((substr) => substr.length)
let row = 0
let column = 0
let line = ''
while (index >= 0 && rows.length) {
row++
column = index
line = rows.shift()
index -= rowLengthList.shift() + 1
}
return {
offset: index,
row,
column,
line
}
}
// const expectedValidationsInfo = {
// 1: [20, 21, 26, 29],
// 3: [22, 25, 27, 34],
// 5: [20, 24, 27, 31, 35, 37, 41, 44, 47, 48, 51, 55, 58],
// 7: [],
// 9: [],
// 11: [20, 22, 25, 29, 34, 35, 39, 42, 45],
// 13: [15, 16, 17, 18, 35, 36],
// 15: [24, 53, 55, 57],
// 17: [26, 30, 37, 39, 43, 45, 48, 50, 57, 59, 66, 72],
// 19: [15, 30, 28],
// 21: [18, 25, 20, 23],
// 23: [36, 41],
// 25: [32, 35, 39, 42, 46, 48, 52, 54],
// 27: []
// }
describe('combo lint', () => {
test('rule units', () => {
const input = fs.readFileSync(
path.resolve(__dirname, './example-units.md'),
{ encoding: 'utf8' }
)
const output = fs.readFileSync(
path.resolve(__dirname, './example-units-fixed.md'),
{ encoding: 'utf8' }
)
const { result, validations, disabled } = run(input, options)
expect(result).toBe(output)
expect(!disabled).toBeTruthy()
const validationsByLine = {}
validations.forEach((v) => {
const { index, length, target } = v
const finalIndex =
target === 'spaceAfter' || target === 'endValue'
? index + length
: index
const { row, column } = parsePosition(input, finalIndex)
validationsByLine[row] = validationsByLine[row] || {}
validationsByLine[row][column] = v
})
// Object.keys(expectedValidationsInfo).forEach((row) => {
// const info = expectedValidationsInfo[row]
// const lineValidations = validationsByLine[row] || {}
// expect(Object.keys(lineValidations).length).toBe(info.length)
// info.forEach((column) => expect(lineValidations[column]).toBeTruthy())
// })
})
test('ignore HTML comment', () => {
const input = fs.readFileSync(
path.resolve(__dirname, './example-ignore.md'),
{ encoding: 'utf8' }
)
const { result, validations, disabled } = run(input, options)
expect(result).toBe(input)
expect(validations.length).toBe(0)
expect(!disabled).toBeTruthy()
})
test('disabled HTML comment', () => {
const input = fs.readFileSync(
path.resolve(__dirname, './example-disabled.md'),
{ encoding: 'utf8' }
)
const { result, validations, disabled } = run(input, options)
expect(result).toBe(input)
expect(validations.length).toBe(0)
expect(disabled).toBe(true)
})
test('support vuepress-special syntax', () => {
const input = fs.readFileSync(
path.resolve(__dirname, './example-vuepress.md'),
{ encoding: 'utf8' }
)
const output = fs.readFileSync(
path.resolve(__dirname, './example-vuepress-fixed.md'),
{ encoding: 'utf8' }
)
const { result, validations } = run(input, options)
expect(result).toBe(output)
expect(validations.length).toBe(10)
})
test('vuejs guide article', () => {
const input = fs.readFileSync(
path.resolve(__dirname, './example-article.md'),
{ encoding: 'utf8' }
)
expect(run(input, options).result).toBe(input)
})
})