1
0
mirror of https://github.com/fumiama/go-simple-protobuf.git synced 2026-06-11 21:50:38 +08:00

feat: add iterator

This commit is contained in:
源文雨
2024-02-26 03:44:30 +09:00
parent 93032ad80a
commit 6c9102f75f
3 changed files with 115 additions and 5 deletions

42
reader_test.go Normal file
View File

@@ -0,0 +1,42 @@
package spb
import (
"bufio"
"fmt"
"os"
"testing"
)
func TestReader(t *testing.T) {
f, err := os.Open("dict.sp")
if err != nil {
t.Fatal(err)
}
defer f.Close()
ft, err := os.Open("dict.txt")
if err != nil {
t.Fatal(err)
}
defer ft.Close()
sc := bufio.NewScanner(ft)
var s Iterator
i := 1
for sc.Scan() {
s, err = NewReader(f)
if err != nil {
break
}
if !s.Next() {
t.Fatal("unexpected no next")
}
t0 := s.String()
if !s.Next() {
t.Fatal("unexpected no next")
}
t1 := s.String()
if fmt.Sprint(t0, "\t", t1) != sc.Text() {
t.Fatal("invalid text @ line", i)
}
i++
}
}