Skip to content

Commit

Permalink
test remove some index listener(middle,first,last).
Browse files Browse the repository at this point in the history
  • Loading branch information
RelicOfTesla committed Jan 15, 2023
1 parent 2caf275 commit dc57b95
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions listener_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,39 @@ func Test_RemoveListener(t *testing.T) {

f1 := makeFn(11)
f2 := makeFn(22)
f3 := &testListenerCalc{bind: 33, owner: global}
f3 := makeFn(33)
p4 := &testListenerCalc{bind: 44, owner: global}
p5 := &testListenerCalc{bind: 55, owner: global}
p6 := &testListenerCalc{bind: 66, owner: global}

evBus.On(evName, f1)
evBus.On(evName, f2)
evBus.On(evName, f3)
evBus.On(evName, p4)
evBus.On(evName, p5)
evBus.On(evName, p6)

evBus.MustFire(evName, nil)
require.Equal(t, global.n, 3)
require.Equal(t, global.sum, 66) //11+22+33=66
require.Equal(t, global.n, 6)
require.Equal(t, global.sum, 231) //11+22+33+44+55+66=231

evBus.RemoveListener(evName, f2)
evBus.RemoveListener(evName, p5)
evBus.MustFire(evName, nil)
require.Equal(t, global.n, 6+4)
require.Equal(t, global.sum, 385) // 231+11+33+44+66=385

evBus.RemoveListener(evName, f1)
evBus.RemoveListener(evName, f1) // not exist function.
evBus.MustFire(evName, nil)
require.Equal(t, global.n, 5)
require.Equal(t, global.sum, 121) // 66+22+33=121
require.Equal(t, global.n, 6+4+3)
require.Equal(t, global.sum, 528) // 385+33+44+66=528

evBus.RemoveListener(evName, f3)
evBus.RemoveListener(evName, p6)
evBus.RemoveListener(evName, p6) // not exist function.
evBus.MustFire(evName, nil)
require.Equal(t, global.n, 6)
require.Equal(t, global.sum, 143) // 121+22=143
require.Equal(t, global.n, 6+4+3+2)
require.Equal(t, global.sum, 605) // 528+33+44=605
})
t.Run("same value struct", func(t *testing.T) {
global := &globalTestVal{}
Expand Down

0 comments on commit dc57b95

Please sign in to comment.