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:
parent
c190a44728
commit
8bb9115538
@ -1,13 +0,0 @@
|
||||
package wtf
|
||||
|
||||
import(
|
||||
"time"
|
||||
)
|
||||
|
||||
type ConfigWatcher struct {
|
||||
UpdatedAt *time.Time
|
||||
}
|
||||
|
||||
func (watcher *ConfigWatcher) Watch() {
|
||||
|
||||
}
|
@ -9,6 +9,17 @@ type Position struct {
|
||||
height int
|
||||
}
|
||||
|
||||
func NewPosition(top, left, width, height int) Position {
|
||||
pos := Position{
|
||||
top: 0,
|
||||
left: 1,
|
||||
width: 2,
|
||||
height: 3,
|
||||
}
|
||||
|
||||
return pos
|
||||
}
|
||||
|
||||
func (pos *Position) Top() int {
|
||||
return pos.top
|
||||
}
|
||||
|
@ -29,14 +29,15 @@ func NewTextWidget(name string, configKey string, focusable bool) TextWidget {
|
||||
|
||||
Name: name,
|
||||
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
|
||||
Position: Position{
|
||||
top: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
|
||||
left: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
|
||||
height: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
|
||||
width: Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
|
||||
},
|
||||
}
|
||||
|
||||
widget.Position = NewPosition(
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
|
||||
)
|
||||
|
||||
widget.addView()
|
||||
|
||||
return widget
|
||||
|
27
wtf_tests/position_test.go
Normal file
27
wtf_tests/position_test.go
Normal 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
107
wtf_tests/utils_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user