breadcrumb_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: "test1",
  17. args: args{
  18. fullpath: "/",
  19. },
  20. wantCrumbs: []Breadcrumb{
  21. {
  22. Name: "/",
  23. Link: "/",
  24. },
  25. },
  26. },
  27. {
  28. name: "test2",
  29. args: args{
  30. fullpath: "/abc",
  31. },
  32. wantCrumbs: []Breadcrumb{
  33. {
  34. Name: "/",
  35. Link: "/",
  36. },
  37. {
  38. Name: "abc",
  39. Link: "/abc/",
  40. },
  41. },
  42. },
  43. {
  44. name: "test3",
  45. args: args{
  46. fullpath: "/abc/def",
  47. },
  48. wantCrumbs: []Breadcrumb{
  49. {
  50. Name: "/",
  51. Link: "/",
  52. },
  53. {
  54. Name: "abc",
  55. Link: "/abc/",
  56. },
  57. {
  58. Name: "def",
  59. Link: "/abc/def/",
  60. },
  61. },
  62. },
  63. }
  64. for _, tt := range tests {
  65. t.Run(tt.name, func(t *testing.T) {
  66. if gotCrumbs := ToBreadcrumb(tt.args.fullpath); !reflect.DeepEqual(gotCrumbs, tt.wantCrumbs) {
  67. t.Errorf("ToBreadcrumb() = %v, want %v", gotCrumbs, tt.wantCrumbs)
  68. }
  69. })
  70. }
  71. }