github.com/madlambda/nash@v0.2.2-0.20230113003044-f2284521680b/readline/runes/runes_test.go (about) 1 package runes 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 type twidth struct { 9 r []rune 10 length int 11 } 12 13 func TestRuneWidth(t *testing.T) { 14 runes := []twidth{ 15 {[]rune("☭"), 1}, 16 {[]rune("a"), 1}, 17 {[]rune("你"), 2}, 18 {ColorFilter([]rune("☭\033[13;1m你")), 3}, 19 } 20 for _, r := range runes { 21 if w := WidthAll(r.r); w != r.length { 22 t.Fatal("result not expect", r.r, r.length, w) 23 } 24 } 25 } 26 27 type tagg struct { 28 r [][]rune 29 e [][]rune 30 length int 31 } 32 33 func TestAggRunes(t *testing.T) { 34 runes := []tagg{ 35 { 36 [][]rune{[]rune("ab"), []rune("a"), []rune("abc")}, 37 [][]rune{[]rune("b"), []rune(""), []rune("bc")}, 38 1, 39 }, 40 { 41 [][]rune{[]rune("addb"), []rune("ajkajsdf"), []rune("aasdfkc")}, 42 [][]rune{[]rune("ddb"), []rune("jkajsdf"), []rune("asdfkc")}, 43 1, 44 }, 45 { 46 [][]rune{[]rune("ddb"), []rune("ajksdf"), []rune("aasdfkc")}, 47 [][]rune{[]rune("ddb"), []rune("ajksdf"), []rune("aasdfkc")}, 48 0, 49 }, 50 { 51 [][]rune{[]rune("ddb"), []rune("ddajksdf"), []rune("ddaasdfkc")}, 52 [][]rune{[]rune("b"), []rune("ajksdf"), []rune("aasdfkc")}, 53 2, 54 }, 55 } 56 for _, r := range runes { 57 same, off := Aggregate(r.r) 58 if off != r.length { 59 t.Fatal("result not expect", off) 60 } 61 if len(same) != off { 62 t.Fatal("result not expect", same) 63 } 64 if !reflect.DeepEqual(r.r, r.e) { 65 t.Fatal("result not expect") 66 } 67 } 68 }