Skip to content

Commit

Permalink
tests: add util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Sep 8, 2023
1 parent ae2f695 commit 20119b4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package util

import (
"bytes"
"testing"

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

func TestUtilContainsAny(t *testing.T) {
assert.True(t, ContainsAny("foo", []string{"foo", "bar"}))
assert.True(t, ContainsAny("bar", []string{"foo", "bar"}))
assert.False(t, ContainsAny("baz", []string{"foo", "bar"}))
}

func TestUtilMustWriteln(t *testing.T) {
var out bytes.Buffer
MustWriteln(&out, "foo")
assert.Equal(t, "foo\n", out.String())
}

func TestUtilMustWritef(t *testing.T) {
var out bytes.Buffer
MustWritef(&out, "foo %s", "bar")
assert.Equal(t, "foo bar", out.String())
}

func TestUtilColor(t *testing.T) {
assert.Equal(t, "\033[1;31mfoo\033[0m", Color("red", "foo"))
assert.Equal(t, "\033[1;37mfoo\033[0m", Color("white", "foo"))
}

0 comments on commit 20119b4

Please sign in to comment.