parse_test.go 983 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package toml
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. var testParseSmall = `
  7. # This is a TOML document. Boom.
  8. wat = "chipper"
  9. [owner.andrew.gallant]
  10. hmm = "hi"
  11. [owner] # Whoa there.
  12. andreW = "gallant # poopy" # weeeee
  13. predicate = false
  14. num = -5192
  15. f = -0.5192
  16. zulu = 1979-05-27T07:32:00Z
  17. whoop = "poop"
  18. tests = [ [1, 2, 3], ["abc", "xyz"] ]
  19. arrs = [ # hmm
  20. # more comments are awesome.
  21. 1987-07-05T05:45:00Z,
  22. # say wat?
  23. 1987-07-05T05:45:00Z,
  24. 1987-07-05T05:45:00Z,
  25. # sweetness
  26. ] # more comments
  27. # hehe
  28. `
  29. var testParseSmall2 = `
  30. [a]
  31. better = 43
  32. [a.b.c]
  33. answer = 42
  34. `
  35. func TestParse(t *testing.T) {
  36. m, err := parse(testParseSmall)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. printMap(m.mapping, 0)
  41. }
  42. func printMap(m map[string]interface{}, depth int) {
  43. for k, v := range m {
  44. testf("%s%s\n", strings.Repeat(" ", depth), k)
  45. switch subm := v.(type) {
  46. case map[string]interface{}:
  47. printMap(subm, depth+1)
  48. default:
  49. testf("%s%v\n", strings.Repeat(" ", depth+1), v)
  50. }
  51. }
  52. }