func TestCborGoldens(t *testing.T) {
	oldMapType := testCborH.MapType
	defer func() {
		testCborH.MapType = oldMapType
	}()
	testCborH.MapType = testMapStrIntfTyp
	// decode test-cbor-goldens.json into a list of []*testCborGolden
	// for each one,
	// - decode hex into []byte bs
	// - decode bs into interface{} v
	// - compare both using deepequal
	// - for any miss, record it
	var gs []*testCborGolden
	f, err := os.Open("test-cbor-goldens.json")
	if err != nil {
		t.Logf("error opening test-cbor-goldens.json: %v", err)
		t.FailNow()
	}
	defer f.Close()
	jh := new(JsonHandle)
	jh.MapType = testMapStrIntfTyp
	// d := NewDecoder(f, jh)
	d := NewDecoder(bufio.NewReader(f), jh)
	// err = d.Decode(&gs)
	d.MustDecode(&gs)
	if err != nil {
		t.Logf("error json decoding test-cbor-goldens.json: %v", err)
		t.FailNow()
	}

	tagregex := regexp.MustCompile(`[\d]+\(.+?\)`)
	hexregex := regexp.MustCompile(`h'([0-9a-fA-F]*)'`)
	for i, g := range gs {
		// fmt.Printf("%v, skip: %v, isTag: %v, %s\n", i, g.Skip, tagregex.MatchString(g.Diagnostic), g.Diagnostic)
		// skip tags or simple or those with prefix, as we can't verify them.
		if g.Skip || strings.HasPrefix(g.Diagnostic, "simple(") || tagregex.MatchString(g.Diagnostic) {
			// fmt.Printf("%v: skipped\n", i)
			if testVerbose {
				t.Logf("[%v] skipping because skip=true OR unsupported simple value or Tag Value", i)
			}
			continue
		}
		// println("++++++++++++", i, "g.Diagnostic", g.Diagnostic)
		if hexregex.MatchString(g.Diagnostic) {
			// println(i, "g.Diagnostic matched hex")
			if s2 := g.Diagnostic[2 : len(g.Diagnostic)-1]; s2 == "" {
				g.Decoded = zeroByteSlice
			} else if bs2, err2 := hex.DecodeString(s2); err2 == nil {
				g.Decoded = bs2
			}
			// fmt.Printf("%v: hex: %v\n", i, g.Decoded)
		}
		bs, err := hex.DecodeString(g.Hex)
		if err != nil {
			t.Logf("[%v] error hex decoding %s [%v]: %v", i, g.Hex, g.Hex, err)
			t.FailNow()
		}
		var v interface{}
		NewDecoderBytes(bs, testCborH).MustDecode(&v)
		if _, ok := v.(RawExt); ok {
			continue
		}
		// check the diagnostics to compare
		switch g.Diagnostic {
		case "Infinity":
			b := math.IsInf(v.(float64), 1)
			testCborError(t, i, math.Inf(1), v, nil, &b)
		case "-Infinity":
			b := math.IsInf(v.(float64), -1)
			testCborError(t, i, math.Inf(-1), v, nil, &b)
		case "NaN":
			// println(i, "checking NaN")
			b := math.IsNaN(v.(float64))
			testCborError(t, i, math.NaN(), v, nil, &b)
		case "undefined":
			b := v == nil
			testCborError(t, i, nil, v, nil, &b)
		default:
			v0 := g.Decoded
			// testCborCoerceJsonNumber(rv4i(&v0))
			testCborError(t, i, v0, v, deepEqual(v0, v), nil)
		}
	}
}
// Some tests are skipped because they include numbers outside the range of int64/uint64
Some tests are skipped because they include numbers outside the range of int64/uint64
// Some tests are skipped because they include numbers outside the range of int64 / uint64
func TestCborGoldens(t *testing.T) {
	oldMapType := testCborH.MapType
	defer func() {
		testCborH.MapType = oldMapType
	}()
	testCborH.MapType = testMapStrIntfTyp
	var gs []*testCborGolden
	f, err := os.Open("test-cbor-goldens.json")
	if err != nil {
		t.Logf("error opening test-cbor-goldens.json: %v", err)
		t.FailNow()
	}
	defer f.Close()
	jh := new(JsonHandle)
	jh.MapType = testMapStrIntfTyp
	d := NewDecoder(bufio.NewReader(f), jh)
	d.MustDecode(&gs)
	if err != nil {
		t.Logf("error json decoding test-cbor-goldens.json: %v", err)
		t.FailNow()
	}
	tagregex := regexp.MustCompile(`[\d]+\(.+?\)`)
	hexregex := regexp.MustCompile(`h'([0-9a-fA-F]*)'`)
	for i, g := range gs {
		if g.Skip || strings.HasPrefix(g.Diagnostic, "simple(") || tagregex.MatchString(g.Diagnostic) {
			if testVerbose {
				t.Logf("[%v] skipping because skip=true OR unsupported simple value or Tag Value", i)
			}
			continue
		}
		if hexregex.MatchString(g.Diagnostic) {
			if s2 := g.Diagnostic[2 : len(g.Diagnostic)-1]; s2 == "" {
				g.Decoded = zeroByteSlice
			} else if bs2, err2 := hex.DecodeString(s2); err2 == nil {
				g.Decoded = bs2
			}
		}
		bs, err := hex.DecodeString(g.Hex)
		if err != nil {
			t.Logf("[%v] error hex decoding %s [%v]: %v", i, g.Hex, g.Hex, err)
			t.FailNow()
		}
		var v interface{}
		NewDecoderBytes(bs, testCborH).MustDecode(&v)
		if _, ok := v.(RawExt); ok {
			continue
		}
		switch g.Diagnostic {
		case "Infinity":
			b := math.IsInf(v.(float64), 1)
			testCborError(t, i, math.Inf(1), v, nil, &b)
		case "-Infinity":
			b := math.IsInf(v.(float64), -1)
			testCborError(t, i, math.Inf(-1), v, nil, &b)
		case "NaN":
			b := math.IsNaN(v.(float64))
			testCborError(t, i, math.NaN(), v, nil, &b)
		case "undefined":
			b := v == nil
			testCborError(t, i, nil, v, nil, &b)
		default:
			v0 := g.Decoded
			testCborError(t, i, v0, v, deepEqual(v0, v), nil)
		}
	}
}
func TestCborGoldens ( t * testing . T ) { oldMapType := testCborH . MapType defer func ( ) { testCborH . MapType = oldMapType } ( ) testCborH . MapType = testMapStrIntfTyp var gs [ ] * testCborGolden f , err := os . Open ( " " ) if err != nil { t . Logf ( " " , err ) t . FailNow ( ) } defer f . Close ( ) jh := new ( JsonHandle ) jh . MapType = testMapStrIntfTyp d := NewDecoder ( bufio . NewReader ( f ) , jh ) d . MustDecode ( & gs ) if err != nil { t . Logf ( " " , err ) t . FailNow ( ) } tagregex := regexp . MustCompile ( `[\d]+\(.+?\)` ) hexregex := regexp . MustCompile ( `h'([0-9a-fA-F]*)'` ) for i , g := range gs { if g . Skip || strings . HasPrefix ( g . Diagnostic , " " ) || tagregex . MatchString ( g . Diagnostic ) { if testVerbose { t . Logf ( " " , i ) } continue } if hexregex . MatchString ( g . Diagnostic ) { if s2 := g . Diagnostic [ 2 : len ( g . Diagnostic ) - 1 ] ; s2 == " " { g . Decoded = zeroByteSlice } else if bs2 , err2 := hex . DecodeString ( s2 ) ; err2 == nil { g . Decoded = bs2 } } bs , err := hex . DecodeString ( g . Hex ) if err != nil { t . Logf ( " " , i , g . Hex , g . Hex , err ) t . FailNow ( ) } var v interface { } NewDecoderBytes ( bs , testCborH ) . MustDecode ( & v ) if _ , ok := v . ( RawExt ) ; ok { continue } switch g . Diagnostic { case " " : b := math . IsInf ( v . ( float64 ) , 1 ) testCborError ( t , i , math . Inf ( 1 ) , v , nil , & b ) case " " : b := math . IsInf ( v . ( float64 ) , - 1 ) testCborError ( t , i , math . Inf ( - 1 ) , v , nil , & b ) case " " : b := math . IsNaN ( v . ( float64 ) ) testCborError ( t , i , math . NaN ( ) , v , nil , & b ) case " " : b := v == nil testCborError ( t , i , nil , v , nil , & b ) default : v0 := g . Decoded testCborError ( t , i , v0 , v , deepEqual ( v0 , v ) , nil ) } } }
Some tests are skipped because they include numbers outside the range of int64/uint64
Some tests are skipped because they include numbers outside the range of int64 / uint64
// decode test-cbor-goldens.json into a list of []*testCborGolden // for each one, // - decode hex into []byte bs // - decode bs into interface{} v // - compare both using deepequal // - for any miss, record it // d := NewDecoder(f, jh) // err = d.Decode(&gs) // fmt.Printf("%v, skip: %v, isTag: %v, %s\n", i, g.Skip, tagregex.MatchString(g.Diagnostic), g.Diagnostic) // skip tags or simple or those with prefix, as we can't verify them. // fmt.Printf("%v: skipped\n", i) // println("++++++++++++", i, "g.Diagnostic", g.Diagnostic) // println(i, "g.Diagnostic matched hex") // fmt.Printf("%v: hex: %v\n", i, g.Decoded) // check the diagnostics to compare // println(i, "checking NaN") // testCborCoerceJsonNumber(rv4i(&v0))