Add boil.Byte type
This commit is contained in:
parent
d27823de53
commit
3bfdae6b5c
3 changed files with 137 additions and 2 deletions
types
74
types/byte_test.go
Normal file
74
types/byte_test.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestByteString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := Byte('b')
|
||||
if b.String() != "b" {
|
||||
t.Errorf("Expected %q, got %s", "b", b.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteUnmarshal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b Byte
|
||||
err := json.Unmarshal([]byte(`"b"`), &b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if b != 'b' {
|
||||
t.Errorf("Expected %q, got %s", "b", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteMarshal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := Byte('b')
|
||||
res, err := json.Marshal(&b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(res, []byte(`"b"`)) {
|
||||
t.Errorf("expected %s, got %s", `"b"`, b.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := Byte('b')
|
||||
v, err := b.Value()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal([]byte{byte(b)}, v.([]byte)) {
|
||||
t.Errorf("byte mismatch, %v %v", b, v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b Byte
|
||||
|
||||
s := "b"
|
||||
err := b.Scan(s)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal([]byte{byte(b)}, []byte{'b'}) {
|
||||
t.Errorf("bad []byte: %#v ≠ %#v\n", b, "b")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue