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

Add tests for wtf/colors.go exported functions

This commit is contained in:
Chris Cummer
2018-07-31 17:46:03 -07:00
parent 22c9da9923
commit f592e09a93
7 changed files with 59 additions and 5 deletions

View File

@@ -0,0 +1,33 @@
package bargraph_test
import (
"testing"
. "github.com/senorprogrammer/wtf/wtf"
. "github.com/stretchr/testify/assert"
)
// MakeData - Create sample data
func makeData() [][2]int64 {
//this could come from config
const lineCount = 2
var stats [lineCount][2]int64
stats[0][1] = 1530122942000
stats[0][0] = 100
stats[1][1] = 1531142942000
stats[1][0] = 210
return stats[:]
}
//TestOutput of the bargraph make string (BuildStars) function
func TestOutput(t *testing.T) {
result := BuildStars(makeData(), 20, "*")
Equal(t, "Jun 27, 2018 -\t [red]*[white] - (100)\nJul 09, 2018 -\t [red]********************[white] - (210)\n", result)
}

14
wtf_tests/colors_test.go Normal file
View File

@@ -0,0 +1,14 @@
package wtf_tests
import (
"testing"
. "github.com/senorprogrammer/wtf/wtf"
. "github.com/stretchr/testify/assert"
)
func TestASCIItoTviewColors(t *testing.T) {
Equal(t, "", ASCIItoTviewColors(""))
Equal(t, "cat", ASCIItoTviewColors("cat"))
Equal(t, "[38;5;226mcat/[-]", ASCIItoTviewColors("[38;5;226mcat/"))
}

View File

@@ -0,0 +1,21 @@
package wtf_tests
import (
"testing"
"time"
. "github.com/senorprogrammer/wtf/wtf"
. "github.com/stretchr/testify/assert"
)
func TestIsToday(t *testing.T) {
Equal(t, true, IsToday(time.Now().Local()))
Equal(t, false, IsToday(time.Now().AddDate(0, 0, -1)))
Equal(t, false, IsToday(time.Now().AddDate(0, 0, +1)))
}
/* -------------------- PrettyDate() -------------------- */
func TestPrettyDate(t *testing.T) {
Equal(t, "Oct 21, 1999", PrettyDate("1999-10-21"))
}

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())
}
}

86
wtf_tests/utils_test.go Normal file
View File

@@ -0,0 +1,86 @@
package wtf_tests
import (
"testing"
. "github.com/senorprogrammer/wtf/wtf"
. "github.com/stretchr/testify/assert"
)
/* -------------------- CenterText() -------------------- */
func TestCenterText(t *testing.T) {
Equal(t, "cat", CenterText("cat", -9))
Equal(t, "cat", CenterText("cat", 0))
Equal(t, " cat ", CenterText("cat", 9))
}
/* -------------------- FindMatch() -------------------- */
func TestFindMatch(t *testing.T) {
var result [][]string
expected := [][]string([][]string{[]string{"SSID: 7E5B5C", "7E5B5C"}})
result = FindMatch(`s*SSID: (.+)s*`, "SSID: 7E5B5C")
Equal(t, expected, result)
}
/* -------------------- Exclude() -------------------- */
func TestExcludeWhenTrue(t *testing.T) {
Equal(t, true, Exclude([]string{"cat", "dog", "rat"}, "bat"))
Equal(t, false, Exclude([]string{"cat", "dog", "rat"}, "dog"))
}
/* -------------------- NameFromEmail() -------------------- */
func TestNameFromEmail(t *testing.T) {
Equal(t, "", NameFromEmail(""))
Equal(t, "Chris Cummer", NameFromEmail("chris.cummer@me.com"))
}
/* -------------------- NamesFromEmails() -------------------- */
func TestNamesFromEmails(t *testing.T) {
var result []string
result = NamesFromEmails([]string{})
Equal(t, []string{}, result)
result = NamesFromEmails([]string{"chris.cummer@me.com", "chriscummer@me.com"})
Equal(t, []string{"Chris Cummer", "Chriscummer"}, result)
}
/* -------------------- PadRow() -------------------- */
func TestPadRow(t *testing.T) {
Equal(t, "", PadRow(0, 0))
Equal(t, "", PadRow(5, 2))
Equal(t, " ", PadRow(1, 2))
}
/* -------------------- ToInts() -------------------- */
func TestToInts(t *testing.T) {
expected := []int{1, 2, 3}
source := make([]interface{}, len(expected))
for idx, val := range expected {
source[idx] = val
}
Equal(t, expected, ToInts(source))
}
/* -------------------- ToStrs() -------------------- */
func TestToStrs(t *testing.T) {
expected := []string{"cat", "dog", "rat"}
source := make([]interface{}, len(expected))
for idx, val := range expected {
source[idx] = val
}
Equal(t, expected, ToStrs(source))
}