github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/editor_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/xyproto/mode" 8 ) 9 10 func TestEditor(t *testing.T) { 11 e := NewSimpleEditor(80) 12 e.InsertRune(nil, 'a') 13 if e.String() != "a\n" { 14 fmt.Println("Expected \"a\" and a newline, got:", e.String()) 15 t.Fail() 16 } 17 } 18 19 func ExampleEditor_InsertStringAndMove() { 20 e := NewSimpleEditor(80) 21 e.InsertStringAndMove(nil, "hello") 22 23 fmt.Println(e) 24 // Output: 25 // hello 26 } 27 28 func ExampleEditor_Home() { 29 e := NewSimpleEditor(80) 30 e.InsertStringAndMove(nil, "llo") 31 e.Home() 32 e.InsertStringAndMove(nil, "he") 33 34 fmt.Println(e) 35 // Output: 36 // hello 37 } 38 39 func ExampleEditor_End() { 40 e := NewSimpleEditor(80) 41 e.InsertStringAndMove(nil, "el") 42 e.Home() 43 e.InsertRune(nil, 'h') 44 e.End(nil) 45 e.InsertStringAndMove(nil, "lo") 46 47 fmt.Println(e) 48 // Output: 49 // hello 50 } 51 52 func ExampleEditor_Next() { 53 e := NewSimpleEditor(80) 54 e.InsertStringAndMove(nil, "hllo") 55 e.Home() 56 e.Next(nil) 57 e.InsertRune(nil, 'e') 58 59 fmt.Println(e) 60 // Output: 61 // hello 62 } 63 64 func ExampleEditor_InsertRune() { 65 e := NewSimpleEditor(80) 66 e.mode = mode.SQL 67 68 e.InsertStringAndMove(nil, "text -- comment") 69 e.Home() 70 e.Next(nil) 71 e.Next(nil) 72 e.Next(nil) 73 e.Next(nil) 74 e.InsertRune(nil, '\n') 75 76 fmt.Println(e) 77 // Output: 78 // text 79 // -- comment 80 }