(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestLexicallyStripRoot(t *testing.T) { |
| 88 | for _, test := range []struct { |
| 89 | root, path, out string |
| 90 | }{ |
| 91 | // Works with multiple components. |
| 92 | {"/a/b", "/a/b/c", "/c"}, |
| 93 | {"/hello/world", "/hello/world/the/quick-brown/fox", "/the/quick-brown/fox"}, |
| 94 | // '/' must be a no-op. |
| 95 | {"/", "/a/b/c", "/a/b/c"}, |
| 96 | // Must be the correct order. |
| 97 | {"/a/b", "/a/c/b", "/a/c/b"}, |
| 98 | // Must be at start. |
| 99 | {"/abc/def", "/foo/abc/def/bar", "/foo/abc/def/bar"}, |
| 100 | // Must be a lexical parent. |
| 101 | {"/foo/bar", "/foo/barSAMECOMPONENT", "/foo/barSAMECOMPONENT"}, |
| 102 | // Must only strip the root once. |
| 103 | {"/foo/bar", "/foo/bar/foo/bar/baz", "/foo/bar/baz"}, |
| 104 | // Deal with .. in a fairly sane way. |
| 105 | {"/foo/bar", "/foo/bar/../baz", "/foo/baz"}, |
| 106 | {"/foo/bar", "../../../../../../foo/bar/baz", "/baz"}, |
| 107 | {"/foo/bar", "/../../../../../../foo/bar/baz", "/baz"}, |
| 108 | {"/foo/bar/../baz", "/foo/baz/bar", "/bar"}, |
| 109 | {"/foo/bar/../baz", "/foo/baz/../bar/../baz/./foo", "/foo"}, |
| 110 | // All paths are made absolute before stripping. |
| 111 | {"foo/bar", "/foo/bar/baz/bee", "/baz/bee"}, |
| 112 | {"/foo/bar", "foo/bar/baz/beef", "/baz/beef"}, |
| 113 | {"foo/bar", "foo/bar/baz/beets", "/baz/beets"}, |
| 114 | } { |
| 115 | got := LexicallyStripRoot(test.root, test.path) |
| 116 | if got != test.out { |
| 117 | t.Errorf("LexicallyStripRoot(%q, %q) -- got %q, expected %q", test.root, test.path, got, test.out) |
| 118 | } |
| 119 | } |
| 120 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…