@@ -19,7 +19,7 @@ func TestNewListener(t *testing.T) {
1919
2020func TestListener_SetCallback (t * testing.T ) {
2121 l := NewListener [S ]()
22- f := func (e []Events ) {}
22+ f := func (e []Events [ S ] ) {}
2323 l .SetCallback (f )
2424 assert .NotNil (t , l .EventCallback )
2525}
@@ -32,10 +32,15 @@ func TestListener_AddNewValue(t *testing.T) {
3232 {F0 : "2" , F1 : "test2" , F2 : "" },
3333 }
3434 l .AddNewValue (s )
35- expected := map [string ]string {
36- "1" : "{\" F0\" :\" 1\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
37- "2" : "{\" F0\" :\" 2\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
38- }
35+ expected := map [string ]Value [S ]{
36+ "1" : {
37+ Hash : "{\" F0\" :\" 1\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
38+ Data : S {F0 : "1" , F1 : "test2" , F2 : "" },
39+ },
40+ "2" : {
41+ Hash : "{\" F0\" :\" 2\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
42+ Data : S {F0 : "2" , F1 : "test2" , F2 : "" },
43+ }}
3944 assert .Equal (t , expected , l .NewValue )
4045}
4146
@@ -47,38 +52,43 @@ func TestListener_convertToMap(t *testing.T) {
4752 {F0 : "2" , F1 : "test2" , F2 : "" },
4853 }
4954 actual := l .convertToMap (s )
50- expected := map [string ]string {
51- "1" : "{\" F0\" :\" 1\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
52- "2" : "{\" F0\" :\" 2\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
53- }
55+ expected := map [string ]Value [S ]{
56+ "1" : {
57+ Hash : "{\" F0\" :\" 1\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
58+ Data : S {F0 : "1" , F1 : "test2" , F2 : "" },
59+ },
60+ "2" : {
61+ Hash : "{\" F0\" :\" 2\" ,\" F1\" :\" test2\" ,\" F2\" :\" \" }" ,
62+ Data : S {F0 : "2" , F1 : "test2" , F2 : "" },
63+ }}
5464 assert .Equal (t , expected , actual )
5565}
5666
5767func TestListener_compareMap (t * testing.T ) {
5868 l := new (Listener [S ])
59- l .CurrentValue = map [string ]string {
60- "2" : "2" ,
61- "3" : "6" ,
62- "4" : "4" ,
63- "5" : "5" ,
69+ l .CurrentValue = map [string ]Value [ S ] {
70+ "2" : { "{ \" F0 \" : \" 2 \" }" , S { F0 : "2" }} ,
71+ "3" : { "{ \" F0 \" : \" 3 \" }" , S { F0 : "3" }} ,
72+ "4" : { "{ \" F0 \" : \" 4 \" }" , S { F0 : "4" }} ,
73+ "5" : { "{ \" F0 \" : \" 5 \" }" , S { F0 : "5" }} ,
6474 }
65- l .NewValue = map [string ]string {
66- "1" : "1" ,
67- "2" : "2" ,
68- "3" : "3" ,
69- "4" : "4" ,
75+ l .NewValue = map [string ]Value [ S ] {
76+ "1" : { "{ \" F0 \" : \" 1 \" }" , S { F0 : "1" }} ,
77+ "2" : { "{ \" F0 \" : \" 2 \" }" , S { F0 : "2" }} ,
78+ "3" : { "{ \" F0 \" : \" 3 \" , \" F2 \" : \" 4 \" }}" , S { F0 : "3" , F2 : "4" }} ,
79+ "4" : { "{ \" F0 \" : \" 4 \" }" , S { F0 : "4" }} ,
7080 }
7181
7282 e := l .compareMap ()
73- expected := []Events {
74- {State : EventStateAdded , ID : "1" },
75- {State : EventStateUpdated , ID : "3" },
76- {State : EventStateDeleted , ID : "5" },
83+ expected := []Events [ S ] {
84+ {State : EventStateAdded , ID : "1" , Data : S { F0 : "1" } },
85+ {State : EventStateUpdated , ID : "3" , Data : S { F0 : "3" , F2 : "4" } },
86+ {State : EventStateDeleted , ID : "5" , Data : S {} },
7787 }
7888 assert .Equal (t , expected , e )
7989
8090 // test compare with callback
81- f := func (e []Events ) {}
91+ f := func (e []Events [ S ] ) {}
8292 l .SetCallback (f )
8393 e = l .compareMap ()
8494 //no change event
0 commit comments