Skip to content

Commit

Permalink
Use specific text for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Jan 22, 2015
1 parent 86ba80e commit 95ccf35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/commands/findreplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

type findTest struct {
in []Region
exp []Region
text string
in []Region
exp []Region
}

func runFindTest(tests []findTest, t *testing.T, commands ...string) {
Expand All @@ -27,11 +28,10 @@ func runFindTest(tests []findTest, t *testing.T, commands ...string) {
v.Close()
}()

e := v.BeginEdit()
v.Insert(e, 0, "Hello World!\nTest123123\nAbrakadabra\n")
v.EndEdit(e)

for i, test := range tests {
e := v.BeginEdit()
v.Insert(e, 0, test.text)
v.EndEdit(e)
v.Sel().Clear()
for _, r := range test.in {
v.Sel().Add(r)
Expand All @@ -42,16 +42,21 @@ func runFindTest(tests []findTest, t *testing.T, commands ...string) {
if sr := v.Sel().Regions(); !reflect.DeepEqual(sr, test.exp) {
t.Errorf("Test %d: Expected %s, but got %s", i, test.exp, sr)
}
e = v.BeginEdit()
v.Erase(e, Region{0, v.Buffer().Size()})
v.EndEdit(e)
}
}

func TestFindUnderExpand(t *testing.T) {
tests := []findTest{
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{0, 0}},
[]Region{{0, 5}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{19, 20}},
[]Region{{19, 20}, {22, 23}},
},
Expand All @@ -63,10 +68,12 @@ func TestFindUnderExpand(t *testing.T) {
func TestFindNext(t *testing.T) {
tests := []findTest{
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{17, 20}},
[]Region{{17, 20}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{21, 23}},
[]Region{{18, 20}},
},
Expand Down
6 changes: 6 additions & 0 deletions backend/commands/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import (
func TestSingleSelection(t *testing.T) {
tests := []findTest{
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{1, 1}, {2, 2}, {3, 3}, {6, 6}},
[]Region{{1, 1}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{2, 2}, {3, 3}, {6, 6}},
[]Region{{2, 2}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{5, 5}},
[]Region{{5, 5}},
},
Expand All @@ -31,14 +34,17 @@ func TestSingleSelection(t *testing.T) {
func TestSelectAll(t *testing.T) {
tests := []findTest{
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{1, 1}, {2, 2}, {3, 3}, {6, 6}},
[]Region{{0, 36}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{2, 2}, {3, 3}, {6, 6}},
[]Region{{0, 36}},
},
{
"Hello World!\nTest123123\nAbrakadabra\n",
[]Region{{5, 5}},
[]Region{{0, 36}},
},
Expand Down

0 comments on commit 95ccf35

Please sign in to comment.