Exemplo n.º 1
0
func TestPeekBufferHasItem(t *testing.T) {
	testCaseList := []testCaseForPeekBufferHasItem{
		{data: "12345", expected: true},
		{data: "", expected: false},
	}

	for testIndex, testCase := range testCaseList {
		buffer := scanner.NewPeekBuffer()
		for _, testData := range testCase.data {
			buffer.Enqueue(testData)
		}
		actual := buffer.HasItem()
		expected := testCase.expected
		if actual != expected {
			t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, expected, actual)
		}
	}
}
Exemplo n.º 2
0
func TestPeekBufferLength(t *testing.T) {
	testCaseList := []testCaseForPeekBufferLength{
		{data: "12345", expected: 5},
		{data: "日本語", expected: 3},
	}

	for testIndex, testCase := range testCaseList {
		buffer := scanner.NewPeekBuffer()
		for _, testData := range testCase.data {
			buffer.Enqueue(testData)
		}
		actual := buffer.Length()
		expected := testCase.expected
		if actual != expected {
			t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, expected, actual)
		}
	}
}
Exemplo n.º 3
0
func TestPeekBufferPeek(t *testing.T) {
	testCaseList := []testCaseForPeekBufferPeek{
		{data: "12345", expected: '1'},
	}

	for testIndex, testCase := range testCaseList {
		buffer := scanner.NewPeekBuffer()
		for _, testData := range testCase.data {
			buffer.Enqueue(testData)
		}
		beforeLength := buffer.Length()
		expected := testCase.expected
		actual := buffer.Peek()
		if actual != expected {
			t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, expected, actual)
		}
		afterLength := buffer.Length()
		if beforeLength != afterLength {
			t.Errorf("testCase[%d] lengt changed", testIndex)
		}
	}
}
Exemplo n.º 4
0
func TestPeekBufferDequeue(t *testing.T) {
	testCaseList := []testCaseForPeekBufferDequeue{
		{data: "12345", expected: []rune{'1', '2', '3', '4', '5'}},
	}

	for testIndex, testCase := range testCaseList {
		buffer := scanner.NewPeekBuffer()
		for _, testData := range testCase.data {
			buffer.Enqueue(testData)
		}
		for expectedIndex, expected := range testCase.expected {
			beforeLength := buffer.Length()
			actual := buffer.Dequeue()
			if actual != expected {
				t.Errorf("testCase[%d:%d] expected=%#v, actual=%#v", testIndex, expectedIndex, expected, actual)
			}
			afterLength := buffer.Length()
			if beforeLength-1 != afterLength {
				t.Errorf("testCase[%d:%d] length is wrong", testIndex, expectedIndex)
			}
		}
	}
}
Exemplo n.º 5
0
func TestPeekBufferEnqueue(t *testing.T) {
	testCaseList := []testCaseForPeekBufferEnqueue{
		{data: "12345", expected: true},
		{data: "", expected: false},
	}

	for testIndex, testCase := range testCaseList {
		buffer := scanner.NewPeekBuffer()
		for _, testData := range testCase.data {
			beforeLength := buffer.Length()
			buffer.Enqueue(testData)
			afterLength := buffer.Length()
			if beforeLength+1 != afterLength {
				t.Errorf("testCase[%d] length is wrong", testIndex)
			}
		}
		actual := buffer.HasItem()
		expected := testCase.expected
		if actual != expected {
			t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, expected, actual)
		}
	}
}
Exemplo n.º 6
0
func TestNewPeekBuffer(t *testing.T) {
	actual := scanner.NewPeekBuffer()
	if actual == nil {
		t.Error("PeekBuffer not created")
	}
}