Skip to content

Commit 9bdf5b7

Browse files
committed
✅ Test a bit more
1 parent 804d573 commit 9bdf5b7

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

packages/all/langs.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import test from 'node:test'
1+
import { Lang as LangNapi } from '@ast-grep/napi'
2+
import test, { describe } from 'node:test'
23
import { Lang } from './langs.js'
34

45
/** Languages supported in `@ast-grep/napi@~0.33.1`. */
@@ -28,6 +29,14 @@ const previous = Object.freeze({
2829
Swift: 'Swift',
2930
})
3031

31-
test('The new language enum is compatible with the old one', ({ assert }) => {
32-
for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang)
32+
describe('Lang', () => {
33+
test('The new language enum is compatible with the old one', ({ assert }) => {
34+
for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang)
35+
})
36+
37+
test('The new language enum is compatible with the built-in ones', ({
38+
assert,
39+
}) => {
40+
for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang)
41+
})
3342
})

packages/all/register.test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
import test from 'node:test'
1+
import { parse } from '@ast-grep/napi'
2+
import { before, describe, test } from 'node:test'
3+
import { Lang } from './langs.js'
24
import { registerDynamicLanguage } from './register.js'
35

4-
test('registerDynamicLanguage', () => registerDynamicLanguage())
6+
describe('registerDynamicLanguage', () => {
7+
before(() => registerDynamicLanguage())
8+
9+
// A newly supported language
10+
test(Lang.Dart, ({ assert }) => {
11+
const sg = parse(Lang.Dart, 'var x = "Hello, world!";"')
12+
const kind = sg.root().kind()
13+
assert.equal(kind, 'program')
14+
})
15+
16+
// A previously supported language
17+
test(Lang.Go, ({ assert }) => {
18+
const sg = parse(Lang.Dart, 'x := "Hello, world!"')
19+
const kind = sg.root().kind()
20+
assert.equal(kind, 'program')
21+
})
22+
23+
// A built-in language
24+
test(Lang.TypeScript, ({ assert }) => {
25+
const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"')
26+
const kind = sg.root().kind()
27+
assert.equal(kind, 'program')
28+
})
29+
})

0 commit comments

Comments
 (0)