Skip to content

Commit

Permalink
Added test case for unicode parsing #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
prataprc committed Jul 3, 2017
1 parent e3d193e commit 8589a49
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package parsec

import "reflect"
import "strings"
import "testing"
import "fmt"

Expand Down Expand Up @@ -203,6 +204,22 @@ func TestTrackLineno(t *testing.T) {
}
}

func TestUnicode(t *testing.T) {
text := "号分隔值, 逗号分隔值"
ytok := TokenExact(`[^,]+`, "FIELD")
y := Many(nil, ytok, Atom(",", "COMMA"))
s := NewScanner([]byte(text))
node, _ := y(s)
nodes := node.([]ParsecNode)
n1, n2 := nodes[0].(*Terminal), nodes[1].(*Terminal)
parts := strings.Split(text, ",")
if parts[0] != string(n1.Value) {
t.Errorf("expected %s, got %s", parts[0], n1.Value)
} else if parts[1] != string(n2.Value) {
t.Errorf("expected %s, got %s", parts[1], n2.Value)
}
}

func BenchmarkSScanClone(b *testing.B) {
text := []byte("hello world")
s := NewScanner(text)
Expand Down

0 comments on commit 8589a49

Please sign in to comment.