This commit is contained in:
parent
513d328226
commit
e7ba61b2aa
35
editor/editor_test.go
Normal file
35
editor/editor_test.go
Normal 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)
|
||||
}
|
||||
}
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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!")
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user