mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
add simple tests for core table functions
add simple tests for each of table functions in core
This commit is contained in:
parent
480f0daa8d
commit
5d58ab24be
1 changed files with 82 additions and 0 deletions
82
core/table_test.go
Normal file
82
core/table_test.go
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"regexp"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestViewLen(t *testing.T) {
|
||||||
|
exp := 2
|
||||||
|
got := viewLen("<3")
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaxLen(t *testing.T) {
|
||||||
|
exp := 7
|
||||||
|
got := maxLen([]string{"go", "python", "ruby", "crystal"})
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlignLeft(t *testing.T) {
|
||||||
|
exp := Alignment(0)
|
||||||
|
got := AlignLeft
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlignCenter(t *testing.T) {
|
||||||
|
exp := Alignment(1)
|
||||||
|
got := AlignCenter
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlignRight(t *testing.T) {
|
||||||
|
exp := Alignment(2)
|
||||||
|
got := AlignRight
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetPads(t *testing.T) {
|
||||||
|
lPadExp := -9
|
||||||
|
rPadExp := -8
|
||||||
|
lPadGot, rPadGot := getPads("Pikachu, thunderbolt!", 3, AlignCenter)
|
||||||
|
if rPadGot != rPadExp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", rPadExp, rPadGot)
|
||||||
|
}
|
||||||
|
if lPadGot != lPadExp {
|
||||||
|
t.Fatalf("expected '%d', got '%d'", lPadExp, lPadGot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPadded(t *testing.T) {
|
||||||
|
exp := "<3"
|
||||||
|
got := padded("<3", 1, AlignLeft)
|
||||||
|
if got != exp {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAsTable(t *testing.T) {
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
AsTable(&b, []string{"top"}, [][]string{[]string{"bottom"}})
|
||||||
|
|
||||||
|
// look for "+-------+" table style for whichever size
|
||||||
|
match, err := regexp.MatchString(`\++-+\+`, b.String())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to perform regex on table output")
|
||||||
|
}
|
||||||
|
if !match {
|
||||||
|
t.Fatalf("expected table in format not found")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue