Skip to content

Commit 7d4f822

Browse files
authored
dependencies update + code grouming (#28)
1 parent e61d86c commit 7d4f822

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/s0rg/fantasyname
22

3-
go 1.20
3+
go 1.21.4
44

5-
require golang.org/x/text v0.11.0
5+
require golang.org/x/text v0.14.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
2-
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
1+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
2+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

parser.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ func newParser(opts ...Option) (p *parser) {
3333

3434
p = &parser{conf: c}
3535

36-
p.stack.Push(state{rndfn: p.conf.RandIntN}) // "root" state
36+
// "root" state
37+
p.stack.Push(&state{
38+
rand: p.conf.RandIntN,
39+
})
3740

3841
return p
3942
}
4043

4144
func (p *parser) OnGroupStart(isLiteral bool) {
42-
p.stack.Push(state{IsGroup: true, IsLiteral: isLiteral, rndfn: p.conf.RandIntN})
45+
p.stack.Push(&state{
46+
IsGroup: true,
47+
IsLiteral: isLiteral,
48+
rand: p.conf.RandIntN,
49+
})
4350
}
4451

4552
func (p *parser) OnGroupEnd(isLiteral bool) (err error) {

state.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type wrapper func(fmt.Stringer) fmt.Stringer
1010

1111
type state struct {
12-
rndfn func(int) int
12+
rand func(int) int
1313
items []fmt.Stringer
1414
wrappers []wrapper
1515
splitpos int
@@ -19,7 +19,7 @@ type state struct {
1919

2020
func (s *state) Add(v fmt.Stringer) {
2121
if !s.IsGroup {
22-
v = s.withWrappers(v)
22+
v = s.applyWrappers(v)
2323
}
2424

2525
s.items = append(s.items, v)
@@ -60,15 +60,15 @@ func (s *state) Stringer() (rv fmt.Stringer) {
6060
case len(s.items) == 1:
6161
rv = s.items[0]
6262
case s.IsGroup:
63-
rv = stringers.MakeRandom(s.items, s.rndfn)
63+
rv = stringers.MakeRandom(s.items, s.rand)
6464
default:
6565
rv = stringers.Sequence(s.items)
6666
}
6767

68-
return s.withWrappers(rv)
68+
return s.applyWrappers(rv)
6969
}
7070

71-
func (s *state) withWrappers(v fmt.Stringer) (rv fmt.Stringer) {
71+
func (s *state) applyWrappers(v fmt.Stringer) (rv fmt.Stringer) {
7272
rv = v
7373

7474
if len(s.wrappers) > 0 {

state_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestStateLiteralWrap(t *testing.T) {
5050
func TestStateLiteralGroupSplitNotEmpty(t *testing.T) {
5151
t.Parallel()
5252

53-
s := state{IsGroup: true, IsLiteral: true, rndfn: rand.Intn}
53+
s := state{IsGroup: true, IsLiteral: true, rand: rand.Intn}
5454
s.Add(stringers.Literal("a"))
5555
s.Add(stringers.Literal("c"))
5656
s.Split()
@@ -70,7 +70,7 @@ func TestStateLiteralGroupSplitNotEmpty(t *testing.T) {
7070
func TestStateLiteralGroupSplitEmpty(t *testing.T) {
7171
t.Parallel()
7272

73-
s := state{IsGroup: true, IsLiteral: true, rndfn: rand.Intn}
73+
s := state{IsGroup: true, IsLiteral: true, rand: rand.Intn}
7474
s.Split()
7575
s.Add(stringers.Literal("a"))
7676
s.Split()

statestack.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package fantasyname
22

3-
type statestack []state
3+
type statestack []*state
44

5-
func (ss *statestack) Push(s state) {
5+
func (ss *statestack) Push(s *state) {
66
*ss = append(*ss, s)
77
}
88

9-
func (ss *statestack) Pop() (rv state, ok bool) {
9+
func (ss *statestack) Pop() (rv *state, ok bool) {
1010
sp := *ss
1111

1212
if n := len(sp); n > 0 {
@@ -21,7 +21,7 @@ func (ss *statestack) Top() (rv *state, ok bool) {
2121
sp := *ss
2222

2323
if n := len(sp); n > 0 {
24-
rv, ok = &sp[n-1], true
24+
rv, ok = sp[n-1], true
2525
}
2626

2727
return

statestack_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestStateStackPushPop(t *testing.T) {
2525

2626
stack := statestack{}
2727

28-
stack.Push(state{IsLiteral: true})
28+
stack.Push(&state{IsLiteral: true})
2929

3030
if len(stack) != 1 {
3131
t.Error("unexpected len")

0 commit comments

Comments
 (0)