mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Tweaking minor code issues
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package bargraphtests
|
||||
|
||||
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] = 1530122942
|
||||
stats[0][0] = 100
|
||||
|
||||
stats[1][1] = 1530132942
|
||||
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, result, "Jan 18, 1970 -\t [red]*[white] - (100)\nJan 18, 1970 -\t [red]********************[white] - (210)\n")
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package wtf_tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
. "github.com/senorprogrammer/wtf/wtf"
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestColorFor(t *testing.T) {
|
||||
Equal(t, tcell.ColorRed, ColorFor("red"))
|
||||
Equal(t, tcell.ColorGreen, ColorFor("cat"))
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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"))
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user