Skip to content

Commit

Permalink
Update tests, dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Nov 15, 2024
1 parent 47c5da2 commit a500ad6
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 22 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ on:
- master
- dev
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'

- name: Set up project
run: make setup

- name: Lint
run: make lint

test:
name: Test
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PKG_PATH=
setup:
go get -v -t ./...
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/vuln/cmd/govulncheck@latest

build:
go build -v -o ./out/abnf ./cmd/...
Expand All @@ -23,6 +25,12 @@ watch:
ginkgo version
ginkgo watch $(GINKGO_WATCH_FLAGS) $(GINKGO_FLAGS) ./$(PKG_PATH)

lint:
golangci-lint version
golangci-lint run ./...
govulncheck -version
govulncheck ./...

cover-report:
go tool cover -html=./cover.profile

Expand Down
8 changes: 6 additions & 2 deletions cmd/abnf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func configAction(ctx *cli.Context) error {
if _, err := os.Stat(confPath); err == nil {
v := "no"
fmt.Printf("WARN: File %s is already exist. Overwrite? (y, N)\n", confPath)
fmt.Scanln(&v)
if _, err := fmt.Scanln(&v); err != nil {
return cli.Exit(fmt.Errorf("read user input: %w", err), 1)
}

switch strings.ToLower(v) {
case "0", "n", "no":
Expand Down Expand Up @@ -223,7 +225,9 @@ func generateAction(ctx *cli.Context) error {
if _, err := os.Stat(outPath); err == nil {
v := "no"
fmt.Printf("WARN: File %s is already exist. Overwrite? (y, N)\n", outPath)
fmt.Scanln(&v)
if _, err := fmt.Scanln(&v); err != nil {
return cli.Exit(fmt.Errorf("read user input: %w", err), 1)
}

switch strings.ToLower(v) {
case "0", "n", "no":
Expand Down
18 changes: 2 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
github.com/dave/jennifer v1.7.0/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/dave/jennifer v1.7.1 h1:B4jJJDHelWcDhlRQxWeo0Npa/pYKBLrirAQoTN45txo=
github.com/dave/jennifer v1.7.1/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -12,14 +10,10 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
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-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/pprof v0.0.0-20241101162523-b92577c0c142 h1:sAGdeJj0bnMgUNVeUpp6AYlVdCt3/GdI3pGRqsNSQLs=
github.com/google/pprof v0.0.0-20241101162523-b92577c0c142/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -32,24 +26,16 @@ github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
12 changes: 8 additions & 4 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ type Node struct {
}

// String returns the node's value as string.
func (n *Node) String() string { return string(n.Value) }
func (n *Node) String() string {
if n == nil {
return "<nil>"
}
return string(n.Value)
}

// Len returns length of the node's value.
func (n *Node) Len() int {
Expand Down Expand Up @@ -53,9 +58,7 @@ func (n *Node) GetNodes(key string) Nodes {
if n.Key == key {
ns = append(ns, n)
}
for _, n := range n.Children.GetAll(key) {
ns = append(ns, n)
}
ns = append(ns, n.Children.GetAll(key)...)
return ns
}

Expand Down Expand Up @@ -148,5 +151,6 @@ func (ns Nodes) free() {
if cap(ns) > 10000 {
return
}
//nolint:staticcheck
nodesPool.Put(ns)
}
149 changes: 149 additions & 0 deletions qwe_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package abnf_test

import (
"strings"
"testing"

"github.com/ghettovoice/abnf"
"github.com/ghettovoice/abnf/pkg/abnf_core"
)

func BenchmarkParseMessageStart(b *testing.B) {
// str := "INVITE sip:[email protected] SIP/2.0"
str := []byte("IN" + strings.Repeat("m", 64<<10) + "VITE")
// str := []byte("INVITE")
ns := make(abnf.Nodes, 0, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
clear(ns)
ns = Method(str, ns[:0])
if ns.Best().Len() != len(str) {
b.Errorf("%d parse fail", i)
}
}
}

var method abnf.Operator

func Method(s []byte, ns abnf.Nodes) abnf.Nodes {
if method == nil {
method = abnf.Alt(
"Method",
INVITEm,
ACKm,
OPTIONSm,
BYEm,
CANCELm,
REGISTERm,
ExtensionMethod,
)
}
return method(s, ns)
}

var invitem abnf.Operator

// INVITEm rule: INVITEm = %x49.4E.56.49.54.45
func INVITEm(s []byte, ns abnf.Nodes) abnf.Nodes {
if invitem == nil {
invitem = abnf.Literal("INVITEm", []byte{73, 78, 86, 73, 84, 69})
}
return invitem(s, ns)
}

var ackm abnf.Operator

// ACKm rule: ACKm = %x41.43.4B
func ACKm(s []byte, ns abnf.Nodes) abnf.Nodes {
if ackm == nil {
ackm = abnf.Literal("ACKm", []byte{65, 67, 75})
}
return ackm(s, ns)
}

var optionsm abnf.Operator

// OPTIONSm rule: OPTIONSm = %x4F.50.54.49.4F.4E.53
func OPTIONSm(s []byte, ns abnf.Nodes) abnf.Nodes {
if optionsm == nil {
optionsm = abnf.Literal("OPTIONSm", []byte{79, 80, 84, 73, 79, 78, 83})
}
return optionsm(s, ns)
}

var byem abnf.Operator

// BYEm rule: BYEm = %x42.59.45
func BYEm(s []byte, ns abnf.Nodes) abnf.Nodes {
if byem == nil {
byem = abnf.Literal("BYEm", []byte{66, 89, 69})
}
return byem(s, ns)
}

var cancelm abnf.Operator

// CANCELm rule: CANCELm = %x43.41.4E.43.45.4C
func CANCELm(s []byte, ns abnf.Nodes) abnf.Nodes {
if cancelm == nil {
cancelm = abnf.Literal("CANCELm", []byte{67, 65, 78, 67, 69, 76})
}
return cancelm(s, ns)
}

var registerm abnf.Operator

// REGISTERm rule: REGISTERm = %x52.45.47.49.53.54.45.52
func REGISTERm(s []byte, ns abnf.Nodes) abnf.Nodes {
if registerm == nil {
registerm = abnf.Literal("REGISTERm", []byte{82, 69, 71, 73, 83, 84, 69, 82})
}
return registerm(s, ns)
}

var extensionMethod abnf.Operator

// ExtensionMethod rule: extension-method = token
func ExtensionMethod(s []byte, ns abnf.Nodes) abnf.Nodes {
if extensionMethod == nil {
extensionMethod = Token
}
return extensionMethod(s, ns)
}

var token abnf.Operator

// Token rule: token = 1*(alphanum / "-" / "." / "!" / "%" / "*" / "_" / "+" / "`" / "'" / "~" )
func Token(s []byte, ns abnf.Nodes) abnf.Nodes {
if token == nil {
token = abnf.Repeat1Inf("token", abnf.Alt(
"alphanum / \"-\" / \".\" / \"!\" / \"%\" / \"*\" / \"_\" / \"+\" / \"`\" / \"'\" / \"~\"",
Alphanum,
abnf.Literal("\"-\"", []byte{45}),
abnf.Literal("\".\"", []byte{46}),
abnf.Literal("\"!\"", []byte{33}),
abnf.Literal("\"%\"", []byte{37}),
abnf.Literal("\"*\"", []byte{42}),
abnf.Literal("\"_\"", []byte{95}),
abnf.Literal("\"+\"", []byte{43}),
abnf.Literal("\"`\"", []byte{96}),
abnf.Literal("\"'\"", []byte{39}),
abnf.Literal("\"~\"", []byte{126}),
))
}
return token(s, ns)
}

var alphanum abnf.Operator

// Alphanum rule: alphanum = ALPHA / DIGIT
func Alphanum(s []byte, ns abnf.Nodes) abnf.Nodes {
if alphanum == nil {
alphanum = abnf.Alt(
"alphanum",
abnf_core.ALPHA,
abnf_core.DIGIT,
)
}
return alphanum(s, ns)
}

0 comments on commit a500ad6

Please sign in to comment.