@@ -14,7 +14,7 @@ import (
14
14
func TestWindowState (t * testing.T ) {
15
15
r := strings .NewReader ("Hello, world!" )
16
16
width , height := 16 , 10
17
- window , err := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
17
+ window , err := newWindow (r , "test" , "test" , nil , nil )
18
18
if err != nil {
19
19
t .Fatal (err )
20
20
}
@@ -70,7 +70,7 @@ func TestWindowState(t *testing.T) {
70
70
func TestWindowEmptyState (t * testing.T ) {
71
71
r := strings .NewReader ("" )
72
72
width , height := 16 , 10
73
- window , err := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
73
+ window , err := newWindow (r , "test" , "test" , nil , nil )
74
74
if err != nil {
75
75
t .Fatal (err )
76
76
}
@@ -136,7 +136,7 @@ func TestWindowEmptyState(t *testing.T) {
136
136
func TestWindowCursorMotions (t * testing.T ) {
137
137
r := strings .NewReader (strings .Repeat ("Hello, world!" , 100 ))
138
138
width , height := 16 , 10
139
- window , err := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
139
+ window , err := newWindow (r , "test" , "test" , nil , nil )
140
140
if err != nil {
141
141
t .Fatal (err )
142
142
}
@@ -437,7 +437,7 @@ func TestWindowCursorMotions(t *testing.T) {
437
437
func TestWindowScreenMotions (t * testing.T ) {
438
438
r := strings .NewReader (strings .Repeat ("Hello, world!" , 100 ))
439
439
width , height := 16 , 10
440
- window , err := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
440
+ window , err := newWindow (r , "test" , "test" , nil , nil )
441
441
if err != nil {
442
442
t .Fatal (err )
443
443
}
@@ -619,13 +619,7 @@ func TestWindowScreenMotions(t *testing.T) {
619
619
func TestWindowDeleteBytes (t * testing.T ) {
620
620
r := strings .NewReader ("Hello, world!" )
621
621
width , height := 16 , 10
622
- eventCh := make (chan event.Event )
623
- go func () {
624
- for {
625
- <- eventCh
626
- }
627
- }()
628
- window , _ := newWindow (r , "test" , "test" , eventCh , make (chan struct {}))
622
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
629
623
window .setSize (width , height )
630
624
631
625
window .cursorNext (mode .Normal , 7 )
@@ -687,13 +681,7 @@ func TestWindowDeleteBytes(t *testing.T) {
687
681
func TestWindowDeletePrevBytes (t * testing.T ) {
688
682
r := strings .NewReader ("Hello, world!" )
689
683
width , height := 16 , 10
690
- eventCh := make (chan event.Event )
691
- go func () {
692
- for {
693
- <- eventCh
694
- }
695
- }()
696
- window , _ := newWindow (r , "test" , "test" , eventCh , make (chan struct {}))
684
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
697
685
window .setSize (width , height )
698
686
699
687
window .cursorNext (mode .Normal , 5 )
@@ -728,7 +716,7 @@ func TestWindowDeletePrevBytes(t *testing.T) {
728
716
func TestWindowIncrementDecrement (t * testing.T ) {
729
717
r := strings .NewReader ("Hello, world!" )
730
718
width , height := 16 , 10
731
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
719
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
732
720
window .setSize (width , height )
733
721
734
722
window .increment (0 )
@@ -778,7 +766,7 @@ func TestWindowIncrementDecrement(t *testing.T) {
778
766
func TestWindowIncrementDecrementEmpty (t * testing.T ) {
779
767
r := strings .NewReader ("" )
780
768
width , height := 16 , 10
781
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
769
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
782
770
window .setSize (width , height )
783
771
784
772
s , _ := window .state (width , height )
@@ -801,7 +789,7 @@ func TestWindowIncrementDecrementEmpty(t *testing.T) {
801
789
t .Errorf ("s.Length should be %d but got %d" , expected , s .Length )
802
790
}
803
791
804
- window , _ = newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
792
+ window , _ = newWindow (r , "test" , "test" , nil , nil )
805
793
window .setSize (width , height )
806
794
807
795
window .decrement (0 )
@@ -820,7 +808,7 @@ func TestWindowIncrementDecrementEmpty(t *testing.T) {
820
808
func TestWindowInsertByte (t * testing.T ) {
821
809
r := strings .NewReader ("Hello, world!" )
822
810
width , height := 16 , 1
823
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
811
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
824
812
window .setSize (width , height )
825
813
826
814
window .cursorNext (mode .Normal , 7 )
@@ -879,7 +867,7 @@ func TestWindowInsertByte(t *testing.T) {
879
867
func TestWindowInsertEmpty (t * testing.T ) {
880
868
r := strings .NewReader ("" )
881
869
width , height := 16 , 10
882
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
870
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
883
871
window .setSize (width , height )
884
872
885
873
window .startInsert ()
@@ -915,7 +903,7 @@ func TestWindowInsertEmpty(t *testing.T) {
915
903
func TestWindowInsertHead (t * testing.T ) {
916
904
r := strings .NewReader (strings .Repeat ("Hello, world!" , 2 ))
917
905
width , height := 16 , 10
918
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
906
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
919
907
window .setSize (width , height )
920
908
921
909
window .pageEnd ()
@@ -948,7 +936,7 @@ func TestWindowInsertHead(t *testing.T) {
948
936
func TestWindowInsertHeadEmpty (t * testing.T ) {
949
937
r := strings .NewReader ("" )
950
938
width , height := 16 , 10
951
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
939
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
952
940
window .setSize (width , height )
953
941
954
942
window .startInsertHead ()
@@ -984,7 +972,7 @@ func TestWindowInsertHeadEmpty(t *testing.T) {
984
972
func TestWindowAppend (t * testing.T ) {
985
973
r := strings .NewReader ("Hello, world!" )
986
974
width , height := 16 , 10
987
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
975
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
988
976
window .setSize (width , height )
989
977
990
978
window .cursorNext (mode .Normal , 7 )
@@ -1028,7 +1016,7 @@ func TestWindowAppend(t *testing.T) {
1028
1016
func TestWindowAppendEmpty (t * testing.T ) {
1029
1017
r := strings .NewReader ("" )
1030
1018
width , height := 16 , 10
1031
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1019
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1032
1020
window .setSize (width , height )
1033
1021
1034
1022
window .startAppend ()
@@ -1075,7 +1063,7 @@ func TestWindowAppendEmpty(t *testing.T) {
1075
1063
func TestWindowReplaceByte (t * testing.T ) {
1076
1064
r := strings .NewReader ("Hello, world!" )
1077
1065
width , height := 16 , 10
1078
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1066
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1079
1067
window .setSize (width , height )
1080
1068
1081
1069
window .cursorNext (mode .Normal , 7 )
@@ -1102,7 +1090,7 @@ func TestWindowReplaceByte(t *testing.T) {
1102
1090
func TestWindowReplaceByteEmpty (t * testing.T ) {
1103
1091
r := strings .NewReader ("" )
1104
1092
width , height := 16 , 10
1105
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1093
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1106
1094
window .setSize (width , height )
1107
1095
1108
1096
window .startReplaceByte ()
@@ -1128,7 +1116,7 @@ func TestWindowReplaceByteEmpty(t *testing.T) {
1128
1116
func TestWindowReplace (t * testing.T ) {
1129
1117
r := strings .NewReader ("Hello, world!" )
1130
1118
width , height := 16 , 10
1131
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1119
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1132
1120
window .setSize (width , height )
1133
1121
1134
1122
window .cursorNext (mode .Normal , 10 )
@@ -1175,7 +1163,7 @@ func TestWindowReplace(t *testing.T) {
1175
1163
func TestWindowReplaceEmpty (t * testing.T ) {
1176
1164
r := strings .NewReader ("" )
1177
1165
width , height := 16 , 10
1178
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1166
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1179
1167
window .setSize (width , height )
1180
1168
1181
1169
window .startReplace ()
@@ -1204,7 +1192,7 @@ func TestWindowReplaceEmpty(t *testing.T) {
1204
1192
func TestWindowInsertByte2 (t * testing.T ) {
1205
1193
r := strings .NewReader ("" )
1206
1194
width , height := 16 , 10
1207
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1195
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1208
1196
window .setSize (width , height )
1209
1197
1210
1198
window .startInsert ()
@@ -1234,7 +1222,7 @@ func TestWindowInsertByte2(t *testing.T) {
1234
1222
func TestWindowBackspace (t * testing.T ) {
1235
1223
r := strings .NewReader ("Hello, world!" )
1236
1224
width , height := 16 , 10
1237
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1225
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1238
1226
window .setSize (width , height )
1239
1227
1240
1228
window .cursorNext (mode .Normal , 5 )
@@ -1258,7 +1246,7 @@ func TestWindowBackspace(t *testing.T) {
1258
1246
func TestWindowBackspacePending (t * testing.T ) {
1259
1247
r := strings .NewReader ("Hello, world!" )
1260
1248
width , height := 16 , 10
1261
- window , _ := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1249
+ window , _ := newWindow (r , "test" , "test" , nil , nil )
1262
1250
window .setSize (width , height )
1263
1251
1264
1252
window .cursorNext (mode .Normal , 5 )
@@ -1288,11 +1276,12 @@ func TestWindowBackspacePending(t *testing.T) {
1288
1276
func TestWindowEventRune (t * testing.T ) {
1289
1277
width , height := 16 , 10
1290
1278
redrawCh := make (chan struct {})
1291
- window , _ := newWindow (strings .NewReader ("" ), "test" , "test" , make ( chan event. Event ) , redrawCh )
1279
+ window , _ := newWindow (strings .NewReader ("" ), "test" , "test" , nil , redrawCh )
1292
1280
window .setSize (width , height )
1293
1281
1294
1282
str := "48723fffab"
1295
1283
go func () {
1284
+ defer close (redrawCh )
1296
1285
window .emit (event.Event {Type : event .StartInsert })
1297
1286
for _ , r := range str {
1298
1287
window .emit (event.Event {Type : event .Rune , Rune : r , Mode : mode .Insert })
@@ -1306,16 +1295,18 @@ func TestWindowEventRune(t *testing.T) {
1306
1295
if expected := "\x48 \x72 \x3f \xff \xab \x00 " ; ! strings .HasPrefix (string (s .Bytes ), expected ) {
1307
1296
t .Errorf ("s.Bytes should start with %q but got %q" , expected , string (s .Bytes ))
1308
1297
}
1298
+ <- redrawCh
1309
1299
}
1310
1300
1311
1301
func TestWindowEventRuneText (t * testing.T ) {
1312
1302
width , height := 16 , 10
1313
1303
redrawCh := make (chan struct {})
1314
- window , _ := newWindow (strings .NewReader ("" ), "test" , "test" , make ( chan event. Event ) , redrawCh )
1304
+ window , _ := newWindow (strings .NewReader ("" ), "test" , "test" , nil , redrawCh )
1315
1305
window .setSize (width , height )
1316
1306
1317
1307
str := "Hello, World!\n こんにちは、世界!\n 鰰は魚の一種"
1318
1308
go func () {
1309
+ defer close (redrawCh )
1319
1310
window .emit (event.Event {Type : event .SwitchFocus })
1320
1311
window .emit (event.Event {Type : event .StartInsert })
1321
1312
for _ , r := range str {
@@ -1331,25 +1322,24 @@ func TestWindowEventRuneText(t *testing.T) {
1331
1322
if expected := str + "\x00 " ; ! strings .HasPrefix (string (s .Bytes ), expected ) {
1332
1323
t .Errorf ("s.Bytes should start with %q but got %q" , expected , string (s .Bytes ))
1333
1324
}
1325
+ <- redrawCh
1334
1326
}
1335
1327
1336
1328
func TestWindowEventUndoRedo (t * testing.T ) {
1337
1329
width , height := 16 , 10
1338
1330
redrawCh := make (chan struct {})
1339
- window , _ := newWindow (strings .NewReader ("Hello, world!" ), "test" , "test" , make ( chan event. Event ) , redrawCh )
1331
+ window , _ := newWindow (strings .NewReader ("Hello, world!" ), "test" , "test" , nil , redrawCh )
1340
1332
window .setSize (width , height )
1341
1333
waitCh := make (chan struct {})
1342
- defer func () {
1343
- close (waitCh )
1344
- close (redrawCh )
1345
- }()
1346
1334
1347
1335
waitRedraw := func (count int ) {
1348
1336
for range count {
1349
1337
<- redrawCh
1350
1338
}
1351
1339
}
1352
1340
go func () {
1341
+ defer close (redrawCh )
1342
+ defer close (waitCh )
1353
1343
window .emit (event.Event {Type : event .Undo })
1354
1344
window .emit (event.Event {Type : event .SwitchFocus })
1355
1345
window .emit (event.Event {Type : event .StartAppend , Mode : mode .Insert })
@@ -1439,11 +1429,12 @@ func TestWindowEventUndoRedo(t *testing.T) {
1439
1429
if expected := int64 (4 ); s .Cursor != expected {
1440
1430
t .Errorf ("s.Cursor should be %d but got %d" , expected , s .Cursor )
1441
1431
}
1432
+ <- redrawCh
1442
1433
}
1443
1434
1444
1435
func TestWindowWriteTo (t * testing.T ) {
1445
1436
r := strings .NewReader ("Hello, world!" )
1446
- window , err := newWindow (r , "test" , "test" , make ( chan event. Event ), make ( chan struct {}) )
1437
+ window , err := newWindow (r , "test" , "test" , nil , nil )
1447
1438
if err != nil {
1448
1439
t .Fatal (err )
1449
1440
}
0 commit comments