@@ -6,13 +6,15 @@ import (
6
6
"testing"
7
7
8
8
json2 "github.com/go-json-experiment/json"
9
+ "github.com/google/go-cmp/cmp/cmpopts"
9
10
"github.com/microsoft/typescript-go/internal/ast"
10
11
"github.com/microsoft/typescript-go/internal/core"
11
12
"github.com/microsoft/typescript-go/internal/packagejson"
12
13
"github.com/microsoft/typescript-go/internal/parser"
13
14
"github.com/microsoft/typescript-go/internal/repo"
14
15
"github.com/microsoft/typescript-go/internal/testutil/filefixture"
15
16
"github.com/microsoft/typescript-go/internal/tspath"
17
+ "gotest.tools/v3/assert"
16
18
)
17
19
18
20
var packageJsonFixtures = []filefixture.Fixture {
@@ -59,3 +61,44 @@ func BenchmarkPackageJSON(b *testing.B) {
59
61
})
60
62
}
61
63
}
64
+
65
+ func TestParse (t * testing.T ) {
66
+ t .Parallel ()
67
+
68
+ tests := []struct {
69
+ name string
70
+ content string
71
+ want packagejson.Fields
72
+ }{
73
+ {
74
+ name : "duplicate names" ,
75
+ content : `{
76
+ "name": "test-package",
77
+ "name": "test-package",
78
+ "version": "1.0.0"
79
+ }` ,
80
+ want : packagejson.Fields {
81
+ HeaderFields : packagejson.HeaderFields {
82
+ Name : packagejson .ExpectedOf ("test-package" ),
83
+ Version : packagejson .ExpectedOf ("1.0.0" ),
84
+ },
85
+ },
86
+ },
87
+ }
88
+
89
+ for _ , tt := range tests {
90
+ t .Run (tt .name , func (t * testing.T ) {
91
+ t .Parallel ()
92
+
93
+ got , err := packagejson .Parse ([]byte (tt .content ))
94
+ assert .NilError (t , err )
95
+ assert .DeepEqual (t , got , tt .want , cmpopts .IgnoreUnexported (
96
+ packagejson.Fields {},
97
+ packagejson.HeaderFields {},
98
+ packagejson.Expected [string ]{},
99
+ packagejson.Expected [map [string ]string ]{},
100
+ packagejson.ExportsOrImports {},
101
+ ))
102
+ })
103
+ }
104
+ }
0 commit comments