2016-12-01 04:35:38 +02:00
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2017-01-05 15:23:08 +02:00
|
|
|
"testing"
|
2016-12-01 04:35:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_read_by_one(t *testing.T) {
|
2017-06-15 17:54:43 +02:00
|
|
|
iter := Parse(ConfigOfDefault, bytes.NewBufferString("abc"), 1)
|
2016-12-01 04:35:38 +02:00
|
|
|
b := iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'a' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
iter.unreadByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
iter.unreadByte()
|
|
|
|
if iter.Error == nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
iter.Error = nil
|
|
|
|
b = iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'a' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_read_by_two(t *testing.T) {
|
2017-06-15 17:54:43 +02:00
|
|
|
iter := Parse(ConfigOfDefault, bytes.NewBufferString("abc"), 2)
|
2016-12-01 04:35:38 +02:00
|
|
|
b := iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'a' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
b = iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'b' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
iter.unreadByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
iter.unreadByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
b = iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'a' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_read_until_eof(t *testing.T) {
|
2017-06-15 17:54:43 +02:00
|
|
|
iter := Parse(ConfigOfDefault, bytes.NewBufferString("abc"), 2)
|
2016-12-01 04:35:38 +02:00
|
|
|
iter.readByte()
|
|
|
|
iter.readByte()
|
|
|
|
b := iter.readByte()
|
|
|
|
if iter.Error != nil {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
|
|
|
if b != 'c' {
|
|
|
|
t.Fatal(b)
|
|
|
|
}
|
|
|
|
iter.readByte()
|
|
|
|
if iter.Error != io.EOF {
|
|
|
|
t.Fatal(iter.Error)
|
|
|
|
}
|
2017-01-05 15:23:08 +02:00
|
|
|
}
|