summaryrefslogtreecommitdiff
path: root/pointer_test.go
blob: 6b432f075755187e20b04cf7e1f6408d8d9940a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package parsec

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestPointer(t *testing.T) {
	p := Pointer{"fooo", 0}

	t.Run("Advances", func(t *testing.T) {
		p2 := p.Advance(2)
		require.Equal(t, Pointer{"fooo", 2}, p2)
		require.Equal(t, Pointer{"fooo", 0}, p)
		require.Equal(t, Pointer{"fooo", 3}, p2.Advance(1))
	})

	t.Run("Get", func(t *testing.T) {
		require.Equal(t, "fooo", p.Get())
		require.Equal(t, "ooo", p.Advance(1).Get())
		require.Equal(t, "", p.Advance(4).Get())
		require.Equal(t, "", p.Advance(10).Get())
	})
}