github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/types/byte_test.go (about) 1 package types 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "testing" 7 ) 8 9 func TestByteString(t *testing.T) { 10 t.Parallel() 11 12 b := Byte('b') 13 if b.String() != "b" { 14 t.Errorf("Expected %q, got %s", "b", b.String()) 15 } 16 } 17 18 func TestByteUnmarshal(t *testing.T) { 19 t.Parallel() 20 21 var b Byte 22 err := json.Unmarshal([]byte(`"b"`), &b) 23 if err != nil { 24 t.Error(err) 25 } 26 27 if b != 'b' { 28 t.Errorf("Expected %q, got %s", "b", b) 29 } 30 } 31 32 func TestByteMarshal(t *testing.T) { 33 t.Parallel() 34 35 b := Byte('b') 36 res, err := json.Marshal(&b) 37 if err != nil { 38 t.Error(err) 39 } 40 41 if !bytes.Equal(res, []byte(`"b"`)) { 42 t.Errorf("expected %s, got %s", `"b"`, b.String()) 43 } 44 } 45 46 func TestByteValue(t *testing.T) { 47 t.Parallel() 48 49 b := Byte('b') 50 v, err := b.Value() 51 if err != nil { 52 t.Error(err) 53 } 54 55 if !bytes.Equal([]byte{byte(b)}, v.([]byte)) { 56 t.Errorf("byte mismatch, %v %v", b, v) 57 } 58 } 59 60 func TestByteScan(t *testing.T) { 61 t.Parallel() 62 63 var b Byte 64 65 s := "b" 66 err := b.Scan(s) 67 if err != nil { 68 t.Error(err) 69 } 70 71 if !bytes.Equal([]byte{byte(b)}, []byte{'b'}) { 72 t.Errorf("bad []byte: %#v ≠ %#v\n", b, "b") 73 } 74 }