lex_test.go 813 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package toml
  2. import (
  3. "log"
  4. "testing"
  5. )
  6. func init() {
  7. log.SetFlags(0)
  8. }
  9. var testSmall = `
  10. # This is a TOML document. Boom.
  11. [owner]
  12. [owner] # Whoa there.
  13. andrew = "gallant # poopy" # weeeee
  14. predicate = false
  15. num = -5192
  16. f = -0.5192
  17. zulu = 1979-05-27T07:32:00Z
  18. whoop = "poop"
  19. arrs = [
  20. 1987-07-05T05:45:00Z,
  21. 5,
  22. "wat?",
  23. "hehe \n\r kewl",
  24. [6], [],
  25. 5.0,
  26. # sweetness
  27. ] # more comments
  28. # hehe
  29. `
  30. var testSmaller = `
  31. [a.b] # Do you ignore me?
  32. andrew = "ga# ll\"ant" # what about me?
  33. kait = "brady"
  34. awesomeness = true
  35. pi = 3.14
  36. dob = 1987-07-05T17:45:00Z
  37. perfection = [
  38. [6, 28],
  39. [496, 8128]
  40. ]
  41. `
  42. func TestLexer(t *testing.T) {
  43. lx := lex(testSmaller)
  44. for {
  45. item := lx.nextItem()
  46. if item.typ == itemEOF {
  47. break
  48. } else if item.typ == itemError {
  49. t.Fatal(item.val)
  50. }
  51. testf("%s\n", item)
  52. }
  53. }