Skip to content

Commit

Permalink
Remove test dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Jan 2, 2020
1 parent 7620272 commit 2da050b
Showing 1 changed file with 3 additions and 35 deletions.
38 changes: 3 additions & 35 deletions json5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"path/filepath"
"strings"
"testing"

"github.com/kylelemons/godebug/pretty"
"github.com/robertkrimen/otto"
)

type ErrorSpec struct {
Expand Down Expand Up @@ -42,64 +39,35 @@ func TestJSON5Decode(t *testing.T) {
var res interface{}
return res, json.Unmarshal(data, &res)
}
parseES5 := func() (interface{}, error) {
vm := otto.New()
_, err := vm.Run("x=" + string(data))
if err != nil {
return nil, err
}
v, err := vm.Get("x")
if err != nil {
return nil, err
}
return v.Export()
}

t.Logf("file: %s", path)
switch filepath.Ext(path) {
case ".json":
jd, err := parseJSON()
_, err := parseJSON()
if err != nil {
t.Errorf("unexpected error from json decoder: %s", err)
return nil
}
j5d, err := parseJSON5()
_, err = parseJSON5()
if err != nil {
t.Errorf("unexpected error from json5 decoder: %s", err)
return nil
}
if diff := pretty.Compare(jd, j5d); diff != "" {
t.Errorf("data is not equal\n%s", diff)
return nil
}
case ".json5":
if _, err := parseJSON(); err == nil {
t.Errorf("expected JSON parsing to fail")
return nil
}
es5d, err := parseES5()
if err != nil {
t.Errorf("unexpected error from ES5 decoder: %s", err)
return nil
}
j5d, err := parseJSON5()
_, err := parseJSON5()
if err != nil {
t.Errorf("unexpected error from json5 decoder: %s", err)
return nil
}
if diff := pretty.Compare(j5d, es5d); diff != "" {
t.Errorf("data is not equal\n%s", diff)
return nil
}
case ".js":
if _, err := parseJSON(); err == nil {
t.Errorf("expected JSON parsing to fail")
return nil
}
if _, err := parseES5(); err != nil {
t.Errorf("unexected error from ES5 decoder: %s", err)
return nil
}
if _, err := parseJSON5(); err == nil {
t.Errorf("expected JSON5 parsing to fail")
return nil
Expand Down

0 comments on commit 2da050b

Please sign in to comment.