tomllint_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package tomllint
  2. import (
  3. "bytes"
  4. "strings"
  5. "testing"
  6. )
  7. func TestSyntaxError(t *testing.T) {
  8. lint := &tomllint{}
  9. r := bytes.NewBufferString(synataxerrordata)
  10. lintErr := lint.Lint(r)
  11. if lintErr == nil {
  12. t.Fatalf("expect lintErr != nil")
  13. }
  14. if lintErr[0].Line == -1 {
  15. t.Errorf("expect get line number")
  16. }
  17. }
  18. func TestTomlLintOK(t *testing.T) {
  19. lint := &tomllint{}
  20. r := bytes.NewBufferString(normaldata)
  21. lintErr := lint.Lint(r)
  22. if lintErr != nil {
  23. t.Errorf("error %v", lintErr)
  24. }
  25. }
  26. func TestNoCommon(t *testing.T) {
  27. lint := &tomllint{}
  28. r := bytes.NewBufferString(nocommondata)
  29. lintErr := lint.Lint(r)
  30. if lintErr == nil {
  31. t.Fatalf("expect lintErr != nil")
  32. }
  33. message := lintErr.Error()
  34. if !strings.Contains(message, "Common") {
  35. t.Errorf("expect error contains common")
  36. }
  37. }
  38. func TestNoIdentify(t *testing.T) {
  39. lint := &tomllint{}
  40. r := bytes.NewBufferString(noidentify)
  41. lintErr := lint.Lint(r)
  42. if lintErr == nil {
  43. t.Fatalf("expect lintErr != nil")
  44. }
  45. message := lintErr.Error()
  46. if !strings.Contains(message, "Identify") {
  47. t.Errorf("expect error Identify common")
  48. }
  49. }
  50. func TestNoApp(t *testing.T) {
  51. lint := &tomllint{}
  52. r := bytes.NewBufferString(noapp)
  53. lintErr := lint.Lint(r)
  54. if lintErr == nil {
  55. t.Fatalf("expect lintErr != nil")
  56. }
  57. message := lintErr.Error()
  58. if !strings.Contains(message, "App") {
  59. t.Errorf("expect error App common")
  60. }
  61. }