Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,60 @@ func (c Color) RGB() string {
return color
}

// RGBA returns a fake color in rgba format for Color
func (c Color) RGBA() string {
return c.RGB() + ", " + strconv.Itoa(c.Faker.IntBetween(0, 100)) + "%"
}

// OKLCH returns a fake color in OKLCH format for Color
func (c Color) OKLCH() string {
oklch := ""

// lightness
oklch = oklch + strconv.Itoa(c.Faker.IntBetween(0, 100)) + "%, "

// chroma
oklch = oklch + strconv.Itoa(c.Faker.IntBetween(0, 100)) + "%, "

// hue
oklch = oklch + strconv.Itoa(c.Faker.IntBetween(0, 360)) + "deg"

return oklch
}

// RGBAsArray returns a fake rgb color in array format for Color
func (c Color) RGBAsArray() [3]string {
split := strings.Split(c.RGB(), ",")
return [3]string{split[0], split[1], split[2]}
}

// RGBAAsArray returns a fake rgba color in array format for Color
func (c Color) RGBAAsArray() [4]string {
split := strings.Split(c.RGBA(), ",")
return [4]string{split[0], split[1], split[2], split[3]}
}

// OKLCHAsArray returns a fake OKLCH color in array format for Color
func (c Color) OKLCHAsArray() [3]string {
split := strings.Split(c.OKLCH(), ",")
return [3]string{split[0], split[1], split[2]}
}

// CSS returns a fake color in CSS format for Color
func (c Color) CSS() string {
return "rgb(" + c.RGB() + ")"
}

// CSSRGBA returns a fake color in CSS rgba format for Color
func (c Color) CSSRGBA() string {
return "rgba(" + c.RGBA() + ")"
}

// CSSOKLCH returns a fake color in CSS oklch format for Color
func (c Color) CSSOKLCH() string {
return "oklch(" + c.OKLCH() + ")"
}

// SafeColorName returns a fake safe color name for Color
func (c Color) SafeColorName() string {
return c.Faker.RandomStringElement(safeColorNames)
Expand Down
61 changes: 61 additions & 0 deletions color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,64 @@ func TestColorName(t *testing.T) {
color := c.ColorName()
Expect(t, true, len(color) > 0)
}

func TestRGBA(t *testing.T) {
c := New().Color()

color := c.RGBA()

Expect(t, true, len(color) > 10)
Expect(t, true, len(color) < 20)
Expect(t, true, strings.Contains(color, ","))
Expect(t, true, strings.Contains(color, "%"))
}

func TestOKLCH(t *testing.T) {
c := New().Color()

color := c.OKLCH()

Expect(t, true, len(color) > 11)
Expect(t, true, len(color) < 19)
Expect(t, true, strings.Contains(color, "%"))
Expect(t, true, strings.Contains(color, "deg"))
}

func TestRGBAAsArray(t *testing.T) {
c := New().Color()

color := c.RGBAAsArray()

Expect(t, 4, len(color))
Expect(t, true, strings.Contains(color[3], "%"))
}

func TestOKLCHAsArray(t *testing.T) {
c := New().Color()

Expect(t, 3, len(c.OKLCHAsArray()))
}

func TestCSSOKLCH(t *testing.T) {
c := New().Color()

color := c.CSSOKLCH()

Expect(t, true, len(color) > 17)
Expect(t, true, len(color) <= 26)
Expect(t, true, strings.Contains(color, "oklch("))
Expect(t, true, strings.Contains(color, ","))
Expect(t, true, strings.Contains(color, ")"))
}

func TestCSSRGBA(t *testing.T) {
c := New().Color()

color := c.CSSRGBA()

Expect(t, true, len(color) > 14)
Expect(t, true, len(color) <= 25)
Expect(t, true, strings.Contains(color, "rgba("))
Expect(t, true, strings.Contains(color, ","))
Expect(t, true, strings.Contains(color, ")"))
}