Exemplo n.º 1
0
func TestLexerSmall(t *testing.T) {
	s := `abcdefghijklm`
	z := NewLexerSize(test.NewPlainReader(bytes.NewBufferString(s)), 4)
	test.That(t, z.Peek(8) == 'i', "first character must be 'i' at position 8")

	z = NewLexerSize(test.NewPlainReader(bytes.NewBufferString(s)), 4)
	test.That(t, z.Peek(12) == 'm', "first character must be 'm' at position 12")

	z = NewLexerSize(test.NewPlainReader(bytes.NewBufferString(s)), 0)
	test.That(t, z.Peek(4) == 'e', "first character must be 'e' at position 4")

	z = NewLexerSize(test.NewPlainReader(bytes.NewBufferString(s)), 13)
	test.That(t, z.Peek(13) == 0, "thirteenth character must yield error")
}
Exemplo n.º 2
0
func TestLexerShift(t *testing.T) {
	s := `Lorem ipsum dolor sit amet, consectetur adipiscing elit.`
	z := NewLexerSize(test.NewPlainReader(bytes.NewBufferString(s)), 5)

	z.Move(len("Lorem "))
	test.Bytes(t, z.Shift(), []byte("Lorem "), "shift must return the buffered string")
	test.That(t, z.ShiftLen() == len("Lorem "), "shifted length must equal last shift")
}
Exemplo n.º 3
0
func TestReader(t *testing.T) {
	input := "x:a;"
	p := NewParser(test.NewPlainReader(bytes.NewBufferString(input)), true)
	for {
		gt, _, _ := p.Next()
		if gt == ErrorGrammar {
			break
		}
	}
}
Exemplo n.º 4
0
func TestShifterZeroLen(t *testing.T) {
	var z = NewShifter(test.NewPlainReader(bytes.NewBufferString("")))
	test.That(t, z.Peek(0) == 0, "first character must yield error")
}
Exemplo n.º 5
0
func TestShifterSmall(t *testing.T) {
	s := `abcdefghi`
	z := NewShifterSize(test.NewPlainReader(bytes.NewBufferString(s)), 4)
	test.That(t, z.Peek(8) == 'i', "first character must be 'i' at position 8")
}