You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.2 KiB

6 months ago
6 months ago
6 months ago
  1. package filer_ui
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestToBreadcrumb(t *testing.T) {
  7. type args struct {
  8. fullpath string
  9. }
  10. tests := []struct {
  11. name string
  12. args args
  13. wantCrumbs []Breadcrumb
  14. }{
  15. {
  16. name: "empty",
  17. args: args{
  18. fullpath: "",
  19. },
  20. wantCrumbs: []Breadcrumb{
  21. {
  22. Name: "/",
  23. Link: "/",
  24. },
  25. },
  26. },
  27. {
  28. name: "test1",
  29. args: args{
  30. fullpath: "/",
  31. },
  32. wantCrumbs: []Breadcrumb{
  33. {
  34. Name: "/",
  35. Link: "/",
  36. },
  37. },
  38. },
  39. {
  40. name: "test2",
  41. args: args{
  42. fullpath: "/abc",
  43. },
  44. wantCrumbs: []Breadcrumb{
  45. {
  46. Name: "/",
  47. Link: "/",
  48. },
  49. {
  50. Name: "abc",
  51. Link: "/abc/",
  52. },
  53. },
  54. },
  55. {
  56. name: "test3",
  57. args: args{
  58. fullpath: "/abc/def",
  59. },
  60. wantCrumbs: []Breadcrumb{
  61. {
  62. Name: "/",
  63. Link: "/",
  64. },
  65. {
  66. Name: "abc",
  67. Link: "/abc/",
  68. },
  69. {
  70. Name: "def",
  71. Link: "/abc/def/",
  72. },
  73. },
  74. },
  75. }
  76. for _, tt := range tests {
  77. t.Run(tt.name, func(t *testing.T) {
  78. if gotCrumbs := ToBreadcrumb(tt.args.fullpath); !reflect.DeepEqual(gotCrumbs, tt.wantCrumbs) {
  79. t.Errorf("ToBreadcrumb() = %v, want %v", gotCrumbs, tt.wantCrumbs)
  80. }
  81. })
  82. }
  83. }