コード例 #1
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
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)
		}
	}
}
コード例 #2
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
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)
		}
	}
}
コード例 #3
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
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)
		}
	}
}
コード例 #4
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
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)
			}
		}
	}
}
コード例 #5
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
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)
		}
	}
}
コード例 #6
0
ファイル: peekbuffer_test.go プロジェクト: mm0205/gjson
func TestNewPeekBuffer(t *testing.T) {
	actual := scanner.NewPeekBuffer()
	if actual == nil {
		t.Error("PeekBuffer not created")
	}
}