-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathparseMarkdown.test.js
136 lines (99 loc) · 2.19 KB
/
parseMarkdown.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
const test = require('ava')
const parseMarkdown = require('../lib/parseMarkdown')
const { isCommand, parseCommand } = parseMarkdown
test('simple', t => {
const res = parseMarkdown(`
## hey
This script is used to say hey.
> blockquote is unnecessary now and treated just like paragraph.
But it's very complex so I'm writing some instructions.
Run task \`goodbye\` after this.
\`\`\`js
console.log('key')
\`\`\`
## goodbye
hehehe
\`\`\`sh
echo goodbye
\`\`\`
`)
t.snapshot(res)
})
test('parseCommand', t => {
t.deepEqual(parseCommand('run task `blah`'), {
taskNames: ['blah'],
when: 'before',
inParallel: false
})
t.deepEqual(
parseCommand('Runs task `blah` in parallel after this task has completed'),
{
taskNames: ['blah'],
when: 'after',
inParallel: true
}
)
t.deepEqual(parseCommand('run task `blah` in parallel'), {
taskNames: ['blah'],
when: 'before',
inParallel: true
})
t.deepEqual(parseCommand('run tasks `blah`, `bleh`, and `blu`'), {
taskNames: ['blah', 'bleh', 'blu'],
when: 'before',
inParallel: false
})
t.deepEqual(
parseCommand('run tasks `blah`, `bleh`, and `blu` after this in parallel'),
{
taskNames: ['blah', 'bleh', 'blu'],
when: 'after',
inParallel: true
}
)
})
test('selected section', t => {
const section = `
## hey
This script is used to say hey.
### key
\`\`\`js
console.log('key')
\`\`\`
### goodbye
hehehe
\`\`\`sh
echo goodbye
\`\`\`
`
const res = parseMarkdown(section, { section: 'hey' })
t.snapshot(res)
})
test('use readme', t => {
const res = parseMarkdown(
`
# my project
cool
## usage
lorem
## build scripts
<!-- maid-tasks -->
### dev
some dev script
## license
MIT
`,
{ filepath: 'README.md' }
)
t.snapshot(res)
})
test('isCommand', t => {
t.false(isCommand('Run task'))
t.true(isCommand('Run task `blah`'))
t.true(isCommand('run Task `blah`'))
t.true(isCommand('Runs task `blah`'))
t.true(isCommand('Run tasks `blah` and `blah`'))
t.true(isCommand('Runs tasks `blah` and `blah`'))
t.true(isCommand('Run tasks `blah` and `blah` in parallel'))
t.true(isCommand('Run task `blah` after this in parallel'))
})