1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

A very basic start to adding some unit tests

This commit is contained in:
Chris Cummer
2018-05-18 11:54:39 -07:00
parent c190a44728
commit 8bb9115538
5 changed files with 152 additions and 19 deletions

View File

@@ -0,0 +1,27 @@
package wtf_tests
import (
"testing"
. "github.com/senorprogrammer/wtf/wtf"
)
func TestPosition(t *testing.T) {
pos := NewPosition(0, 1, 2, 3)
if pos.Top() != 0 {
t.Fatalf("Expected 0 but got %d", pos.Top())
}
if pos.Left() != 1 {
t.Fatalf("Expected 1 but got %d", pos.Left())
}
if pos.Width() != 2 {
t.Fatalf("Expected 2 but got %d", pos.Width())
}
if pos.Height() != 3 {
t.Fatalf("Expected 3 but got %d", pos.Height())
}
}

107
wtf_tests/utils_test.go Normal file
View File

@@ -0,0 +1,107 @@
package wtf_tests
import (
"testing"
. "github.com/senorprogrammer/wtf/wtf"
"github.com/go-test/deep"
)
/* -------------------- Exclude() -------------------- */
func TestExcludeWhenTrue(t *testing.T) {
if Exclude([]string{"cat", "dog", "rat"}, "bat") != true {
t.Fatalf("Expected true but got false")
}
}
func TestExcludeWhenFalse(t *testing.T) {
if Exclude([]string{"cat", "dog", "rat"}, "dog") != false {
t.Fatalf("Expected false but got true")
}
}
/* -------------------- NameFromEmail() -------------------- */
func TestNameFromEmailWhenEmpty(t *testing.T) {
expected := ""
actual := NameFromEmail("")
if expected != actual {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
func TestNameFromEmailWithEmail(t *testing.T) {
expected := "Chris Cummer"
actual := NameFromEmail("chris.cummer@me.com")
if expected != actual {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
/* -------------------- NamesFromEmails() -------------------- */
func TestNamesFromEmailsWhenEmpty(t *testing.T) {
expected := []string{}
actual := NamesFromEmails([]string{})
if diff := deep.Equal(expected, actual); diff != nil {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
func TestNamesFromEmailsWithEmails(t *testing.T) {
expected := []string{"Chris Cummer", "Chriscummer"}
actual := NamesFromEmails([]string{"chris.cummer@me.com", "chriscummer@me.com"})
if diff := deep.Equal(expected, actual); diff != nil {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
/* -------------------- ToInts() -------------------- */
func TestToInts(t *testing.T) {
expected := []int{1, 2, 3}
source := make([]interface{}, len(expected))
for idx, val := range expected {
source[idx] = val
}
actual := ToInts(source)
if diff := deep.Equal(expected, actual); diff != nil {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
/* -------------------- ToStrs() -------------------- */
func TestToStrs(t *testing.T) {
expected := []string{"cat", "dog", "rat"}
source := make([]interface{}, len(expected))
for idx, val := range expected {
source[idx] = val
}
actual := ToStrs(source)
if diff := deep.Equal(expected, actual); diff != nil {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}
/* -------------------- PrettyDate() -------------------- */
func TestPrettyDate(t *testing.T) {
expected := "Oct 21, 1999"
actual := PrettyDate("1999-10-21")
if expected != actual {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}