9 # Comments should be skipped
10 # rune; bool; uint; int; float; runes; # Y
11 0..0005; Y; 0; 2; -5.25 ; 0 1 2 3 4 5;
12 6..0007; Yes ; 6; 1; -4.25 ; 0006 0007;
13 8; T ; 8 ; 0 ;-3.25 ;;# T
14 9; True ;9 ; -1;-2.25 ; 0009;
16 # more comments to be ignored
19 A; N; 10 ; -2; -1.25; ;# N
20 B; No; 11 ; -3; -0.25;
21 C; False;12; -4; 0.75;
24 @Part1 # Another part.
25 # We test part comments get removed by not commenting the the next line.
26 E..10FFFF; F; 14 ; -6; 2.75;
43 func TestGetters(t *testing.T) {
46 {"Part1", "Another part."},
48 handler := func(p *Parser) {
50 t.Error("Part handler invoked too many times.")
55 if got0, got1 := p.String(0), p.Comment(); got0 != want[0] || got1 != want[1] {
56 t.Errorf(`part: got %q, %q; want %q"`, got0, got1, want)
60 p := New(strings.NewReader(file), KeepRanges, Part(handler))
61 for i := 0; p.Next(); i++ {
62 start, end := p.Range(0)
64 if start != w.start || end != w.end {
65 t.Fatalf("%d:Range(0); got %#x..%#x; want %#x..%#x", i, start, end, w.start, w.end)
67 if w.start == w.end && p.Rune(0) != w.start {
68 t.Errorf("%d:Range(0).start: got %U; want %U", i, p.Rune(0), w.start)
70 if got, want := p.Bool(1), w.start <= 9; got != want {
71 t.Errorf("%d:Bool(1): got %v; want %v", i, got, want)
73 if got := p.Rune(4); got != 0 || p.Err() == nil {
74 t.Errorf("%d:Rune(%q): got no error; want error", i, p.String(1))
77 if got := p.Uint(2); rune(got) != start {
78 t.Errorf("%d:Uint(2): got %v; want %v", i, got, start)
80 if got, want := p.Int(3), 2-i; got != want {
81 t.Errorf("%d:Int(3): got %v; want %v", i, got, want)
83 if got, want := p.Float(4), -5.25+float64(i); got != want {
84 t.Errorf("%d:Int(3): got %v; want %v", i, got, want)
86 if got := p.Runes(5); got == nil {
87 if p.String(5) != "" {
88 t.Errorf("%d:Runes(5): expected non-empty list", i)
91 if got[0] != start || got[len(got)-1] != end {
92 t.Errorf("%d:Runes(5): got %#x; want %#x..%#x", i, got, start, end)
95 if got := p.Comment(); got != "" && got != p.String(1) {
96 t.Errorf("%d:Comment(): got %v; want %v", i, got, p.String(1))
99 if err := p.Err(); err != nil {
100 t.Errorf("Parser error: %v", err)
103 t.Errorf("expected %d more invocations of part handler", len(parts))