mirror of
https://github.com/zyedidia/micro
synced 2024-09-30 05:06:02 +00:00
Add some tests
This commit is contained in:
parent
df409630d2
commit
770ad7f444
6
Makefile
6
Makefile
|
@ -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
46
src/rope_test.go
Normal 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
39
src/stack_test.go
Normal 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")
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue