summaryrefslogtreecommitdiff
path: root/ui/width_test.go
diff options
context:
space:
mode:
authorHubert Hirtz <hubert.hirtz@laposte.net>2020-06-04 22:55:15 +0200
committerHubert Hirtz <hubert.hirtz@laposte.net>2020-06-04 22:55:15 +0200
commitf7331d1c665bd997fe5bc41c6d375d30ea9f4457 (patch)
treefe3ba9f932ace2b8582fa0f9b903349aa44017cb /ui/width_test.go
parentFix color codes (diff)
Buffers are now shown (mostly) correctly
senpai must now split on whitespace when drawing
Diffstat (limited to '')
-rw-r--r--ui/width_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/ui/width_test.go b/ui/width_test.go
new file mode 100644
index 0000000..ae478ab
--- /dev/null
+++ b/ui/width_test.go
@@ -0,0 +1,25 @@
+package ui
+
+import "testing"
+
+func assertStringWidth(t *testing.T, input string, expected int) {
+ actual := StringWidth(input)
+ if actual != expected {
+ t.Errorf("%q: expected width of %d got %d", input, expected, actual)
+ }
+}
+
+func TestStringWidth(t *testing.T) {
+ assertStringWidth(t, "", 0)
+
+ assertStringWidth(t, "hello", 5)
+ assertStringWidth(t, "\x02hello", 5)
+ assertStringWidth(t, "\x035hello", 5)
+ assertStringWidth(t, "\x0305hello", 5)
+ assertStringWidth(t, "\x0305,0hello", 5)
+ assertStringWidth(t, "\x0305,09hello", 5)
+
+ assertStringWidth(t, "\x0305,hello", 6)
+ assertStringWidth(t, "\x03050hello", 6)
+ assertStringWidth(t, "\x0305,090hello", 6)
+}