Skip to content

Commit

Permalink
Add test for utf8, japanese characters and emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
meyermarcel committed Jun 6, 2024
1 parent 71b79ce commit 9128676
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions annot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"io"
"slices"
"strings"
"unicode/utf8"

"github.com/rivo/uniseg"
)

// Annot annotates information with a text (represented in Lines)
Expand Down Expand Up @@ -88,7 +89,7 @@ func Write(w io.Writer, annots ...*Annot) error {
a.lines = make([]*line, len(a.Lines))
for i := range a.Lines {
a.lines[i] = &line{
length: utf8.RuneCountInString(a.Lines[i]),
length: uniseg.StringWidth(a.Lines[i]),
leadingSpaces: a.Col,
}
}
Expand Down
13 changes: 13 additions & 0 deletions annot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ func TestWrite(t *testing.T) {
line3
line4
line5
`,
wantErr: false,
},
{
name: "utf8, japanese characters and emojis",
annots: []*Annot{
{Col: 0, Lines: []string{"⭐️漢", "æñ🥏NJ"}},
{Col: 10, Lines: []string{"æñŶǼNJ", "字ñŶǼNJ"}},
},
wantW: `
↑ ↑
└─ ⭐️漢 └─ æñŶǼNJ
æñ🥏NJ 字ñŶǼNJ
`,
wantErr: false,
},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/meyermarcel/annot

go 1.22

require github.com/rivo/uniseg v0.4.7
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=

0 comments on commit 9128676

Please sign in to comment.