Skip to content

Commit 032c512

Browse files
committed
Update tests
1 parent b82429f commit 032c512

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

maml.test.js renamed to spec/v0.1/maml.test.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { beforeAll, test } from 'vitest'
1+
import { test } from 'vitest'
2+
import path from 'node:path'
23
import { parseFile } from 'abnf'
34
import peggy from 'peggy'
45

5-
let parse
6-
7-
beforeAll(async () => {
8-
const rules = await parseFile('spec/v0.1/maml.abnf')
6+
async function generateParser(startRule = 'maml') {
7+
const __dirname = new URL('.', import.meta.url).pathname
8+
const rules = await parseFile(path.join(__dirname, 'maml.abnf'))
99
const text = rules.toFormat()
1010
const doParse = peggy.generate(text, {startRule: 'maml'})?.parse
1111
if (!doParse) throw new Error('Parser generation failed')
12-
parse = (input) => {
12+
return (input) => {
1313
try {
1414
doParse(input, {grammarSource: 'input'})
1515
} catch (e) {
@@ -22,15 +22,17 @@ beforeAll(async () => {
2222
}
2323
}
2424
}
25-
})
25+
}
2626

27-
test('simple', () => {
27+
test('simple', async () => {
28+
const parse = await generateParser()
2829
parse(`null`)
2930
parse(`true`)
3031
parse(`false`)
3132
})
3233

33-
test('object', () => {
34+
test('object', async () => {
35+
const parse = await generateParser()
3436
parse(`{"a":1,"b":2}`)
3537
parse(` { "a" : 1 , "b" : 2 } `)
3638
parse(`
@@ -47,7 +49,8 @@ test('object', () => {
4749
`)
4850
})
4951

50-
test('object with comments', () => {
52+
test('object with comments', async () => {
53+
const parse = await generateParser()
5154
parse(`
5255
# before
5356
{}
@@ -62,7 +65,8 @@ test('object with comments', () => {
6265
`)
6366
})
6467

65-
test('array', () => {
68+
test('array', async () => {
69+
const parse = await generateParser()
6670
parse(`[]`)
6771
parse(`[1,2,3]`)
6872
parse(`
@@ -81,7 +85,8 @@ test('array', () => {
8185
`)
8286
})
8387

84-
test('array with comments', () => {
88+
test('array with comments', async () => {
89+
const parse = await generateParser()
8590
parse(`
8691
# before
8792
[]
@@ -98,7 +103,8 @@ test('array with comments', () => {
98103
`)
99104
})
100105

101-
test('string', () => {
106+
test('string', async () => {
107+
const parse = await generateParser()
102108
parse(`""`)
103109
parse(`"a"`)
104110

0 commit comments

Comments
 (0)