util_test.go 988 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package pagebuilder
  2. import (
  3. "testing"
  4. "github.com/google/go-cmp/cmp"
  5. )
  6. func TestFillCategoryIndentLevels(t *testing.T) {
  7. for _, c := range []struct {
  8. name string
  9. cats []*Category
  10. expect []*Category
  11. }{
  12. {
  13. name: "",
  14. cats: []*Category{
  15. {
  16. Path: "/",
  17. },
  18. {
  19. Path: "/a",
  20. },
  21. {
  22. Path: "/a/b",
  23. },
  24. {
  25. Path: "/a/b/c",
  26. },
  27. {
  28. Path: "/a/bb",
  29. },
  30. {
  31. Path: "/a/c",
  32. },
  33. },
  34. expect: []*Category{
  35. {
  36. Path: "/",
  37. IndentLevel: 0,
  38. },
  39. {
  40. Path: "/a",
  41. IndentLevel: 0,
  42. },
  43. {
  44. Path: "/a/b",
  45. IndentLevel: 1,
  46. },
  47. {
  48. Path: "/a/b/c",
  49. IndentLevel: 2,
  50. },
  51. {
  52. Path: "/a/bb",
  53. IndentLevel: 1,
  54. },
  55. {
  56. Path: "/a/c",
  57. IndentLevel: 1,
  58. },
  59. },
  60. },
  61. } {
  62. fillCategoryIndentLevels(c.cats)
  63. if diff := cmp.Diff(c.expect, c.cats); diff != "" {
  64. t.Fatalf("%s: %s\n", c.name, diff)
  65. }
  66. }
  67. }