github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/json/unmarshal_test.go (about)

     1  package json_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  	"github.com/lmorg/murex/utils/json"
     8  )
     9  
    10  type testCase struct {
    11  	Json     string
    12  	Expected string
    13  	Error    bool
    14  }
    15  
    16  func runTestCases(t *testing.T, tests []testCase) {
    17  	count.Tests(t, len(tests))
    18  
    19  	for i := range tests {
    20  		testMx(t, tests[i].Json, tests[i].Expected, tests[i].Error, i)
    21  	}
    22  }
    23  
    24  func testMx(t *testing.T, src string, sExp string, fail bool, testNum int) {
    25  	var v interface{}
    26  	err := json.UnmarshalMurex([]byte(src), &v)
    27  	/*bAct, jsonErr := corejson.Marshal(v)
    28  	if jsonErr != nil {
    29  		t.Errorf("Unable to marshal Go struct from mxjson unmarshaller, this is possibly an error with the standard library: %s", jsonErr.Error())
    30  	}
    31  
    32  	sAct := string(bAct)
    33  	bExp := []byte(sExp)*/
    34  
    35  	if (err != nil) != fail {
    36  		t.Errorf("Error response not as expected in test %d: ", testNum)
    37  		t.Logf("  mxjson:  %s", src)
    38  		t.Logf("  exp err: %v", fail)
    39  		t.Logf("  act err: %v", err)
    40  		/*t.Logf("  exp str: %s", sExp)
    41  		t.Logf("  act str: %s", sAct)
    42  		t.Log("  exp byt: ", bExp)
    43  		t.Log("  act byt: ", bAct)*/
    44  	}
    45  
    46  	/*if sExp == "" && v == nil {
    47  		return
    48  	}
    49  
    50  	if sExp != sAct {
    51  		t.Errorf("Output doesn't match expected in test %d: ", testNum)
    52  		t.Logf("  mxjson:  %s", src)
    53  		t.Logf("  exp err: %v", fail)
    54  		t.Logf("  act err: %v", err)
    55  		t.Logf("  exp str: %s", sExp)
    56  		t.Logf("  act str: %s", sAct)
    57  		t.Log("  exp byt: ", bExp)
    58  		t.Log("  act byt: ", bAct)
    59  	}*/
    60  }