Debian Codegraph @

internal/util/util_test.go

raw
1 package util
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestStringWidth(t *testing.T) {
10 bytes := []byte("\tPot să \tmănânc sticlă și ea nu mă rănește.")
11
12 n := StringWidth(bytes, 23, 4)
13 assert.Equal(t, 26, n)
14 }
15
16 func TestSliceVisualEnd(t *testing.T) {
17 s := []byte("\thello")
18 slc, n, _ := SliceVisualEnd(s, 2, 4)
19 assert.Equal(t, []byte("\thello"), slc)
20 assert.Equal(t, 2, n)
21
22 slc, n, _ = SliceVisualEnd(s, 1, 4)
23 assert.Equal(t, []byte("\thello"), slc)
24 assert.Equal(t, 1, n)
25
26 slc, n, _ = SliceVisualEnd(s, 4, 4)
27 assert.Equal(t, []byte("hello"), slc)
28 assert.Equal(t, 0, n)
29
30 slc, n, _ = SliceVisualEnd(s, 5, 4)
31 assert.Equal(t, []byte("ello"), slc)
32 assert.Equal(t, 0, n)
33 }