Skip to content

Commit 03f8d9a

Browse files
authored
Add test that verifies all of TS parses (#95)
1 parent a876515 commit 03f8d9a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

internal/compiler/parser_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package compiler
22

33
import (
4+
"io/fs"
5+
"os"
6+
"path/filepath"
47
"testing"
58

69
"github.com/microsoft/typescript-go/internal/core"
10+
"github.com/microsoft/typescript-go/internal/repo"
11+
"github.com/microsoft/typescript-go/internal/tspath"
12+
"gotest.tools/v3/assert"
713
)
814

915
func BenchmarkParse(b *testing.B) {
@@ -20,3 +26,40 @@ func BenchmarkParse(b *testing.B) {
2026
})
2127
}
2228
}
29+
30+
func TestParseTypeScriptSrc(t *testing.T) {
31+
t.Parallel()
32+
33+
srcDir := filepath.Join(repo.TypeScriptSubmodulePath, "src")
34+
35+
if _, err := os.Stat(srcDir); os.IsNotExist(err) {
36+
t.Skipf("TypeScript submodule not found at %s", srcDir)
37+
}
38+
39+
err := filepath.WalkDir(srcDir, func(path string, d fs.DirEntry, err error) error {
40+
if err != nil {
41+
return err
42+
}
43+
44+
if d.IsDir() || tspath.TryExtractTSExtension(path) == "" {
45+
return nil
46+
}
47+
48+
testName, err := filepath.Rel(srcDir, path)
49+
assert.NilError(t, err)
50+
testName = filepath.ToSlash(testName)
51+
52+
t.Run(testName, func(t *testing.T) {
53+
t.Parallel()
54+
55+
sourceText, err := os.ReadFile(path)
56+
assert.NilError(t, err)
57+
58+
sourceFile := ParseSourceFile(path, string(sourceText), core.ScriptTargetESNext)
59+
assert.Equal(t, len(sourceFile.Diagnostics()), 0)
60+
})
61+
62+
return nil
63+
})
64+
assert.NilError(t, err)
65+
}

0 commit comments

Comments
 (0)