Skip to content

Commit

Permalink
fix: GetDynamicStyle panic (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth authored Aug 12, 2024
1 parent cd59e56 commit 7ea7a3d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/back-compat-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ env:
jobs:
check-back-compat:
name: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/back-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ env:
jobs:
check-back-compat:
name: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ env:
jobs:
build:
name: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
Expand All @@ -29,10 +32,6 @@ jobs:
run: go build -v ./...
- name: go test
run: go test -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
- name: run omm
run: |
go build .
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: lint

on:
push:
branches: [ "main" ]
pull_request:
paths:
- "go.*"
- "**/*.go"
- ".github/workflows/*.yml"

permissions:
contents: read

env:
GO_VERSION: '1.22.5'

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
2 changes: 1 addition & 1 deletion internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func GetDynamicStyle(str string) lipgloss.Style {
h.Write([]byte(str))
hash := h.Sum32()

color := colors[int(hash)%len(colors)]
color := colors[hash%uint32(len(colors))]
return lipgloss.NewStyle().
Foreground(lipgloss.Color(color))
}
Expand Down
15 changes: 15 additions & 0 deletions internal/types/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package types

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetDynamicStyle(t *testing.T) {
input := "abcdefghi"
gota := GetDynamicStyle(input)
gotb := GetDynamicStyle(input)
// assert same style returned for the same string
assert.Equal(t, gota.GetBackground(), gotb.GetBackground())
}

0 comments on commit 7ea7a3d

Please sign in to comment.