Skip to content

Commit

Permalink
test: testing panics and empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinaldy Rafli committed Oct 27, 2021
1 parent 559192b commit 063b44a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@ name: CI
on: [push, pull_request]

jobs:
build-test:
name: Build test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.16.x, 1.17.x]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build ./
coverage:
name: Coverage
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions asciitxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func WithConfig(txt string, config Config) string {
config.Style = StyleStandard
}

if txt == "" {
return ""
}

letters := strings.Split(txt, "")
var arr [][]string
llen := getStyleLength(config.Style)
Expand Down
21 changes: 21 additions & 0 deletions asciitxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ func TestWithConfig(t *testing.T) {
t.Error("should not be empty")
}
}

func TestEmpty(t *testing.T) {
s := asciitxt.New("")
if s != "" {
t.Error("should be empty, got:", s)
}
}

func TestInvalidStyle(t *testing.T) {
// this should panic
assertPanic(t, func() { asciitxt.WithConfig("hello", asciitxt.Config{Style: 2}) })
}

func assertPanic(t *testing.T, f func()) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
f()
}

0 comments on commit 063b44a

Please sign in to comment.