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

Move /wtf tests into /wtf directory

This commit is contained in:
Chris Cummer
2019-08-03 17:19:55 -07:00
parent c17678013d
commit a1aafbeade
4 changed files with 4 additions and 8 deletions

39
wtf/bargraph_test.go Normal file
View File

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

13
wtf/colors_test.go Normal file
View File

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

20
wtf/datetime_test.go Normal file
View File

@@ -0,0 +1,20 @@
package wtf
import (
"testing"
"time"
. "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"))
}

85
wtf/utils_test.go Normal file
View File

@@ -0,0 +1,85 @@
package wtf
import (
"testing"
. "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))
}