mirror of https://github.com/aldy505/asciitxt.git
test: testing panics and empty input
This commit is contained in:
parent
559192bae5
commit
063b44a57e
|
@ -3,24 +3,6 @@ name: CI
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
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:
|
coverage:
|
||||||
name: Coverage
|
name: Coverage
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -32,6 +32,10 @@ func WithConfig(txt string, config Config) string {
|
||||||
config.Style = StyleStandard
|
config.Style = StyleStandard
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if txt == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
letters := strings.Split(txt, "")
|
letters := strings.Split(txt, "")
|
||||||
var arr [][]string
|
var arr [][]string
|
||||||
llen := getStyleLength(config.Style)
|
llen := getStyleLength(config.Style)
|
||||||
|
|
|
@ -20,3 +20,24 @@ func TestWithConfig(t *testing.T) {
|
||||||
t.Error("should not be empty")
|
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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue