Skip to content

Commit

Permalink
Move diff_test.go to v1
Browse files Browse the repository at this point in the history
The diff_test.go suite of tests check for expected differences
between v1 and v2. In some ways, they are higher fidelity tests
for v1 behavior than the v1 tests themselves.

Modify diff_test.go to use the emulated v1 implementation
and skip the tests are currently failing.
  • Loading branch information
dsnet committed Dec 21, 2024
1 parent 764075c commit 446a168
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions diff_test.go → v1/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package json_test
package json

import (
"errors"
Expand All @@ -13,8 +13,6 @@ import (
"testing"
"time"

jsonv1 "encoding/json"

jsonv2 "github.com/go-json-experiment/json"
)

Expand All @@ -27,7 +25,7 @@ var jsonPackages = []struct {
Marshal func(any) ([]byte, error)
Unmarshal func([]byte, any) error
}{
{"v1", jsonv1.Marshal, jsonv1.Unmarshal},
{"v1", Marshal, Unmarshal},
{"v2",
func(in any) ([]byte, error) { return jsonv2.Marshal(in) },
func(in []byte, out any) error { return jsonv2.Unmarshal(in, out) }},
Expand Down Expand Up @@ -367,6 +365,7 @@ func TestStringOption(t *testing.T) {

for _, json := range jsonPackages {
t.Run(path.Join("Unmarshal/Null", json.Version), func(t *testing.T) {
skipKnownFailure(t)
var got Types
err := json.Unmarshal([]byte(`{
"Bool": "null",
Expand Down Expand Up @@ -416,6 +415,7 @@ func TestStringOption(t *testing.T) {
})

t.Run(path.Join("Unmarshal/Deep", json.Version), func(t *testing.T) {
skipKnownFailure(t)
var got Types
want := map[string]Types{
"v1": {
Expand Down Expand Up @@ -631,6 +631,7 @@ func TestPointerReceiver(t *testing.T) {

for _, json := range jsonPackages {
t.Run(path.Join("Marshal", json.Version), func(t *testing.T) {
skipKnownFailure(t)
var cc CallCheck
in := Values{
S: []CallCheck{cc},
Expand All @@ -655,6 +656,7 @@ func TestPointerReceiver(t *testing.T) {

for _, json := range jsonPackages {
t.Run(path.Join("Unmarshal", json.Version), func(t *testing.T) {
skipKnownFailure(t)
in := `{"S":[""],"A":[""],"M":{"":""},"V":"","I":""}`
called := CallCheck("CALLED") // resulting state if UnmarshalJSON is called
want := map[string]Values{
Expand Down Expand Up @@ -881,6 +883,7 @@ func TestMergeNull(t *testing.T) {

for _, json := range jsonPackages {
t.Run(path.Join("Unmarshal", json.Version), func(t *testing.T) {
skipKnownFailure(t)
// Start with a non-empty value where all fields are populated.
in := Types{
Bool: true,
Expand Down Expand Up @@ -960,6 +963,7 @@ func TestMergeComposite(t *testing.T) {

for _, json := range jsonPackages {
t.Run(path.Join("Unmarshal", json.Version), func(t *testing.T) {
skipKnownFailure(t)
// Start with a non-empty value where all fields are populated.
in := Composites{
Slice: []Tuple{{Old: true}, {Old: true}}[:1],
Expand Down
10 changes: 10 additions & 0 deletions v1/failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ TestNilMarshalerTextMapKey
TestEncoderSetEscapeHTML
TestEncoderSetEscapeHTML/stringOption
TestRawMessage
TestStringOption
TestStringOption/Unmarshal/Null/v1
TestStringOption/Unmarshal/Deep/v1
TestPointerReceiver
TestPointerReceiver/Marshal/v1
TestPointerReceiver/Unmarshal/v1
TestMergeNull
TestMergeNull/Unmarshal/v1
TestMergeComposite
TestMergeComposite/Unmarshal/v1

0 comments on commit 446a168

Please sign in to comment.