...

Source file src/github.com/Azure/go-ansiterm/parser_test_utilities_test.go

Documentation: github.com/Azure/go-ansiterm

     1  package ansiterm
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func createTestParser(s string) (*AnsiParser, *TestAnsiEventHandler) {
     8  	evtHandler := CreateTestAnsiEventHandler()
     9  	parser := CreateParser(s, evtHandler)
    10  
    11  	return parser, evtHandler
    12  }
    13  
    14  func validateState(t *testing.T, actualState state, expectedStateName string) {
    15  	actualName := "Nil"
    16  
    17  	if actualState != nil {
    18  		actualName = actualState.Name()
    19  	}
    20  
    21  	if actualName != expectedStateName {
    22  		t.Errorf("Invalid state: '%s' != '%s'", actualName, expectedStateName)
    23  	}
    24  }
    25  
    26  func validateFuncCalls(t *testing.T, actualCalls []string, expectedCalls []string) {
    27  	actualCount := len(actualCalls)
    28  	expectedCount := len(expectedCalls)
    29  
    30  	if actualCount != expectedCount {
    31  		t.Errorf("Actual   calls: %v", actualCalls)
    32  		t.Errorf("Expected calls: %v", expectedCalls)
    33  		t.Errorf("Call count error: %d != %d", actualCount, expectedCount)
    34  		return
    35  	}
    36  
    37  	for i, v := range actualCalls {
    38  		if v != expectedCalls[i] {
    39  			t.Errorf("Actual   calls: %v", actualCalls)
    40  			t.Errorf("Expected calls: %v", expectedCalls)
    41  			t.Errorf("Mismatched calls: %s != %s with lengths %d and %d", v, expectedCalls[i], len(v), len(expectedCalls[i]))
    42  		}
    43  	}
    44  }
    45  
    46  func fillContext(context *ansiContext) {
    47  	context.currentChar = 'A'
    48  	context.paramBuffer = []byte{'C', 'D', 'E'}
    49  	context.interBuffer = []byte{'F', 'G', 'H'}
    50  }
    51  
    52  func validateEmptyContext(t *testing.T, context *ansiContext) {
    53  	var expectedCurrChar byte = 0x0
    54  	if context.currentChar != expectedCurrChar {
    55  		t.Errorf("Currentchar mismatch '%#x' != '%#x'", context.currentChar, expectedCurrChar)
    56  	}
    57  
    58  	if len(context.paramBuffer) != 0 {
    59  		t.Errorf("Non-empty parameter buffer: %v", context.paramBuffer)
    60  	}
    61  
    62  	if len(context.paramBuffer) != 0 {
    63  		t.Errorf("Non-empty intermediate buffer: %v", context.interBuffer)
    64  	}
    65  
    66  }
    67  

View as plain text