Skip to content

Commit

Permalink
Merge pull request #2 from svanharmelen/master
Browse files Browse the repository at this point in the history
Fixed a small bug and added some tests
  • Loading branch information
Sander van Harmelen committed Aug 15, 2014
2 parents c26c3c7 + 643fbc0 commit 1df22d1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
49 changes: 49 additions & 0 deletions chefignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright 2014, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package pathspec

import (
"bytes"
"strings"
"testing"
)

func TestChefIgnore(t *testing.T) {
files_to_include := []string{"foo", "~foo", "foo.txt", "foo/bar.txt", "foo/bar"}
files_to_ignore := []string{"foo~", "foo/bar.txt~", "foo/bar/foo.txt.swp", "foo.txt.bak", "test/foo.test", "test/foo/bar.test", "foo/bar_flymake.el"}
content := []byte("*~\n*.sw[a-z]\n*.b?k\ntest*\n*_flymake.*\nfoo/b[^a]r")

for _, f := range files_to_include {
match, err := ChefIgnore(bytes.NewReader(content), f)
if err != nil {
t.Fatalf("Received an unexpected error: %s", err)
}
if match {
t.Errorf("ChefIgnore('%s', %s) returned '%v', want 'false'", strings.Replace(string(content), "\n", ", ", -1), f, match)
}
}

for _, f := range files_to_ignore {
match, err := ChefIgnore(bytes.NewReader(content), f)
if err != nil {
t.Fatalf("Received an unexpected error: %s", err)
}
if !match {
t.Errorf("ChefIgnore('%s', %s) returned '%v', want 'true'", strings.Replace(string(content), "\n", ", ", -1), f, match)
}
}
}
2 changes: 1 addition & 1 deletion gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,5 @@ func translateBraketExpression(i *int, glob string) string {
// braket literal instead of as an expression.
regex = regexp.QuoteMeta(string(glob[*i]))
}
return regex
return "[" + regex + "]"
}
49 changes: 49 additions & 0 deletions gitignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright 2014, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package pathspec

import (
"bytes"
"strings"
"testing"
)

func TestGitIgnore(t *testing.T) {
files_to_include := []string{"!.#test", "~foo", "foo/foo.txt", "bar/foobar.txt", "foo/bar.txt", "/bar/foo"}
files_to_ignore := []string{".#test", "foo/#test#", "foo/bar/.foo.txt.swp", "foo/foobar/foobar.txt", "foo.txt", "test/foo.test", "test/foo/bar.test", "foo/bar", "foo/1/2/bar"}
content := []byte(".#*\n\\#*#\n.*.sw[a-z]\n**/foobar/foobar.txt\n/foo.txt\ntest/\nfoo/**/bar\n/b[^a]r/foo")

for _, f := range files_to_include {
match, err := GitIgnore(bytes.NewReader(content), f)
if err != nil {
t.Fatalf("Received an unexpected error: %s", err)
}
if match {
t.Errorf("ChefIgnore('%s', %s) returned '%v', want 'false'", strings.Replace(string(content), "\n", ", ", -1), f, match)
}
}

for _, f := range files_to_ignore {
match, err := GitIgnore(bytes.NewReader(content), f)
if err != nil {
t.Fatalf("Received an unexpected error: %s", err)
}
if !match {
t.Errorf("ChefIgnore('%s', %s) returned '%v', want 'true'", strings.Replace(string(content), "\n", ", ", -1), f, match)
}
}
}

0 comments on commit 1df22d1

Please sign in to comment.