Skip to content

Commit

Permalink
Merge pull request #294 from nervo/utf-8-support
Browse files Browse the repository at this point in the history
UTF-8 Support
  • Loading branch information
goccy committed May 1, 2022
2 parents e4f32a2 + 91b0428 commit dadf142
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ast/ast.go
Expand Up @@ -266,7 +266,7 @@ func readNode(p []byte, node Node) (int, error) {
return 0, io.EOF
}
size := min(remain, len(p))
for idx, b := range s[readLen : readLen+size] {
for idx, b := range []byte(s[readLen : readLen+size]) {
p[idx] = byte(b)
}
node.addReadLen(size)
Expand Down
27 changes: 26 additions & 1 deletion ast/ast_test.go
@@ -1,6 +1,10 @@
package ast

import "testing"
import (
"testing"

"github.com/goccy/go-yaml/token"
)

func TestEscapeSingleQuote(t *testing.T) {
expected := `'Victor''s victory'`
Expand All @@ -9,3 +13,24 @@ func TestEscapeSingleQuote(t *testing.T) {
t.Fatalf("expected:%s\ngot:%s", expected, got)
}
}

func TestReadNode(t *testing.T) {
t.Run("utf-8", func(t *testing.T) {
value := "éɛทᛞ⠻チ▓🦄"
node := &StringNode{
BaseNode: &BaseNode{},
Token: &token.Token{},
Value: value,
}
expectedSize := len(value)
gotBuffer := make([]byte, expectedSize)
expectedBuffer := []byte(value)
gotSize, _ := readNode(gotBuffer, node)
if gotSize != expectedSize {
t.Fatalf("expected size:%d\ngot:%d", expectedSize, gotSize)
}
if string(gotBuffer) != string(expectedBuffer) {
t.Fatalf("expected buffer:%s\ngot:%s", expectedBuffer, gotBuffer)
}
})
}

0 comments on commit dadf142

Please sign in to comment.