7 func TestGetBufferCursorLocationEmptyArgs(t *testing.T) {
8 buf := NewBufferFromString("this is my\nbuffer\nfile\nhello", "")
10 location, err := GetBufferCursorLocation(nil, buf)
12 assertEqual(t, 0, location.Y)
13 assertEqual(t, 0, location.X)
15 // an error is present due to the cursorLocation being nil
16 assertTrue(t, err != nil)
20 func TestGetBufferCursorLocationStartposFlag(t *testing.T) {
21 buf := NewBufferFromString("this is my\nbuffer\nfile\nhello", "")
25 location, err := GetBufferCursorLocation(nil, buf)
27 // note: 1 is subtracted from the line to get the correct index in the buffer
28 assertTrue(t, 0 == location.Y)
29 assertTrue(t, 2 == location.X)
31 // an error is present due to the cursorLocation being nil
32 assertTrue(t, err != nil)
35 func TestGetBufferCursorLocationInvalidStartposFlag(t *testing.T) {
36 buf := NewBufferFromString("this is my\nbuffer\nfile\nhello", "")
38 *flagStartPos = "apples,2"
40 location, err := GetBufferCursorLocation(nil, buf)
41 // expect to default to the start of the file, which is 0,0
42 assertEqual(t, 0, location.Y)
43 assertEqual(t, 0, location.X)
45 // an error is present due to the cursorLocation being nil
46 assertTrue(t, err != nil)
48 func TestGetBufferCursorLocationStartposFlagAndCursorPosition(t *testing.T) {
49 text := "this is my\nbuffer\nfile\nhello"
50 cursorPosition := []string{"3", "1"}
52 buf := NewBufferFromString(text, "")
56 location, err := GetBufferCursorLocation(cursorPosition, buf)
57 // expect to have the flag positions, not the cursor position
58 // note: 1 is subtracted from the line to get the correct index in the buffer
59 assertEqual(t, 0, location.Y)
60 assertEqual(t, 2, location.X)
62 assertTrue(t, err == nil)
64 func TestGetBufferCursorLocationCursorPositionAndInvalidStartposFlag(t *testing.T) {
65 text := "this is my\nbuffer\nfile\nhello"
66 cursorPosition := []string{"3", "1"}
68 buf := NewBufferFromString(text, "")
70 *flagStartPos = "apples,2"
72 location, err := GetBufferCursorLocation(cursorPosition, buf)
73 // expect to have the flag positions, not the cursor position
74 // note: 1 is subtracted from the line to get the correct index in the buffer
75 assertEqual(t, 2, location.Y)
76 assertEqual(t, 1, location.X)
78 // no errors this time as cursorPosition is not nil
79 assertTrue(t, err == nil)
82 func TestGetBufferCursorLocationNoErrorWhenOverflowWithStartpos(t *testing.T) {
83 text := "this is my\nbuffer\nfile\nhello"
85 buf := NewBufferFromString(text, "")
87 *flagStartPos = "50,50"
89 location, err := GetBufferCursorLocation(nil, buf)
90 // expect to have the flag positions, not the cursor position
91 assertEqual(t, buf.NumLines-1, location.Y)
92 assertEqual(t, 5, location.X)
94 // error is expected as cursorPosition is nil
95 assertTrue(t, err != nil)
97 func TestGetBufferCursorLocationNoErrorWhenOverflowWithCursorPosition(t *testing.T) {
98 text := "this is my\nbuffer\nfile\nhello"
99 cursorPosition := []string{"50", "2"}
103 buf := NewBufferFromString(text, "")
105 location, err := GetBufferCursorLocation(cursorPosition, buf)
106 // expect to have the flag positions, not the cursor position
107 assertEqual(t, buf.NumLines-1, location.Y)
108 assertEqual(t, 2, location.X)
110 // error is expected as cursorPosition is nil
111 assertTrue(t, err == nil)
114 //func TestGetBufferCursorLocationColonArgs(t *testing.T) {
115 // buf := new(Buffer)