Merge "veyron/lib/glob: Recursive matches are not exact matches."
diff --git a/lib/glob/glob.go b/lib/glob/glob.go
index a69be73..9551c7e 100644
--- a/lib/glob/glob.go
+++ b/lib/glob/glob.go
@@ -84,7 +84,8 @@
if !g.recursive {
return false, false, nil
}
- return true, true, g
+ // The segment matches "...". This is not an exact match.
+ return true, false, g
}
if matches, err := filepath.Match(g.elems[0], segment); err != nil {
@@ -100,7 +101,8 @@
// Returns:
// matched, a boolean indicating whether each element e_i of elems matches the
// (start + i)th element of the glob pattern;
-// exact, a boolean indicating whether elems matched a fixed string pattern;
+// exact, a boolean indicating whether elems matched a fixed string pattern.
+// <path> is considered an exact match for pattern <path>/...;
// remainder, a Glob representing the unmatched remainder of g. remainder will
// be empty if the pattern is completely matched.
//
diff --git a/lib/glob/glob_test.go b/lib/glob/glob_test.go
index 785a1eb..0e43baf 100644
--- a/lib/glob/glob_test.go
+++ b/lib/glob/glob_test.go
@@ -46,6 +46,11 @@
matched bool
exact bool
}{
+ // Test recursive.
+ {"...", []string{}, true, true},
+ {"...", []string{"a"}, true, false},
+ {"a/...", []string{"a"}, true, true},
+ {"a/...", []string{"a", "b"}, true, false},
// Test one element, fixed.
{"a", []string{"a"}, true, true},
{"a", []string{"b"}, false, false},
@@ -93,7 +98,7 @@
}
matched, exact, _ := g.PartialMatch(0, test.elems)
if matched != test.matched || exact != test.exact {
- t.Fatalf("%v.PartialMatch(0, %v) got (%v, %v), expected (%v, %v)",
+ t.Fatalf("'%v'.PartialMatch(0, '%v') got (%v, %v), expected (%v, %v)",
test.pattern, test.elems, matched, exact, test.matched, test.exact)
}
}