Esempio n. 1
0
func TestToken(t *testing.T) {
	l := new(compiler.Lexer).Init("package")
	tok := l.NextToken()
	// fmt.Printf("%s\n", tok)
	if tok.GetTokenType() != compiler.PACKAGE {
		t.Fatalf("Fail : PACKAGE not found")
	}
}
Esempio n. 2
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")
	}
}
Esempio n. 3
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")
	}
}