Skip to content

Commit

Permalink
refactor: release stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
maolonglong committed May 31, 2023
1 parent ff83277 commit ea2e558
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
linters:
enable:
- asciicheck
- depguard
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- goimports
- gosec
- misspell
- nakedret
- nilerr
- nolintlint
- revive
- wastedassign
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module go.chensl.me/redglob

go 1.20

retract v0.2.0
2 changes: 1 addition & 1 deletion internal/cgo_stringmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ int stringmatch(const char *pattern, const char *string, int nocase) {
*/
import "C"

func CGO_stringmatch(str, pattern string) bool {
func OriginStringMatch(str, pattern string) bool {
return int(C.stringmatch(C.CString(pattern), C.CString(str), C.int(0))) == 1
}
27 changes: 27 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
alias t := test
alias c := check

default:
just --list

# install dev tools
deps:
go install github.com/segmentio/golines@latest
go install mvdan.cc/gofumpt@latest
go install github.com/rinchsan/gosimports/cmd/gosimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

fmt:
golines --max-len=99 --base-formatter="gofumpt -extra" -w .
gosimports -local go.chensl.me -w .

fuzz:
go test -fuzz=Fuzz .

test:
go test -v -race -count=1 ./...

lint:
golangci-lint run

check: fmt lint test
10 changes: 4 additions & 6 deletions match.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func MatchBytesFold(b []byte, pattern string) bool {

func stringmatch(str, pattern string, nocase bool) bool {
skipLongerMatches := false
return stringmatch_impl(str, pattern, nocase, &skipLongerMatches)
return stringmatchImpl(str, pattern, nocase, &skipLongerMatches)
}

func stringmatch_impl(str, pattern string, nocase bool, skipLongerMatches *bool) bool {
func stringmatchImpl(str, pattern string, nocase bool, skipLongerMatches *bool) bool {
for len(pattern) > 0 {
pc, ps := decodeRune(pattern)
var sc rune
Expand All @@ -86,7 +86,7 @@ func stringmatch_impl(str, pattern string, nocase bool, skipLongerMatches *bool)
return true
}
for len(str) > 0 {
if stringmatch_impl(str, pattern[1:], nocase, skipLongerMatches) {
if stringmatchImpl(str, pattern[1:], nocase, skipLongerMatches) {
return true
}
if *skipLongerMatches {
Expand Down Expand Up @@ -139,9 +139,7 @@ func stringmatch_impl(str, pattern string, nocase bool, skipLongerMatches *bool)
end := pc
c := sc
if start > end {
tmp := start
start = end
end = tmp
start, end = end, start
}
if nocase {
start = unicode.ToLower(start)
Expand Down
2 changes: 1 addition & 1 deletion match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func FuzzMatch(f *testing.F) {
return
}
got := Match(str, pattern)
want := internal.CGO_stringmatch(str, pattern)
want := internal.OriginStringMatch(str, pattern)
if got != want {
t.Errorf("Match(%q, %q) = %v, want %v", str, pattern, got, want)
}
Expand Down
14 changes: 6 additions & 8 deletions tidwall_match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package redglob

import (
"math/rand"
"crypto/rand"
"strings"
"testing"
"time"
)

func TestMatch_tidwall(t *testing.T) {
Expand Down Expand Up @@ -388,14 +387,13 @@ func TestWildcardMatch_tidwall(t *testing.T) {
}

func TestRandomInput_tidwall(t *testing.T) {
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
b1 := make([]byte, 100)
b2 := make([]byte, 100)
for i := 0; i < 1000000; i++ {
if _, err := rnd.Read(b1); err != nil {
if _, err := rand.Read(b1); err != nil {
t.Fatal(err)
}
if _, err := rnd.Read(b2); err != nil {
if _, err := rand.Read(b2); err != nil {
t.Fatal(err)
}
Match(string(b1), string(b2))
Expand All @@ -418,7 +416,7 @@ func BenchmarkUnicode(t *testing.B) {
}
}

func TestLotsaStars_tidwall(t *testing.T) {
func TestLotsaStars_tidwall(_ *testing.T) {
// This tests that a pattern with lots of stars will complete quickly.
var str, pat string

Expand All @@ -427,8 +425,8 @@ func TestLotsaStars_tidwall(t *testing.T) {
`**,**,"",**,**,**,**,**,**,**,**,**,**]`
Match(pat, str)

str = strings.Replace(str, ",", "情", -1)
pat = strings.Replace(pat, ",", "情", -1)
str = strings.ReplaceAll(str, ",", "情")
pat = strings.ReplaceAll(pat, ",", "情")
Match(pat, str)

str = strings.Repeat("hello", 100)
Expand Down

0 comments on commit ea2e558

Please sign in to comment.