1
0
Fork 0

Add more tests
timw4mail/gilo/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2021-03-31 19:17:04 -04:00
parent 513d328226
commit e7ba61b2aa
4 changed files with 51 additions and 12 deletions

35
editor/editor_test.go Normal file
View File

@ -0,0 +1,35 @@
package editor
import "testing"
func TestNew(t *testing.T) {
e := New()
if e == nil {
t.Errorf("Failed to create editor")
}
}
func TestAppendRow(t *testing.T) {
e := New()
e.appendRow("Test Row")
got := len(e.rows)
want := 1
if got != want {
t.Errorf("Failed to add a row to the editor")
}
}
func TestRowCount(t *testing.T) {
e := New()
e.appendRow("Test Row")
got := e.rowCount()
want := 1
if got != want {
t.Errorf("Expected %d rows, got %d rows", want, got)
}
}

View File

@ -25,3 +25,16 @@ func TestRowSize(t *testing.T) {
t.Errorf("Row size not equal to number of runes in original string")
}
}
func TestRenderSize(t *testing.T) {
str := "\tabcdefg"
row := newRow(str)
row.update()
got := row.rSize()
want := 11
if got != want {
t.Errorf("Row rsize not equal to number of runes in original string")
}
}

View File

@ -8,8 +8,6 @@ import (
// Put the terminal in raw mode
func RawOn() *term.State {
check()
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
@ -25,10 +23,3 @@ func RawOff(oldState *term.State) {
panic(err)
}
}
// Is this a valid interactive terminal?
func check() {
if !term.IsTerminal(int(os.Stdin.Fd())) {
panic("An interactive terminal is required to use a text editor!")
}
}

View File

@ -13,8 +13,6 @@ type Screen struct {
// Get the size of the terminal in rows and columns
func Size () *Screen {
check()
cols := 80
rows := 24
@ -25,7 +23,9 @@ func Size () *Screen {
}
// Figure out the size the hard way
rows, cols = sizeTrick()
if term.IsTerminal(int(os.Stdin.Fd())) {
rows, cols = sizeTrick()
}
return &Screen{ rows, cols }
}