Skip to content

Commit

Permalink
Modernise (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dim authored Jan 3, 2023
1 parent 9447605 commit 45cb42a
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 60 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
go:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.18.x, 1.19.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
- run: make test
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.x
cache: true
- uses: golangci/golangci-lint-action@v3
with:
version: latest
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
default: vet test

vet:
go vet ./...
default: test

test:
go test ./...
Expand Down
4 changes: 2 additions & 2 deletions builder_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package qualify

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

var _ = Describe("Builder", func() {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/bsm/qualify

go 1.19

require (
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
github.com/bsm/ginkgo/v2 v2.5.0
github.com/bsm/gomega v1.20.0
)
27 changes: 4 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk=
4 changes: 2 additions & 2 deletions internal/intsets/dense_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package intsets
import (
"math/rand"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

var _ = Describe("Dense", func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/intsets/intsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package intsets
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

func TestSuite(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/intsets/naive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package intsets
import (
"math/rand"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

var _ = Describe("Naive", func() {
Expand Down
4 changes: 2 additions & 2 deletions multi_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package qualify

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

var _ = Describe("multiOneOf", func() {
Expand Down
29 changes: 19 additions & 10 deletions qualify.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func (q *Qualifier) Qualify(dst []int, fact Fact) []int {
}

// retrieve fact values
vv = fact.AppendFieldValues(vv[:0], field)
vv.S = fact.AppendFieldValues(vv.S[:0], field)

// merge all explicit oneOf outcomes
for _, val := range vv {
for _, val := range vv.S {
fv := fieldValue{Field: field, Value: val}

if set, ok := q.oneOf[fv]; ok {
Expand All @@ -78,7 +78,7 @@ func (q *Qualifier) Qualify(dst []int, fact Fact) []int {
}

// now, exclude all explicit noneOf outcomes
for _, val := range vv {
for _, val := range vv.S {
fv := fieldValue{Field: field, Value: val}

if set, ok := q.noneOf[fv]; ok {
Expand All @@ -93,17 +93,19 @@ func (q *Qualifier) Qualify(dst []int, fact Fact) []int {
}

// extract candidate positions (from pool)
poss := oc.AppendTo(q.recycleSlice())
poss := q.recycleSlice()
defer q.islPool.Put(poss)

poss.S = oc.AppendTo(poss.S)

// check each candidate against oneOfX restrictions
for _, pos := range poss {
for _, pos := range poss.S {
outcome := q.outcomes[pos]

skip := false
for field, multi := range q.oneOfX[outcome] {
vv = fact.AppendFieldValues(vv[:0], field)
if !multi.Match(fc, vv...) {
vv.S = fact.AppendFieldValues(vv.S[:0], field)
if !multi.Match(fc, vv.S...) {
skip = true
break
}
Expand All @@ -120,14 +122,21 @@ func (q *Qualifier) Qualify(dst []int, fact Fact) []int {
func (q *Qualifier) recycleSet() *intsets.Dense {
if v := q.setPool.Get(); v != nil {
s := v.(*intsets.Dense)
s.Clear()
return s
}
return new(intsets.Dense)
}

func (q *Qualifier) recycleSlice() []int {
func (q *Qualifier) recycleSlice() *intSlice {
if v := q.islPool.Get(); v != nil {
return v.([]int)[:0]
s := v.(*intSlice)
s.S = s.S[:0]
return s
}
return nil
return new(intSlice)
}

type intSlice struct {
S []int
}
7 changes: 3 additions & 4 deletions qualify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package qualify
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/bsm/gomega/types"
)

var _ = DescribeTable("Qualifier",
Expand Down
4 changes: 2 additions & 2 deletions util_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package qualify

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)

var _ = Describe("StrDict", func() {
Expand Down

0 comments on commit 45cb42a

Please sign in to comment.