Tests.
This commit is contained in:
parent
681f5703ca
commit
f21574baa6
3 changed files with 46 additions and 8 deletions
|
@ -7,6 +7,36 @@ import (
|
||||||
"golang.org/x/image/colornames"
|
"golang.org/x/image/colornames"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestColorEquals(t *testing.T) {
|
||||||
|
if ColorEquals(nil, nil) == false {
|
||||||
|
t.Error("ColorEquals(nil, nil) == false")
|
||||||
|
}
|
||||||
|
if ColorEquals(nil, color.Black) == true {
|
||||||
|
t.Error("ColorEquals(nil, color.Black) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, nil) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, nil) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, color.Black) == false {
|
||||||
|
t.Error("ColorEquals(color.Black, color.Black) == false")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, color.White) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, color.White) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, colornames.Red) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, colornames.Red) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, colornames.Green) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, colornames.Green) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, colornames.Blue) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, colornames.Blue) == true")
|
||||||
|
}
|
||||||
|
if ColorEquals(color.Black, color.Transparent) == true {
|
||||||
|
t.Error("ColorEquals(color.Black, color.Transparent) == true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestColor_names(t *testing.T) {
|
func TestColor_names(t *testing.T) {
|
||||||
for _, name := range colornames.Names {
|
for _, name := range colornames.Names {
|
||||||
c1 := colornames.Map[name]
|
c1 := colornames.Map[name]
|
||||||
|
@ -60,6 +90,7 @@ var colorTests = []struct {
|
||||||
{"rgba(128,128,128,0)", color.NRGBA{0x80, 0x80, 0x80, 0x00}},
|
{"rgba(128,128,128,0)", color.NRGBA{0x80, 0x80, 0x80, 0x00}},
|
||||||
{"rgba(128,128,128,1)", color.NRGBA{0x80, 0x80, 0x80, 0xff}},
|
{"rgba(128,128,128,1)", color.NRGBA{0x80, 0x80, 0x80, 0xff}},
|
||||||
{"rgba(128,128,128,0.0)", color.NRGBA{0x80, 0x80, 0x80, 0x00}},
|
{"rgba(128,128,128,0.0)", color.NRGBA{0x80, 0x80, 0x80, 0x00}},
|
||||||
|
{"rgba(128,128,128,0.5)", color.NRGBA{0x80, 0x80, 0x80, 0x80}},
|
||||||
{"rgba(128,128,128,1.0)", color.NRGBA{0x80, 0x80, 0x80, 0xff}},
|
{"rgba(128,128,128,1.0)", color.NRGBA{0x80, 0x80, 0x80, 0xff}},
|
||||||
{"not a color", nil},
|
{"not a color", nil},
|
||||||
{"", nil},
|
{"", nil},
|
||||||
|
@ -80,7 +111,7 @@ var colorTests = []struct {
|
||||||
{"rgba(128,128,128)", nil},
|
{"rgba(128,128,128)", nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestColor_strings(t *testing.T) {
|
func TestParseColor(t *testing.T) {
|
||||||
for _, test := range colorTests {
|
for _, test := range colorTests {
|
||||||
c := ParseColor(test.data)
|
c := ParseColor(test.data)
|
||||||
if !ColorEquals(c, test.want) {
|
if !ColorEquals(c, test.want) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ func Unescape(s string) string {
|
||||||
state := initial
|
state := initial
|
||||||
for _, b := range []byte(s) {
|
for _, b := range []byte(s) {
|
||||||
switch state {
|
switch state {
|
||||||
case initial:
|
default:
|
||||||
switch b {
|
switch b {
|
||||||
case '\\':
|
case '\\':
|
||||||
state = escape1
|
state = escape1
|
||||||
|
|
|
@ -10,6 +10,7 @@ var unescapeTests = []struct {
|
||||||
}{
|
}{
|
||||||
{``, ""},
|
{``, ""},
|
||||||
{`abc`, "abc"},
|
{`abc`, "abc"},
|
||||||
|
{`abc\`, "abc"},
|
||||||
{`ab\c`, "abc"},
|
{`ab\c`, "abc"},
|
||||||
{`a\bc`, "a\bc"},
|
{`a\bc`, "a\bc"},
|
||||||
{`abc\f`, "abc\f"},
|
{`abc\f`, "abc\f"},
|
||||||
|
@ -20,6 +21,9 @@ var unescapeTests = []struct {
|
||||||
{`a\1c`, "a\001c"},
|
{`a\1c`, "a\001c"},
|
||||||
{`a\12c`, "a\012c"},
|
{`a\12c`, "a\012c"},
|
||||||
{`a\123c`, "a\123c"},
|
{`a\123c`, "a\123c"},
|
||||||
|
{`a\1\c`, "a\001c"},
|
||||||
|
{`a\12\c`, "a\012c"},
|
||||||
|
{`a\123\c`, "a\123c"},
|
||||||
{`a\1\b`, "a\001\b"},
|
{`a\1\b`, "a\001\b"},
|
||||||
{`a\12\b`, "a\012\b"},
|
{`a\12\b`, "a\012\b"},
|
||||||
{`a\123\b`, "a\123\b"},
|
{`a\123\b`, "a\123\b"},
|
||||||
|
@ -27,13 +31,16 @@ var unescapeTests = []struct {
|
||||||
{`abc\12`, "abc\012"},
|
{`abc\12`, "abc\012"},
|
||||||
{`abc\123`, "abc\123"},
|
{`abc\123`, "abc\123"},
|
||||||
{`abc\1234`, "abc\1234"},
|
{`abc\1234`, "abc\1234"},
|
||||||
{`abc\001`, "abc\001"},
|
{`abc\0123`, "abc\0123"},
|
||||||
{`abc\012`, "abc\012"},
|
{`abc\0012`, "abc\0012"},
|
||||||
{`abc\123`, "abc\123"},
|
|
||||||
{`abc\4`, "abc\004"},
|
|
||||||
{`abc\45`, "abc\045"},
|
|
||||||
{`abc\456`, "abc\056"},
|
|
||||||
{`abc\4567`, "abc\0567"},
|
{`abc\4567`, "abc\0567"},
|
||||||
|
{`abc\5678`, "abc\1678"},
|
||||||
|
{`abc\6789`, "abc\06789"},
|
||||||
|
{`abc\7890`, "abc\007890"},
|
||||||
|
{"ab\xcdef", "ab\xcdef"},
|
||||||
|
{"ab\\\xcdef", "ab\xcdef"},
|
||||||
|
{"ab\xcd\\ef", "ab\xcdef"},
|
||||||
|
{"ab\\0\xcdef", "ab\000\xcdef"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnescape(t *testing.T) {
|
func TestUnescape(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue