Skip to content

Commit

Permalink
fix #36. wrong skip checks in Squeeze
Browse files Browse the repository at this point in the history
  • Loading branch information
huandu committed Feb 14, 2018
1 parent 2a6a9f9 commit 2bf18b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,9 @@ func Count(str, pattern string) int {
// If pattern is not empty, only runes matching the pattern will be squeezed.
//
// Samples:
// Squeeze("hello", "") => "helo"
// Squeeze("hello", "m-z") => "hello"
// Squeeze("hello", "") => "helo"
// Squeeze("hello", "m-z") => "hello"
// Squeeze("hello world", " ") => "hello world"
func Squeeze(str, pattern string) string {
var last, r rune
var size int
Expand Down Expand Up @@ -532,6 +533,7 @@ func Squeeze(str, pattern string) string {
}

last = r
skipSqueeze = false
}

str = str[size:]
Expand Down
12 changes: 8 additions & 4 deletions translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ func TestSqueeze(t *testing.T) {
}

runTestCases(t, runner, _M{
sep("hello", ""): "helo",
sep("hello", "a-k"): "hello",
sep("hello", "^a-k"): "helo",
sep("hello", "^a-l"): "hello",
sep("hello", ""): "helo",
sep("hello world", ""): "helo world",
sep("hello world", " "): "hello world",
sep("hello world", " "): "hello world",
sep("hello", "a-k"): "hello",
sep("hello", "^a-k"): "helo",
sep("hello", "^a-l"): "hello",
sep("foooo baaaaar", "a"): "foooo bar",

sep("打打打打个劫!!", ""): "打个劫!",
sep("打打打打个劫!!", "打"): "打个劫!!",
Expand Down

0 comments on commit 2bf18b2

Please sign in to comment.