From 78b9d1a14311a5bd82c219eb4fa815a54ad832bd Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 10 Nov 2023 15:58:33 +0100 Subject: prog: add helper function parser.HasNext This helper function will be used in a subsequent commit to take a look ahead at several characters. Signed-off-by: Paul Chaignon --- prog/encoding_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'prog/encoding_test.go') diff --git a/prog/encoding_test.go b/prog/encoding_test.go index e99663aa3..daa2ac0cb 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -515,3 +515,26 @@ serialize0(0x0) t.Errorf("bad program comments %q\nwant: %q", p.Comments, wantComments) } } + +func TestHasNext(t *testing.T) { + testCases := []struct { + input string + expected bool + }{ + {"abcdef", true}, + {"xyz", false}, + {"ab", false}, + {"abc", true}, + } + for _, testCase := range testCases { + p := newParser(nil, []byte(testCase.input), true) + if !p.Scan() { + t.Fatalf("parser does not scan") + } + result := p.HasNext("abc") + if result != testCase.expected { + t.Errorf("expected HasNext(\"abc\") on input %q to be %v, but got %v", + testCase.input, testCase.expected, result) + } + } +} -- cgit mrf-deployment