37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package tokenize
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGivenCursor_WhenMoving_CursorIsUpdated(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
input []string
|
|
byte int
|
|
rune int
|
|
line int
|
|
column int
|
|
}{
|
|
{"No input at all", []string{""}, 0, 0, 0, 0},
|
|
{"One ASCII char", []string{"a"}, 1, 1, 0, 1},
|
|
{"Multiple ASCII chars", []string{"abc"}, 3, 3, 0, 3},
|
|
{"One newline", []string{"\n"}, 1, 1, 1, 0},
|
|
{"Carriage return", []string{"\r\r\r"}, 3, 3, 0, 3},
|
|
{"One UTF8 3 byte char", []string{"⌘"}, 3, 1, 0, 1},
|
|
{"Mixture", []string{"Hello\n\npretty\nW⌘O⌘R⌘L⌘D"}, 31, 23, 3, 9},
|
|
{"Multiple calls", []string{"hello", "world"}, 10, 10, 0, 10},
|
|
} {
|
|
api := NewAPI("")
|
|
for _, s := range test.input {
|
|
api.stackFrame.moveCursor(s)
|
|
}
|
|
if api.stackFrame.line != test.line {
|
|
t.Errorf("[%s] Unexpected line offset %d (expected %d)", test.name, api.stackFrame.line, test.line)
|
|
}
|
|
if api.stackFrame.column != test.column {
|
|
t.Errorf("[%s] Unexpected column offset %d (expected %d)", test.name, api.stackFrame.column, test.column)
|
|
}
|
|
}
|
|
}
|