File: parser_test_utilities_test.go

package info (click to toggle)
golang-github-azure-go-ansiterm 0.0~git20210617.d185dfc-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 232 kB
  • sloc: makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ansiterm

import (
	"testing"
)

func createTestParser(s string) (*AnsiParser, *TestAnsiEventHandler) {
	evtHandler := CreateTestAnsiEventHandler()
	parser := CreateParser(s, evtHandler)

	return parser, evtHandler
}

func validateState(t *testing.T, actualState state, expectedStateName string) {
	actualName := "Nil"

	if actualState != nil {
		actualName = actualState.Name()
	}

	if actualName != expectedStateName {
		t.Errorf("Invalid state: '%s' != '%s'", actualName, expectedStateName)
	}
}

func validateFuncCalls(t *testing.T, actualCalls []string, expectedCalls []string) {
	actualCount := len(actualCalls)
	expectedCount := len(expectedCalls)

	if actualCount != expectedCount {
		t.Errorf("Actual   calls: %v", actualCalls)
		t.Errorf("Expected calls: %v", expectedCalls)
		t.Errorf("Call count error: %d != %d", actualCount, expectedCount)
		return
	}

	for i, v := range actualCalls {
		if v != expectedCalls[i] {
			t.Errorf("Actual   calls: %v", actualCalls)
			t.Errorf("Expected calls: %v", expectedCalls)
			t.Errorf("Mismatched calls: %s != %s with lengths %d and %d", v, expectedCalls[i], len(v), len(expectedCalls[i]))
		}
	}
}

func fillContext(context *ansiContext) {
	context.currentChar = 'A'
	context.paramBuffer = []byte{'C', 'D', 'E'}
	context.interBuffer = []byte{'F', 'G', 'H'}
}

func validateEmptyContext(t *testing.T, context *ansiContext) {
	var expectedCurrChar byte = 0x0
	if context.currentChar != expectedCurrChar {
		t.Errorf("Currentchar mismatch '%#x' != '%#x'", context.currentChar, expectedCurrChar)
	}

	if len(context.paramBuffer) != 0 {
		t.Errorf("Non-empty parameter buffer: %v", context.paramBuffer)
	}

	if len(context.paramBuffer) != 0 {
		t.Errorf("Non-empty intermediate buffer: %v", context.interBuffer)
	}

}