Exemple #1
0
func TestInitLexer(t *testing.T) {
	l := new(compiler.Lexer).Init("package a")

	if l.GetInput() != "package a" {
		t.Fatalf("l.input failed")
	}
	if l.GetOffset() != 1 {
		t.Fatalf("l.readOffset failed != 1")
	}
	if l.GetCh() != 'p' {
		t.Fatalf("l.readOffset failed != p")
	}
}
Exemple #2
0
func TestConsume(t *testing.T) {
	s := "package นี้"
	l := new(compiler.Lexer).Init(s)
	if l.GetInput() != "package นี้" {
		t.Fatalf("l.input failed")
	}

	str := utf8.NewString(s)
	for i := 0; i < str.RuneCount(); i++ {
		if l.GetOffset() != i+1 {
			t.Fatalf("l.readOffset failed != " + strconv.Itoa(i+1))
		}
		if l.GetCh() != str.At(i) {
			t.Fatalf("ch " + strconv.Itoa(l.GetCh()) + " != at " + strconv.Itoa(str.At(i)))
		}
		l.Consume()
	}
	if l.GetCh() != compiler.EOF {
		t.Fatalf("EOF not found")
	}
}