github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/ansititle/ansititle_test.go (about) 1 //go:build !js 2 // +build !js 3 4 package ansititle 5 6 import ( 7 "testing" 8 9 "github.com/lmorg/murex/test/count" 10 ) 11 12 func TestFormatTitle(t *testing.T) { 13 type testT struct { 14 Title string 15 Format []byte 16 } 17 18 tests := []testT{ 19 { 20 Title: "", 21 Format: nil, 22 }, 23 { 24 Title: "1", 25 Format: []byte{27, ']', '2', ';', '1', 27, '\\'}, 26 }, 27 { 28 Title: "12", 29 Format: []byte{27, ']', '2', ';', '1', '2', 27, '\\'}, 30 }, 31 { 32 Title: "123", 33 Format: []byte{27, ']', '2', ';', '1', '2', '3', 27, '\\'}, 34 }, 35 { 36 Title: "1234", 37 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', 27, '\\'}, 38 }, 39 { 40 Title: "12345", 41 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', 27, '\\'}, 42 }, 43 { 44 Title: "123456", 45 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', '6', 27, '\\'}, 46 }, 47 { 48 Title: "1234567", 49 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', '6', '7', 27, '\\'}, 50 }, 51 { 52 Title: "12345678", 53 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', '6', '7', '8', 27, '\\'}, 54 }, 55 { 56 Title: "123456789", 57 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', '6', '7', '8', '9', 27, '\\'}, 58 }, 59 { 60 Title: "1234567890", 61 Format: []byte{27, ']', '2', ';', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 27, '\\'}, 62 }, 63 // TODO: test unicode 64 } 65 66 count.Tests(t, len(tests)) 67 68 for i, test := range tests { 69 70 actual := formatTitle([]byte(test.Title)) 71 72 if string(actual) != string(test.Format) { 73 t.Errorf("Format error in %s test %d", t.Name(), i) 74 t.Logf(" Title: '%s'", test.Title) 75 t.Logf(" Expected: '%s'", string(test.Format)) 76 t.Logf(" Actual: '%s'", string(actual)) 77 t.Logf(" exp byte: %v", test.Format) 78 t.Logf(" act byte: %v", actual) 79 } 80 } 81 } 82 83 func TestFormatIcon(t *testing.T) { 84 type testT struct { 85 Title string 86 Format []byte 87 } 88 89 tests := []testT{ 90 { 91 Title: "", 92 Format: nil, 93 }, 94 { 95 Title: "1", 96 Format: []byte{27, ']', '1', ';', '1', 27, '\\'}, 97 }, 98 { 99 Title: "12", 100 Format: []byte{27, ']', '1', ';', '1', '2', 27, '\\'}, 101 }, 102 { 103 Title: "123", 104 Format: []byte{27, ']', '1', ';', '1', '2', '3', 27, '\\'}, 105 }, 106 { 107 Title: "1234", 108 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', 27, '\\'}, 109 }, 110 { 111 Title: "12345", 112 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', 27, '\\'}, 113 }, 114 { 115 Title: "123456", 116 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', '6', 27, '\\'}, 117 }, 118 { 119 Title: "1234567", 120 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', '6', '7', 27, '\\'}, 121 }, 122 { 123 Title: "12345678", 124 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', '6', '7', '8', 27, '\\'}, 125 }, 126 { 127 Title: "123456789", 128 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', '6', '7', '8', '9', 27, '\\'}, 129 }, 130 { 131 Title: "1234567890", 132 Format: []byte{27, ']', '1', ';', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 27, '\\'}, 133 }, 134 // TODO: test unicode 135 } 136 137 count.Tests(t, len(tests)) 138 139 for i, test := range tests { 140 141 actual := formatIcon([]byte(test.Title)) 142 143 if string(actual) != string(test.Format) { 144 t.Errorf("Format error in %s test %d", t.Name(), i) 145 t.Logf(" Title: '%s'", test.Title) 146 t.Logf(" Expected: '%s'", string(test.Format)) 147 t.Logf(" Actual: '%s'", string(actual)) 148 t.Logf(" exp byte: %v", test.Format) 149 t.Logf(" act byte: %v", actual) 150 } 151 } 152 } 153 154 func TestFormatTmux(t *testing.T) { 155 type testT struct { 156 Title string 157 Format []byte 158 } 159 160 tests := []testT{ 161 { 162 Title: "", 163 Format: nil, 164 }, 165 { 166 Title: "1", 167 Format: []byte{27, 'k', '1', 27, '\\'}, 168 }, 169 { 170 Title: "12", 171 Format: []byte{27, 'k', '1', '2', 27, '\\'}, 172 }, 173 { 174 Title: "123", 175 Format: []byte{27, 'k', '1', '2', '3', 27, '\\'}, 176 }, 177 { 178 Title: "1234", 179 Format: []byte{27, 'k', '1', '2', '3', '4', 27, '\\'}, 180 }, 181 { 182 Title: "12345", 183 Format: []byte{27, 'k', '1', '2', '3', '4', '5', 27, '\\'}, 184 }, 185 { 186 Title: "123456", 187 Format: []byte{27, 'k', '1', '2', '3', '4', '5', '6', 27, '\\'}, 188 }, 189 { 190 Title: "1234567", 191 Format: []byte{27, 'k', '1', '2', '3', '4', '5', '6', '7', 27, '\\'}, 192 }, 193 { 194 Title: "12345678", 195 Format: []byte{27, 'k', '1', '2', '3', '4', '5', '6', '7', '8', 27, '\\'}, 196 }, 197 { 198 Title: "123456789", 199 Format: []byte{27, 'k', '1', '2', '3', '4', '5', '6', '7', '8', '9', 27, '\\'}, 200 }, 201 { 202 Title: "1234567890", 203 Format: []byte{27, 'k', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 27, '\\'}, 204 }, 205 // TODO: test unicode 206 } 207 208 count.Tests(t, len(tests)) 209 210 for i, test := range tests { 211 212 actual := formatTmux([]byte(test.Title)) 213 214 if string(actual) != string(test.Format) { 215 t.Errorf("Format error in %s test %d", t.Name(), i) 216 t.Logf(" Title: '%s'", test.Title) 217 t.Logf(" Expected: '%s'", string(test.Format)) 218 t.Logf(" Actual: '%s'", string(actual)) 219 t.Logf(" exp byte: %v", test.Format) 220 t.Logf(" act byte: %v", actual) 221 } 222 } 223 }