lexer_test.go 778 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package muesli
  2. import (
  3. _ "strings"
  4. "testing"
  5. )
  6. func LexText(input string) []Token {
  7. lexer := NewLexerFromInputString(input)
  8. tokens := lexer.LexAll()
  9. return tokens
  10. }
  11. func Assert(test *testing.T, ok bool, text string) bool {
  12. if !ok {
  13. test.Errorf(text)
  14. }
  15. return ok
  16. }
  17. func HelperTryLexText(input string, test * testing.T) {
  18. tokens := LexText(input)
  19. for i:= 0; i < len(tokens) ; i++ {
  20. test.Logf("%d: %s", i, tokens[i].String())
  21. }
  22. }
  23. func TestLexing(test *testing.T) {
  24. const input = `
  25. greet "hi there"
  26. say "hello \"world\\"
  27. define open a door {
  28. set (door open) true
  29. }
  30. def increment variable by value {
  31. =variable (add variable $value)
  32. }
  33. `
  34. test.Log("Hi test!")
  35. HelperTryLexText(input, test)
  36. }