Add some tests

This commit is contained in:
Zachary Yedidia 2016-03-25 13:42:41 -04:00
parent df409630d2
commit 770ad7f444
4 changed files with 95 additions and 0 deletions

View file

@ -8,3 +8,9 @@ install: syn-files build
syn-files:
mkdir -p ~/.micro/syntax
cp -r runtime/* ~/.micro
test:
go test ./src
clean:
rm -f micro

46
src/rope_test.go Normal file
View file

@ -0,0 +1,46 @@
package main
import "testing"
func TestInsert(t *testing.T) {
var tests = []struct {
origStr string
insertStr string
insertPos int
want string
}{
{"foo", " bar", 3, "foo bar"},
{"üñîç", "ø∂é", 4, "üñîçø∂é"},
{"test", "3", 2, "te3st"},
{"", "test", 0, "test"},
}
for _, test := range tests {
r := NewRope(test.origStr)
r.Insert(test.insertPos, test.insertStr)
got := r.String()
if got != test.want {
t.Errorf("Insert(%d, %s) = %s", test.insertPos, test.insertStr, got)
}
}
}
func TestRemove(t *testing.T) {
var tests = []struct {
inputStr string
removeStart int
removeEnd int
want string
}{
{"foo bar", 3, 7, "foo"},
{"üñîçø∂é", 0, 3, "çø∂é"},
{"test", 0, 4, ""},
}
for _, test := range tests {
r := NewRope(test.inputStr)
r.Remove(test.removeStart, test.removeEnd)
got := r.String()
if got != test.want {
t.Errorf("Remove(%d, %d) = %s", test.removeStart, test.removeEnd, got)
}
}
}

39
src/stack_test.go Normal file
View file

@ -0,0 +1,39 @@
package main
import "testing"
func TestStack(t *testing.T) {
stack := new(Stack)
if stack.Len() != 0 {
t.Errorf("Len failed")
}
stack.Push(5)
stack.Push("test")
stack.Push(10)
if stack.Len() != 3 {
t.Errorf("Len failed")
}
var popped interface{}
popped = stack.Pop()
if popped != 10 {
t.Errorf("Pop failed")
}
popped = stack.Pop()
if popped != "test" {
t.Errorf("Pop failed")
}
stack.Push("test")
popped = stack.Pop()
if popped != "test" {
t.Errorf("Pop failed")
}
stack.Pop()
popped = stack.Pop()
if popped != nil {
t.Errorf("Pop failed")
}
}

View file

@ -84,6 +84,10 @@ func NewViewWidthHeight(buf *Buffer, m *Messenger, w, h int) *View {
view: v,
}
// Set mouseReleased to true because we assume the mouse is not being pressed when
// the editor is opened
v.mouseReleased = true
return v
}