Skip to content

Commit

Permalink
fix: hsl and hsla functions and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bsushmith committed Apr 30, 2024
1 parent 1280ce3 commit a7ef1ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions styles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func HSL(hue, saturation, lightness int) string {
builder.WriteString("hsl(")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(",")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(strconv.FormatInt(int64(saturation), 10))
builder.WriteString("%,")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(strconv.FormatInt(int64(lightness), 10))
builder.WriteString("%")
builder.WriteString(")")
return builder.String()
Expand All @@ -147,9 +147,9 @@ func HSLA(hue, saturation, lightness int, alpha float64) string {
builder.WriteString("hsla(")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(",")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(strconv.FormatInt(int64(saturation), 10))
builder.WriteString("%,")
builder.WriteString(strconv.FormatInt(int64(hue), 10))
builder.WriteString(strconv.FormatInt(int64(lightness), 10))
builder.WriteString("%,")
builder.WriteString(strconv.FormatFloat(alpha, 'f', 2, 64))
builder.WriteString(")")
Expand Down
14 changes: 7 additions & 7 deletions styles/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ func TestMilliseconds(t *testing.T) {
}

func TestHSL(t *testing.T) {
assert.Equal(t, "hsl(100,100%,100%)", HSL(100, 100, 100))
assert.Equal(t, "hsl(100,50%,25%)", HSL(100, 50, 25))
assert.Equal(t, "hsl(0,0%,0%)", HSL(0, 0, 0))
assert.Equal(t, "hsl(50,50%,50%)", HSL(50, 50, 50))
assert.Equal(t, "hsl(25,25%,25%)", HSL(25, 25, 25))
assert.Equal(t, "hsl(50,70%,80%)", HSL(50, 70, 80))
assert.Equal(t, "hsl(20,40%,60%)", HSL(20, 40, 60))
}

func TestHSLA(t *testing.T) {
assert.Equal(t, "hsla(100,100%,100%,1.00)", HSLA(100, 100, 100, 1))
assert.Equal(t, "hsla(90,50%,30%,1.00)", HSLA(90, 50, 30, 1))
assert.Equal(t, "hsla(0,0%,0%,0.10)", HSLA(0, 0, 0, 0.1))
assert.Equal(t, "hsla(50,50%,50%,0.50)", HSLA(50, 50, 50, 0.5000))
assert.Equal(t, "hsla(25,25%,25%,0.25)", HSLA(25, 25, 25, 0.2500))
assert.Equal(t, "hsla(25,25%,25%,0.00)", HSLA(25, 25, 25, 0))
assert.Equal(t, "hsla(50,60%,70%,0.50)", HSLA(50, 60, 70, 0.5000))
assert.Equal(t, "hsla(25,35%,45%,0.25)", HSLA(25, 35, 45, 0.2500))
assert.Equal(t, "hsla(20,50%,80%,0.00)", HSLA(20, 50, 80, 0))
}

0 comments on commit a7ef1ab

Please sign in to comment.