chore: coding style (#3959)

master^2
Kevin Wan 9 months ago committed by GitHub
parent e08ba2fee8
commit 45be48a4ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,7 +13,7 @@ import (
)
func FuzzMapReduce(f *testing.F) {
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
f.Add(int64(10), runtime.NumCPU())
f.Fuzz(func(t *testing.T, n int64, workers int) {

@ -20,7 +20,7 @@ import (
// If Fuzz stuck, we don't know why, because it only returns hung or unexpected,
// so we need to simulate the fuzz test in test mode.
func TestMapReduceRandom(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
const (
times = 10000

@ -41,7 +41,7 @@ type RedisLock struct {
}
func init() {
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
}
// NewRedisLock returns a RedisLock.

@ -11,7 +11,7 @@ import (
)
func FuzzNodeFind(f *testing.F) {
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
f.Add(10)
f.Fuzz(func(t *testing.T, keys int) {

@ -12,7 +12,7 @@ import (
func TestStableRunner(t *testing.T) {
size := bufSize * 2
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
runner := NewStableRunner(func(v int) float64 {
if v == 0 {
time.Sleep(time.Millisecond * 100)
@ -49,7 +49,7 @@ func TestStableRunner(t *testing.T) {
}
func FuzzStableRunner(f *testing.F) {
rand.Seed(time.Now().UnixNano())
rand.NewSource(time.Now().UnixNano())
f.Add(uint64(bufSize))
f.Fuzz(func(t *testing.T, n uint64) {
runner := NewStableRunner(func(v int) float64 {

@ -17,9 +17,9 @@ type parser struct {
spec *spec.ApiSpec
}
// Parse parses the api file.
// Depreacted: use tools/goctl/pkg/parser/api/parser/parser.go:18 instead,
// it will be removed in the future.
// Parse parses the api file.
func Parse(filename string) (*spec.ApiSpec, error) {
if env.UseExperimental() {
return apiParser.Parse(filename, "")

@ -94,6 +94,7 @@ func (t *TokenNode) RawText() string {
text = strings.TrimPrefix(text, `"`)
text = strings.TrimSuffix(text, `"`)
}
return text
}

@ -158,6 +158,7 @@ func (a *Analyzer) convertKV(kv []*ast.KVExpr) map[string]string {
ret[key] = v.Value.Token.Text
}
}
return ret
}

@ -8,9 +8,8 @@ import (
"strings"
"testing"
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/assertx"
)
@ -43,6 +42,7 @@ func Test_Parse(t *testing.T) {
return false
}())
})
t.Run("invalid", func(t *testing.T) {
data, err := os.ReadFile("./testdata/invalid.api")
assert.NoError(t, err)
@ -64,10 +64,12 @@ func Test_Parse(t *testing.T) {
assertx.Error(t, err)
}
})
t.Run("circleImport", func(t *testing.T) {
_, err := Parse("./testdata/base.api", nil)
assertx.Error(t, err)
})
t.Run("link_import", func(t *testing.T) {
_, err := Parse("./testdata/link_import.api", nil)
assert.Nil(t, err)

@ -1158,15 +1158,18 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}
pathText += p.curTok.Text
if p.peekTokenIs(token.SUB) { // 解析 abc-efg 格式
if p.peekTokenIs(token.SUB) { // parse abc-efg format
if !p.nextToken() {
return nil
}
pathText += p.curTok.Text
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}
pathText += p.curTok.Text
}
@ -1203,6 +1206,7 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
return nil
}
}
if !p.nextToken() {
return nil
}
@ -1263,15 +1267,18 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}
pathText += p.curTok.Text
if p.peekTokenIs(token.SUB) { // 解析 abc-efg 格式
if p.peekTokenIs(token.SUB) { // parse abc-efg format
if !p.nextToken() {
return nil
}
pathText += p.curTok.Text
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}
pathText += p.curTok.Text
}

Loading…
Cancel
Save