Add more tests

This commit is contained in:
Neale Pickett 2018-07-21 12:00:26 -06:00
parent a72914b8d8
commit c85e30fa93
1 changed files with 12 additions and 12 deletions

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
) )
func assertEqual(name string, a, b interface{}, t *testing.T) { func assertEqual(t *testing.T, name string, a, b interface{}) {
if a != b { if a != b {
t.Errorf("%s: %#v != %#v", name, a, b) t.Errorf("%s: %#v != %#v", name, a, b)
} }
@ -15,11 +15,11 @@ func TestChunk(t *testing.T) {
var c chunk var c chunk
c = chunk{gap: 2} c = chunk{gap: 2}
assertEqual("gap chunk", c.length(), 2, t) assertEqual(t, "gap chunk", c.length(), 2)
c = chunk{data: []byte("moo")} c = chunk{data: []byte("moo")}
assertEqual("byte chunk", c.length(), 3, t) assertEqual(t, "byte chunk", c.length(), 3)
assertEqual("byte slice", string(c.slice(1,3).data), "oo", t) assertEqual(t, "byte slice", string(c.slice(1,3).data), "oo")
} }
func TestGapString(t *testing.T) { func TestGapString(t *testing.T) {
@ -59,18 +59,18 @@ func TestGapString(t *testing.T) {
} }
g = g.AppendString("baz") g = g.AppendString("baz")
if g.String("") != "moobarbaz" { assertEqual(t, "string", g.String(""), "moobarbaz")
t.Errorf("String conversion with empty string") assertEqual(t, "string drop", g.String("DROP"), "moobarOPDROPDRbaz")
}
if g.String("DROP") != "moobarOPDROPDRbaz" {
t.Errorf("String conversion with fill")
}
assertEqual("slice", g.Slice(2, 5).String(""), "oba", t) assertEqual(t, "xor", g.Xor(1).String(""), "lnnc`sc`{")
assertEqual(t, "xor drop", g.Xor(1).String("DROP"), "lnnc`sOPDROPDRc`{")
assertEqual(t, "slice", g.Slice(2, 5).String(""), "oba")
assertEqual(t, "slice+xor", g.Slice(2, 5).Xor(1).String(""), "nc`")
hexdump := hexdump :=
"00000000 6d 6f 6f 62 61 72 -- -- -- -- -- -- -- -- 62 61 moobar<61><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ba\n" + "00000000 6d 6f 6f 62 61 72 -- -- -- -- -- -- -- -- 62 61 moobar<61><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ba\n" +
"00000010 7a z\n" + "00000010 7a z\n" +
"00000011\n" "00000011\n"
assertEqual("hexdump", g.Hexdump(), hexdump, t) assertEqual(t, "hexdump", g.Hexdump(), hexdump)
} }