From 1b9571846007270034b4f04beb98e3e4efa641f5 Mon Sep 17 00:00:00 2001
From: Nick Craig-Wood <nick@craig-wood.com>
Date: Tue, 20 Oct 2015 09:16:47 +0100
Subject: [PATCH] Fix typos in filter docs and unit test assertions

---
 docs/content/filtering.md |  4 +--
 fs/filter_test.go         | 53 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/docs/content/filtering.md b/docs/content/filtering.md
index 1257cfe2c..9b0491cc3 100644
--- a/docs/content/filtering.md
+++ b/docs/content/filtering.md
@@ -40,7 +40,7 @@ A `*` matches anything but not a `/`.
 
     *.jpg  - matches "file.jpg"
            - matches "directory/file.jpg"
-           - doesn't match "file.jpg/anotherfile.jpg"
+           - doesn't match "file.jpg/anotherfile.png"
 
 Use `**` to match anything, including slashes.
 
@@ -76,7 +76,7 @@ Special characters can be escaped with a `\` before them.
 
     \*.jpg       - matches "*.jpg"
     \\.jpg       - matches "\.jpg"
-    \[one\].jpeg - matches "[one].jpg"
+    \[one\].jpg  - matches "[one].jpg"
   
 ### Differences between rsync and rclone patterns ###
 
diff --git a/fs/filter_test.go b/fs/filter_test.go
index bb469f7b9..265c2ce95 100644
--- a/fs/filter_test.go
+++ b/fs/filter_test.go
@@ -250,3 +250,56 @@ five
 		t.Errorf("want %q got %q", want, got)
 	}
 }
+
+func TestFilterMatchesFromDocs(t *testing.T) {
+	for _, test := range []struct {
+		glob     string
+		included bool
+		file     string
+	}{
+		{"file.jpg", true, "file.jpg"},
+		{"file.jpg", true, "directory/file.jpg"},
+		{"file.jpg", false, "afile.jpg"},
+		{"file.jpg", false, "directory/afile.jpg"},
+		{"/file.jpg", true, "file.jpg"},
+		{"/file.jpg", false, "afile.jpg"},
+		{"/file.jpg", false, "directory/file.jpg"},
+		{"*.jpg", true, "file.jpg"},
+		{"*.jpg", true, "directory/file.jpg"},
+		{"*.jpg", false, "file.jpg/anotherfile.png"},
+		{"dir/**", true, "dir/file.jpg"},
+		{"dir/**", true, "dir/dir1/dir2/file.jpg"},
+		{"dir/**", false, "directory/file.jpg"},
+		{"dir/**", false, "adir/file.jpg"},
+		{"l?ss", true, "less"},
+		{"l?ss", true, "lass"},
+		{"l?ss", false, "floss"},
+		{"h[ae]llo", true, "hello"},
+		{"h[ae]llo", true, "hallo"},
+		{"h[ae]llo", false, "hullo"},
+		{"{one,two}_potato", true, "one_potato"},
+		{"{one,two}_potato", true, "two_potato"},
+		{"{one,two}_potato", false, "three_potato"},
+		{"{one,two}_potato", false, "_potato"},
+		{"\\*.jpg", true, "*.jpg"},
+		{"\\\\.jpg", true, "\\.jpg"},
+		{"\\[one\\].jpg", true, "[one].jpg"},
+	} {
+		f, err := NewFilter()
+		if err != nil {
+			t.Fatal(err)
+		}
+		err = f.Add(true, test.glob)
+		if err != nil {
+			t.Fatal(err)
+		}
+		err = f.Add(false, "*")
+		if err != nil {
+			t.Fatal(err)
+		}
+		included := f.Include(test.file, 0)
+		if included != test.included {
+			t.Logf("%q match %q: want %v got %v", test.glob, test.file, test.included, included)
+		}
+	}
+}