diff --git a/.github/workflows/gosec.yml b/.github/workflows/gosec.yml old mode 100644 new mode 100755 index c46d69a..05c09ae --- a/.github/workflows/gosec.yml +++ b/.github/workflows/gosec.yml @@ -8,12 +8,11 @@ on: jobs: tests: runs-on: ubuntu-latest - env: - GO111MODULE: on + permissions: + security-events: write steps: - name: Checkout Source uses: actions/checkout@v4 - - name: Run Gosec Security Scanner uses: securego/gosec@master with: diff --git a/.github/workflows/test-matrix.yml b/.github/workflows/test-matrix.yml new file mode 100755 index 0000000..d3c670f --- /dev/null +++ b/.github/workflows/test-matrix.yml @@ -0,0 +1,49 @@ +name: Matrix tests + +on: + push: + pull_request: + +jobs: + test-matrix: + runs-on: ubuntu-latest + + strategy: + matrix: + go: ["1.22.x", "stable"] + continueOnError: [false] +# include: +# - go: ">=1.23.0-rc.1" +# continueOnError: true + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + check-latest: true + + - run: make go-all-tests + + - name: Test Summary + uses: test-summary/action@v2 + with: + paths: "junit-report.xml" + if: always() + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: "junit-report.xml" + verbose: true + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage-unit.out + verbose: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml old mode 100644 new mode 100755 index 285a069..9d6e771 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test +name: Tests on: push: @@ -10,17 +10,25 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: asdf-vm/actions/install@v3 + - uses: actions/setup-go@v5 + with: + go-version: 'stable' - run: go mod tidy && git diff --exit-code go.mod go.sum - test-asdf: + tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Install asdf & tools - uses: asdf-vm/actions/install@v3 + - uses: actions/setup-go@v5 + with: + go-version: 'stable' + check-latest: true + + - run: make go-dependencies + + - run: make go-generate && git diff --exit-code - run: make go-all-tests @@ -30,36 +38,18 @@ jobs: paths: "junit-report.xml" if: always() - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - files: ./.coverage.out - - test-matrix: - runs-on: ubuntu-latest - - strategy: - matrix: - go: ["1.21.x"] - continueOnError: [false] - include: - - go: ">=1.22.0-rc.1" - continueOnError: true - - steps: - - uses: actions/checkout@v4 + files: "junit-report.xml" + verbose: true - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go }} - check-latest: true - - - run: make go-all-tests - - - name: Test Summary - uses: test-summary/action@v2 + - name: Upload coverage reports to Codecov + if: ${{ !cancelled() }} + uses: codecov/codecov-action@v4 with: - paths: "junit-report.xml" - if: always() + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage-unit.out + verbose: true diff --git a/.gitignore b/.gitignore index c12e565..432f89d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ tmp.* # Go -.coverage.out -.coverage-*.out +coverage-*.* +ginkgo-coverage-*.* junit-report.xml # IntelliJ IDEs diff --git a/.golangci.yml b/.golangci.yml old mode 100644 new mode 100755 index 0ef76f2..6958d31 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ #file: noinspection SpellCheckingInspection run: concurrency: 4 + modules-download-mode: readonly # https://golangci-lint.run/usage/configuration/#linters-configuration linters: @@ -12,7 +13,6 @@ linters: - ineffassign - staticcheck - unused - - unused - asasalint - bodyclose - containedctx @@ -27,16 +27,19 @@ linters: - funlen - gocritic - gocyclo - - goerr113 + - err113 - goimports - - gomnd + - mnd - gomoddirectives - gosec + - govet + - grouper - misspell - nilerr - nlreturn - noctx - prealloc + - predeclared - promlinter - revive - wastedassign @@ -52,7 +55,9 @@ linters: - wrapcheck - wsl - ginkgolinter -# - interfacebloat + - interfacebloat + - sloglint + - nilnil linters-settings: varnamelen: @@ -60,3 +65,8 @@ linters-settings: ignore-map-index-ok: true ignore-names: - l + govet: + enable-all: true + nolintlint: + require-explanation: true + require-specific: true diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 98756a6..0000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -golang 1.21.6 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index ca9ddb0..3525342 --- a/Makefile +++ b/Makefile @@ -1,38 +1,24 @@ -go-dependencies: - # https://asdf-vm.com/ - asdf install golang || : +go-all: go-update go-generate go-all-tests +go-all-tests: go-lint go-unit-tests - # https://github.com/securego/gosec - go install github.com/securego/gosec/v2/cmd/gosec@latest - go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest - # - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - go install github.com/nunnatsa/ginkgolinter/cmd/ginkgolinter@latest +go-dependencies: + $(eval GOBIN=$(shell go env GOPATH 2>/dev/null)/bin) + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) latest # go install github.com/onsi/ginkgo/v2/ginkgo@latest - # - go install github.com/vektra/mockery/v2@latest - # - asdf reshim golang || : - # - go get -u -t -v ./... || : -go-generate: go-dependencies - #mockery +go-update: go-dependencies + go mod tidy && go get -t -v -u ./... + +go-generate: go generate ./... -go-lint: go-dependencies +go-lint: golangci-lint run - ginkgolinter ./... - go vet -vettool=$$(go env GOPATH)/bin/shadow ./... - -go-test: go-lint - gosec ./... - ginkgo -r -race --cover --coverprofile=.coverage-ginkgo.out --junit-report=junit-report.xml ./... - go tool cover -func=.coverage-ginkgo.out -o=.coverage.out - cat .coverage.out -go-all-tests: go-dependencies go-generate go-lint go-test +go-unit-tests: + ginkgo -race --cover --coverprofile="ginkgo-coverage-unit.out" --junit-report="junit-report.xml" ./... + go tool cover -func "ginkgo-coverage-unit.out" -o "coverage-unit.out" + go tool cover -html "ginkgo-coverage-unit.out" -o "coverage-unit.html" -go-all: go-all-tests - go mod tidy || : + cat coverage-unit.out diff --git a/README.adoc b/README.adoc index 1e186e0..1305ef8 100644 --- a/README.adoc +++ b/README.adoc @@ -17,16 +17,44 @@ https://goreportcard.com/report/github.com/itbasis/go-hashtag[image:https://gore go get -u github.com/itbasis/go-hashtag@latest ``` -== Example +== Examples +Case-insensitive: [source,go] -``` +---- package main -import "github.com/itbasis/go-hashtag" +import ( + "fmt" + + "github.com/itbasis/go-hashtag" +) + +func main() { + text := "An example of a text with a #hashtag #another #Another" + hashTags := hashtag.NewParser(false).Parse(text) + fmt.Println(hashTags) -func func main() { - text := "An example of a text with a #hashtag" - hashTags := NewParser(false).Parse(text) + // Output: ["hashtag": 1, "another": 2] } -``` +---- + +Case-sensitive: +[source,go] +---- +package main + +import ( + "fmt" + + "github.com/itbasis/go-hashtag" +) + +func main() { + text := "An example of a text with a #hashtag #another #Another" + hashTags := hashtag.NewParser(true).Parse(text) + fmt.Println(hashTags) + + // Output: ["hashtag": 1, "another": 1, "Another": 1] +} +---- diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 index 052e459..236a58d --- a/go.mod +++ b/go.mod @@ -1,25 +1,26 @@ module github.com/itbasis/go-hashtag -go 1.21 +go 1.22 require ( - github.com/onsi/ginkgo/v2 v2.15.0 - github.com/onsi/gomega v1.31.1 + github.com/itbasis/go-test-utils/v4 v4.0.0 + github.com/onsi/ginkgo/v2 v2.20.0 + github.com/onsi/gomega v1.34.1 ) require ( - github.com/go-logr/logr v1.4.1 // indirect - github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect + github.com/dusted-go/logging v1.3.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/pprof v0.0.0-20240125082051-42cd04596328 // indirect - github.com/kr/pretty v0.3.1 // indirect + github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect + github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.17.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + golang.org/x/tools v0.24.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 index 73a9cda..cbc5d55 --- a/go.sum +++ b/go.sum @@ -1,19 +1,18 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/dusted-go/logging v1.3.0 h1:SL/EH1Rp27oJQIte+LjWvWACSnYDTqNx5gZULin0XRY= +github.com/dusted-go/logging v1.3.0/go.mod h1:s58+s64zE5fxSWWZfp+b8ZV0CHyKHjamITGyuY1wzGg= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20240125082051-42cd04596328 h1:oI+lCI2DY1BsRrdzMJBhIMxBBdlZJl31YNQC11EiyvA= -github.com/google/pprof v0.0.0-20240125082051-42cd04596328/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k= +github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/itbasis/go-test-utils/v4 v4.0.0 h1:4rZ6O9lQglIqYNUIhT9WIllk+xN3KbmX9FrHHVjzW/U= +github.com/itbasis/go-test-utils/v4 v4.0.0/go.mod h1:8a8zTjbBfPoqVa7ER9p+aKk1SgZhBI2ymMqFLekycP8= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -21,35 +20,30 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= -github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= -github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= -github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/onsi/ginkgo/v2 v2.20.0 h1:PE84V2mHqoT1sglvHc8ZdQtPcwmvvt29WLEEO3xmdZw= +github.com/onsi/ginkgo/v2 v2.20.0/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI= +github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= +github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/parser.go b/parser.go index 144be7b..2650c77 100644 --- a/parser.go +++ b/parser.go @@ -11,9 +11,9 @@ const ( ) type Parser struct { - caseSensitive bool - re *regexp.Regexp + + caseSensitive bool } func NewParser(caseSensitive bool) *Parser { diff --git a/parser_suite_test.go b/parser_suite_test.go old mode 100644 new mode 100755 index 264401d..9b42776 --- a/parser_suite_test.go +++ b/parser_suite_test.go @@ -3,12 +3,9 @@ package hashtag_test import ( "testing" - "github.com/onsi/ginkgo/v2" - "github.com/onsi/gomega" + "github.com/itbasis/go-test-utils/v4/ginkgo" ) func TestParser(t *testing.T) { - gomega.RegisterFailHandler(ginkgo.Fail) - - ginkgo.RunSpecs(t, "HashTag Parser") + ginkgo.InitGinkgoSuite(t, "HashTag Parser") } diff --git a/parser_test.go b/parser_test.go old mode 100644 new mode 100755 index 8d5ca5f..9d98c23 --- a/parser_test.go +++ b/parser_test.go @@ -2,48 +2,48 @@ package hashtag_test import ( "github.com/itbasis/go-hashtag" - . "github.com/onsi/ginkgo/v2" //nolint:revive - . "github.com/onsi/gomega" //nolint:revive + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" ) -var _ = Describe( +var _ = ginkgo.Describe( "Parsing", func() { - DescribeTable( + ginkgo.DescribeTable( "no hashtags", func(text string, sensitivity bool) { - Ω(hashtag.NewParser(sensitivity).Parse(text)).To(BeNil()) + gomega.Ω(hashtag.NewParser(sensitivity).Parse(text)).To(gomega.BeNil()) }, - Entry(nil, "", false), - Entry(nil, "qw", false), - Entry(nil, "qw", true), - Entry(nil, "Qw", false), - Entry(nil, "Qw", true), - Entry(nil, "qw qw", false), - Entry(nil, "$qw", false), + ginkgo.Entry(nil, "", false), + ginkgo.Entry(nil, "qw", false), + ginkgo.Entry(nil, "qw", true), + ginkgo.Entry(nil, "Qw", false), + ginkgo.Entry(nil, "Qw", true), + ginkgo.Entry(nil, "qw qw", false), + ginkgo.Entry(nil, "$qw", false), ) - DescribeTable( + ginkgo.DescribeTable( "Success parsing", func(text string, sensitivity bool, want map[string]int) { parser := hashtag.NewParser(sensitivity) - Ω(parser.Parse(text)).To(Equal(want)) + gomega.Ω(parser.Parse(text)).To(gomega.Equal(want)) }, - Entry(nil, "#1qw2", false, map[string]int{"1qw2": 1}), - Entry(nil, "#12_", false, map[string]int{"12_": 1}), - Entry(nil, "#1_2", false, map[string]int{"1_2": 1}), - Entry(nil, "#12", false, map[string]int{"12": 1}), - Entry(nil, "#qw", false, map[string]int{"qw": 1}), - Entry(nil, "#qw #", false, map[string]int{"qw": 1}), - Entry(nil, " #qw", false, map[string]int{"qw": 1}), - Entry(nil, "#q1w", false, map[string]int{"q1w": 1}), - Entry(nil, "#q12w", false, map[string]int{"q12w": 1}), - Entry(nil, "#qw1", false, map[string]int{"qw1": 1}), - Entry(nil, "#qw12", false, map[string]int{"qw12": 1}), - Entry(nil, "#qw$", false, map[string]int{"qw": 1}), - Entry(nil, "#qw qw", false, map[string]int{"qw": 1}), - Entry(nil, "#qw #qw", false, map[string]int{"qw": 2}), - Entry(nil, "#qw #Qw", false, map[string]int{"qw": 2}), - Entry(nil, "#qw #Qw", false, map[string]int{"qw": 2}), - Entry(nil, "#qw #Qw", true, map[string]int{"qw": 1, "Qw": 1}), - Entry(nil, "#qw sd #qw", false, map[string]int{"qw": 2}), + ginkgo.Entry(nil, "#1qw2", false, map[string]int{"1qw2": 1}), + ginkgo.Entry(nil, "#12_", false, map[string]int{"12_": 1}), + ginkgo.Entry(nil, "#1_2", false, map[string]int{"1_2": 1}), + ginkgo.Entry(nil, "#12", false, map[string]int{"12": 1}), + ginkgo.Entry(nil, "#qw", false, map[string]int{"qw": 1}), + ginkgo.Entry(nil, "#qw #", false, map[string]int{"qw": 1}), + ginkgo.Entry(nil, " #qw", false, map[string]int{"qw": 1}), + ginkgo.Entry(nil, "#q1w", false, map[string]int{"q1w": 1}), + ginkgo.Entry(nil, "#q12w", false, map[string]int{"q12w": 1}), + ginkgo.Entry(nil, "#qw1", false, map[string]int{"qw1": 1}), + ginkgo.Entry(nil, "#qw12", false, map[string]int{"qw12": 1}), + ginkgo.Entry(nil, "#qw$", false, map[string]int{"qw": 1}), + ginkgo.Entry(nil, "#qw qw", false, map[string]int{"qw": 1}), + ginkgo.Entry(nil, "#qw #qw", false, map[string]int{"qw": 2}), + ginkgo.Entry(nil, "#qw #Qw", false, map[string]int{"qw": 2}), + ginkgo.Entry(nil, "#qw #Qw", false, map[string]int{"qw": 2}), + ginkgo.Entry(nil, "#qw #Qw", true, map[string]int{"qw": 1, "Qw": 1}), + ginkgo.Entry(nil, "#qw sd #qw", false, map[string]int{"qw": 2}), ) }, )