MCPcopy Index your code
hub / github.com/antonmedv/gitmal / TestLineOperations

Function TestLineOperations

pkg/gitdiff/parser_test.go:13–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestLineOperations(t *testing.T) {
14 const content = "the first line\nthe second line\nthe third line\n"
15
16 t.Run("read", func(t *testing.T) {
17 p := newTestParser(content, false)
18
19 for i, expected := range []string{
20 "the first line\n",
21 "the second line\n",
22 "the third line\n",
23 } {
24 if err := p.Next(); err != nil {
25 t.Fatalf("error advancing parser after line %d: %v", i, err)
26 }
27 if p.lineno != int64(i+1) {
28 t.Fatalf("incorrect line number: expected %d, actual: %d", i+1, p.lineno)
29 }
30
31 line := p.Line(0)
32 if line != expected {
33 t.Fatalf("incorrect line %d: expected %q, was %q", i+1, expected, line)
34 }
35 }
36
37 // reading after the last line should return EOF
38 if err := p.Next(); err != io.EOF {
39 t.Fatalf("expected EOF after end, but got: %v", err)
40 }
41 if p.lineno != 4 {
42 t.Fatalf("incorrect line number: expected %d, actual: %d", 4, p.lineno)
43 }
44
45 // reading again returns EOF again and does not advance the line
46 if err := p.Next(); err != io.EOF {
47 t.Fatalf("expected EOF after end, but got: %v", err)
48 }
49 if p.lineno != 4 {
50 t.Fatalf("incorrect line number: expected %d, actual: %d", 4, p.lineno)
51 }
52 })
53
54 t.Run("peek", func(t *testing.T) {
55 p := newTestParser(content, false)
56 if err := p.Next(); err != nil {
57 t.Fatalf("error advancing parser: %v", err)
58 }
59
60 line := p.Line(1)
61 if line != "the second line\n" {
62 t.Fatalf("incorrect peek line: %s", line)
63 }
64
65 if err := p.Next(); err != nil {
66 t.Fatalf("error advancing parser after peek: %v", err)
67 }
68
69 line = p.Line(0)
70 if line != "the second line\n" {

Callers

nothing calls this directly

Calls 3

newTestParserFunction · 0.85
NextMethod · 0.80
LineMethod · 0.80

Tested by

no test coverage detected