11package compiler
22
33import (
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
915func 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