github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/virtualterm/term_test.go (about) 1 package virtualterm 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/test/count" 7 ) 8 9 func TestWriteCell(t *testing.T) { 10 count.Tests(t, 1) 11 12 test := "Hello world!" 13 exp := "Hello\n worl\nd! \n" 14 15 term := NewTerminal(5, 3) 16 17 for _, r := range []rune(test) { 18 term.writeCell(r) 19 } 20 act := term.Export() 21 22 if exp != act { 23 t.Error("Expected output does not match actual output") 24 t.Logf(" Expected: '%s'", exp) 25 t.Logf(" Actual: '%s'", act) 26 t.Logf(" exp bytes: %v", []byte(exp)) 27 t.Logf(" act bytes: %v", []byte(act)) 28 } 29 } 30 31 func TestMoveContentsUp(t *testing.T) { 32 count.Tests(t, 1) 33 34 test := "1234554321" 35 exp := "54321\n \n \n" 36 37 term := NewTerminal(5, 3) 38 39 for _, r := range []rune(test) { 40 term.writeCell(r) 41 } 42 term.moveContentsUp() 43 44 act := term.Export() 45 46 if exp != act { 47 t.Error("Expected output does not match actual output") 48 t.Logf(" Expected: '%s'", exp) 49 t.Logf(" Actual: '%s'", act) 50 t.Logf(" exp bytes: %v", []byte(exp)) 51 t.Logf(" act bytes: %v", []byte(act)) 52 } 53 } 54 55 func TestCell(t *testing.T) { 56 count.Tests(t, 1) 57 58 term := NewTerminal(5, 3) 59 term.cells[1][4].char = 'T' 60 term.curPos.X = 4 61 term.curPos.Y = 1 62 63 c := term.cell().char 64 if c != 'T' { 65 t.Errorf("*Term.Cell look up appears to fail. %d", c) 66 } 67 } 68 69 func TestMoveCursorForwards(t *testing.T) { 70 count.Tests(t, 1) 71 72 term := NewTerminal(5, 3) 73 overflow := term.moveCursorForwards(5) 74 75 if term.curPos.X != term.size.X-1 { 76 t.Errorf("curPos.X not where expected:") 77 t.Logf(" Expected: %d", term.size.X-1) 78 t.Logf(" Actual: %d", term.curPos.X) 79 } 80 81 if overflow != 1 { 82 t.Errorf("overflow value does not match expected:") 83 t.Logf(" Expected: %d", 1) 84 t.Logf(" Actual: %d", overflow) 85 } 86 } 87 88 func TestMoveCursorDownwards(t *testing.T) { 89 count.Tests(t, 1) 90 91 term := NewTerminal(5, 3) 92 overflow := term.moveCursorDownwards(3) 93 94 if term.curPos.Y != term.size.Y-1 { 95 t.Errorf("curPos.Y not where expected:") 96 t.Logf(" Expected: %d", term.size.Y-1) 97 t.Logf(" Actual: %d", term.curPos.Y) 98 } 99 100 if overflow != 1 { 101 t.Errorf("overflow value does not match expected:") 102 t.Logf(" Expected: %d", 1) 103 t.Logf(" Actual: %d", overflow) 104 } 105 }