@@ -3,12 +3,14 @@ package check
33import (
44 "errors"
55 "fmt"
6+ "reflect"
67 "testing"
78 "time"
89
910 "github.com/ctx42/testing/internal/affirm"
1011 "github.com/ctx42/testing/internal/cases"
1112 "github.com/ctx42/testing/internal/types"
13+ "github.com/ctx42/testing/pkg/dump"
1214 "github.com/ctx42/testing/pkg/must"
1315)
1416
@@ -1297,6 +1299,23 @@ func Test_equalError(t *testing.T) {
12971299 affirm .Equal (t , wMsg , err .Error ())
12981300 })
12991301
1302+ t .Run ("does not override already set byte dumper" , func (t * testing.T ) {
1303+ // --- Given ---
1304+ w := byte ('A' )
1305+ h := byte ('B' )
1306+ fn := func (_ dump.Dump , _ int , _ reflect.Value ) string { return "abc" }
1307+ ops := DefaultOptions (WithDumper (dump .WithDumper (byte (0 ), fn )))
1308+
1309+ // --- When ---
1310+ err := equalError (w , h , WithOptions (ops ))
1311+
1312+ // --- Then ---
1313+ wMsg := "expected values to be equal:\n " +
1314+ " want: abc\n " +
1315+ " have: abc"
1316+ affirm .Equal (t , wMsg , err .Error ())
1317+ })
1318+
13001319 t .Run ("different types" , func (t * testing.T ) {
13011320 // --- Given ---
13021321 w := byte ('A' )
@@ -1315,3 +1334,41 @@ func Test_equalError(t *testing.T) {
13151334 affirm .Equal (t , wMsg , err .Error ())
13161335 })
13171336}
1337+
1338+ func Test_dumpByte (t * testing.T ) {
1339+ t .Run ("success printable" , func (t * testing.T ) {
1340+ // --- Given ---
1341+ dmp := dump .New ()
1342+ val := reflect .ValueOf (byte (42 ))
1343+
1344+ // --- When ---
1345+ have := dumpByte (dmp , 0 , val )
1346+
1347+ // --- Then ---
1348+ affirm .Equal (t , "0x2a ('*')" , have )
1349+ })
1350+
1351+ t .Run ("success not printable" , func (t * testing.T ) {
1352+ // --- Given ---
1353+ dmp := dump .New ()
1354+ val := reflect .ValueOf (byte (1 ))
1355+
1356+ // --- When ---
1357+ have := dumpByte (dmp , 0 , val )
1358+
1359+ // --- Then ---
1360+ affirm .Equal (t , "0x01" , have )
1361+ })
1362+
1363+ t .Run ("uses indent and level" , func (t * testing.T ) {
1364+ // --- Given ---
1365+ dmp := dump .New (dump .WithIndent (2 ))
1366+ val := reflect .ValueOf (byte (1 ))
1367+
1368+ // --- When ---
1369+ have := dumpByte (dmp , 1 , val )
1370+
1371+ // --- Then ---
1372+ affirm .Equal (t , " 0x01" , have )
1373+ })
1374+ }
0 commit comments