|
| 1 | +package project |
| 2 | + |
| 3 | +import ( |
| 4 | + "path/filepath" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func testStartsWithAnyOf(t *testing.T, path string, prefix string, expectation bool) { |
| 9 | + result := startsWithAnyOf(path, []string{prefix}) |
| 10 | + if result != expectation { |
| 11 | + t.Errorf("Expected startsWithAnyOf(%s, %s) to be %t, but it is %t.", path, prefix, expectation, result) |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +func TestStartsWithAnyOf(t *testing.T) { |
| 16 | + testStartsWithAnyOf(t, ".", ".", true) |
| 17 | + testStartsWithAnyOf(t, ".", "dir", true) |
| 18 | + testStartsWithAnyOf(t, ".", filepath.Join("foo", "bar"), true) |
| 19 | + testStartsWithAnyOf(t, "dir", "dir", true) |
| 20 | + testStartsWithAnyOf(t, "foo", filepath.Join("foo", "bar"), true) |
| 21 | + testStartsWithAnyOf(t, filepath.Join("foo", "bar"), filepath.Join("foo", "bar"), true) |
| 22 | + testStartsWithAnyOf(t, filepath.Join("foo", "bar"), filepath.Join("foo", "bar", "baz"), true) |
| 23 | + |
| 24 | + testStartsWithAnyOf(t, filepath.Join("foo", "bar"), "foo", false) |
| 25 | + testStartsWithAnyOf(t, filepath.Join("foo", "bar"), "bar", false) |
| 26 | + testStartsWithAnyOf(t, filepath.Join("foo", "bar"), filepath.Join("foo", "baz"), false) |
| 27 | +} |
0 commit comments