github.com/status-im/status-go@v1.1.0/images/color_test.go (about) 1 package images 2 3 import ( 4 "image/color" 5 "testing" 6 ) 7 8 func TestParseColor(t *testing.T) { 9 // Test hex color string format 10 hexColor := "#FF00FF" 11 expectedResult := color.RGBA{R: 255, G: 0, B: 255, A: 255} 12 result, err := ParseColor(hexColor) 13 if err != nil { 14 t.Errorf("unexpected error: %s", err) 15 } 16 if result != expectedResult { 17 t.Errorf("unexpected result: %v (expected %v)", result, expectedResult) 18 } 19 20 // Test RGB color string format 21 rgbColor := "rgb(255, 0, 255)" 22 expectedResult = color.RGBA{R: 255, G: 0, B: 255, A: 255} 23 result, err = ParseColor(rgbColor) 24 if err != nil { 25 t.Errorf("unexpected error: %s", err) 26 } 27 if result != expectedResult { 28 t.Errorf("unexpected result: %v (expected %v)", result, expectedResult) 29 } 30 31 // Test RGBA color string format 32 rgbaColor := "rgba(255, 0, 255, 1)" 33 expectedResult = color.RGBA{R: 255, G: 0, B: 255, A: 255} 34 result, err = ParseColor(rgbaColor) 35 if err != nil { 36 t.Errorf("unexpected error: %s", err) 37 } 38 if result != expectedResult { 39 t.Errorf("unexpected result: %v (expected %v)", result, expectedResult) 40 } 41 42 // Test invalid color string format 43 invalidColor := "blah" 44 _, err = ParseColor(invalidColor) 45 if err == nil { 46 t.Errorf("expected error, but got none") 47 } 48 }