Skip to content

Commit 7978b05

Browse files
Anonymouseh-steve
Anonymous
authored andcommitted
Test for Issue pkujhd#74
1 parent c296023 commit 7978b05

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Diff for: jit/jit_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,39 @@ func TestGCGlobals(t *testing.T) {
13471347
}
13481348
}
13491349

1350+
func TestJson(t *testing.T) {
1351+
conf := jit.BuildConfig{
1352+
GoBinary: goBinary,
1353+
KeepTempFiles: false,
1354+
ExtraBuildFlags: nil,
1355+
BuildEnv: nil,
1356+
TmpDir: "",
1357+
DebugLog: false,
1358+
RandomSymbolNameOrder: false,
1359+
}
1360+
1361+
data := testData{
1362+
files: []string{"./testdata/test_json_marshal/test.go"},
1363+
pkg: "./testdata/test_json_marshal",
1364+
}
1365+
testNames := []string{"BuildGoFiles", "BuildGoPackage", "BuildGoText"}
1366+
for _, testName := range testNames {
1367+
t.Run(testName, func(t *testing.T) {
1368+
module, symbols := buildLoadable(t, conf, testName, data)
1369+
1370+
testFunc := symbols["TestJSONMarshal"].(func() string)
1371+
1372+
if testFunc() != "1" {
1373+
t.Fatalf("expected \"1\" but got %s", testFunc())
1374+
}
1375+
err := module.Unload()
1376+
if err != nil {
1377+
t.Fatal(err)
1378+
}
1379+
})
1380+
}
1381+
}
1382+
13501383
func TestTypeMismatch(t *testing.T) {
13511384
conf := baseConfig
13521385
conf.UnsafeBlindlyUseFirstmoduleTypes = false // If set to true, this test should fail (fault)

Diff for: jit/testdata/test_json_marshal/test.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test_json_marshal
2+
3+
import (
4+
"encoding/json"
5+
)
6+
7+
type impl struct {
8+
a int
9+
}
10+
11+
func (impl) MarshalJSON() ([]byte, error) {
12+
return []byte("1"), nil
13+
}
14+
15+
func TestJSONMarshal() string {
16+
i := impl{}
17+
b, _ := json.Marshal(&i)
18+
return string(b)
19+
}

0 commit comments

Comments
 (0)