-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Please keep the contents of this file sorted alphabetically. | ||
|
||
Calum MacRae <[email protected]> | ||
Mateusz Czapliński <[email protected]> | ||
Rohan Verma <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func Test_Editor_insert(test *testing.T) { | ||
cases := []struct { | ||
comment string | ||
e Editor | ||
insert []rune | ||
wantValue []rune | ||
}{ | ||
{ | ||
comment: "prepend ASCII char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 0, | ||
}, | ||
insert: []rune{'X'}, | ||
wantValue: []rune(`Xabc`), | ||
}, | ||
{ | ||
comment: "prepend UTF char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 0, | ||
}, | ||
insert: []rune{'☃'}, | ||
wantValue: []rune(`☃abc`), | ||
}, | ||
{ | ||
comment: "insert ASCII char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 1, | ||
}, | ||
insert: []rune{'X'}, | ||
wantValue: []rune(`aXbc`), | ||
}, | ||
{ | ||
comment: "insert UTF char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 1, | ||
}, | ||
insert: []rune{'☃'}, | ||
wantValue: []rune(`a☃bc`), | ||
}, | ||
{ | ||
comment: "append ASCII char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 3, | ||
}, | ||
insert: []rune{'X'}, | ||
wantValue: []rune(`abcX`), | ||
}, | ||
{ | ||
comment: "append UTF char", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 3, | ||
}, | ||
insert: []rune{'☃'}, | ||
wantValue: []rune(`abc☃`), | ||
}, | ||
{ | ||
comment: "insert 2 ASCII chars", | ||
e: Editor{ | ||
value: []rune(`abc`), | ||
cursor: 1, | ||
}, | ||
insert: []rune{'X', 'Y'}, | ||
wantValue: []rune(`aXYbc`), | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c.e.insert(c.insert...) | ||
if string(c.e.value) != string(c.wantValue) { | ||
test.Errorf("%q: bad value\nwant: %q\nhave: %q", c.comment, c.wantValue, c.e.value) | ||
} | ||
} | ||
} |