forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ScintillaWrapperTestCase.py
More file actions
1020 lines (838 loc) · 43.5 KB
/
test_ScintillaWrapperTestCase.py
File metadata and controls
1020 lines (838 loc) · 43.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import unittest
import time
from Npp import (
editor, notepad, SCINTILLANOTIFICATION, FINDOPTION, KEYMOD,
SCINTILLAMESSAGE, MODIFICATIONFLAGS, LANGTYPE, Cell
)
class ScintillaWrapperTestCase(unittest.TestCase):
def setUp(self):
# Make doubly sure we've got no lingering callbacks waiting
notepad.clearCallbacks()
editor.clearCallbacks()
notepad.new()
self.callbackCalled = False
def tearDown(self):
notepad.clearCallbacks()
editor.clearCallbacks()
editor.setSavePoint()
notepad.close()
def poll_for_callback(self, timeout = 0.5, interval = 0.1):
while (not self.callbackCalled) and (timeout > 0):
time.sleep(interval)
timeout -= interval
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_void_textrange(self):
notepad.setLangType(LANGTYPE.XML)
editor.write('<test attrib="unit" />')
time.sleep(0.1) # let the lexer do it's thing. The getStyledText appears to fail occassionally, returns a bunch of zeroes for the styles
# I'm assuming it's a timing bug, as it "normally" works. Added the sleep to see if it makes a difference.
result = editor.getStyledText(0, 19)
self.assertEqual(('<test attrib="unit"', [1, 1, 1, 1, 1, 8, 3, 3, 3, 3, 3, 3, 8, 6, 6, 6, 6, 6, 6]), result)
def callback_scintillawrapper_int_void_textrange(self, args):
result = editor.getStyledText(0, 19)
self.assertEqual(('<test attrib="unit"', [1, 1, 1, 1, 1, 8, 3, 3, 3, 3, 3, 3, 8, 6, 6, 6, 6, 6, 6]), result)
self.callbackCalled = True
def test_scintillawrapper_int_void_textrange_in_callback(self):
notepad.setLangType(LANGTYPE.XML)
editor.write('<test attrib="unit" />')
time.sleep(0.1) # lexing and threading don't seem to mix
editor.callback(lambda args: self.callback_scintillawrapper_int_void_textrange(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_int_string(self):
editor.write('ABC This is a some ABC text we are going to search')
time.sleep(0.1) # let N++ mess with the target
editor.setSearchFlags(0)
editor.setTarget(5, 25)
result = editor.searchInTarget('ABC')
self.assertEqual(result, 19)
def callback_scintillawrapper_int_int_string(self, args):
time.sleep(0.1) # let N++ mess with the target
editor.setTarget(5, 25)
self.assertEqual(editor.getTargetStart(), 5)
self.assertEqual(editor.getTargetEnd(), 25)
result = editor.searchInTarget('ABC')
self.assertEqual(result, 19)
self.callbackCalled = True
def test_scintillawrapper_int_int_string_in_callback(self):
editor.write('ABC This is a some ABC text we are going to search')
editor.callback(lambda args: self.callback_scintillawrapper_int_int_string(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_cells(self):
notepad.setLangType(LANGTYPE.TXT)
editor.addStyledText(Cell('Test', [1,2,3,4]))
result = editor.getStyledText(0, 4)
self.assertEqual(result, ('Test',[1,2,3,4]))
def callback_scintillawrapper_void_int_cells(self, args):
notepad.setLangType(LANGTYPE.TXT)
editor.addStyledText(Cell('Test', [1,2,3,4]))
result = editor.getStyledText(0, 4)
self.assertEqual(result, ('Test',[1,2,3,4]))
self.callbackCalled = True
def test_scintillawrapper_void_int_cells_in_callback(self):
editor.write('Hi')
editor.setText('')
editor.callback(lambda args: self.callback_scintillawrapper_void_int_cells(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
# TODO: NPP BUG - Crash
@unittest.skipUnless(notepad.getVersion() > (7,5,8), "NPP BUG STILL EXISTS")
def test_scintillawrapper_void_void_int(self):
# we'll grab the doc point of the current document, then create another scintilla, set it to the document, write text in it,
# then grab the text from the main 'editor' Scintilla, which should be what we added in
docPointer = editor.getDocPointer()
notepad.outputDebugString('creating hidden scintilla\n')
hiddenScintilla = notepad.createScintilla()
notepad.outputDebugString('setting doc pointer in hidden scintilla\n')
hiddenScintilla.setDocPointer(docPointer)
notepad.outputDebugString('complete - set doc pointer in hidden scintilla\n')
hiddenScintilla.write('hello world, from the other side')
text = editor.getText()
notepad.outputDebugString('about to destroy scintilla\n')
notepad.destroyScintilla(hiddenScintilla)
notepad.outputDebugString('destroyed scintilla\n')
self.assertEqual(text, 'hello world, from the other side')
def callback_scintillawrapper_void_void_int(self, args):
editor.clearCallbacks()
editor.clearAll()
self.test_scintillawrapper_void_void_int()
self.callbackCalled = True
def test_scintillawrapper_void_void_int_in_callback(self):
notepad.outputDebugString('test_scintillawrapper_void_void_int_in_callback')
editor.write('test')
editor.callback(lambda args: self.callback_scintillawrapper_void_void_int(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_void(self):
editor.write('one\r\ntwo\r\nthree\r\n')
before = editor.getCurLine()
editor.gotoLine(1)
after = editor.getCurLine()
self.assertEqual(after, 'two\r\n')
self.assertNotEqual(before, after)
def callback_scintillawrapper_void_int_void(self, args):
editor.write('one\r\ntwo\r\nthree\r\n')
before = editor.getCurLine()
editor.gotoLine(1)
after = editor.getCurLine()
self.assertEqual(after, 'two\r\n')
self.assertNotEqual(before, after)
self.callbackCalled = True
def test_scintillawrapper_void_int_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_void(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_position_string(self):
editor.write('ABCDEF')
editor.insertText(3, 'GHI')
content = editor.getText()
self.assertEqual('ABCGHIDEF', content)
def callback_scintillawrapper_void_position_string(self, args):
editor.write('ABCDEF')
editor.insertText(3, 'GHI')
content = editor.getText()
self.assertEqual('ABCGHIDEF', content)
self.callbackCalled = True
def test_scintillawrapper_void_position_string_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_position_string(args), [SCINTILLANOTIFICATION.SAVEPOINTREACHED])
editor.setSavePoint()
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_colour(self):
currentColour = editor.styleGetFore(1)
editor.styleSetFore(1, (218,219,220))
newColour = editor.styleGetFore(1)
# reset the style back to the original (assuming it works!)
editor.styleSetFore(1, currentColour)
self.assertEqual(newColour, (218,219,220))
self.assertNotEqual(currentColour, newColour)
def callback_scintillawrapper_void_int_colour(self, args):
self.test_scintillawrapper_void_int_colour()
self.callbackCalled = True
def test_scintillawrapper_void_int_colour_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_colour(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_position_position(self):
# Actually, in Scintilla source, changeLexerState doesn't officially return anything,
# other than an "always return 0", but Scintilla.iface has it as int, so we'll check it's a 0.
result = editor.changeLexerState(3,7)
self.assertEqual(result, 0)
# nothing else to check, just makes sure the call doesn't throw an error/deadlock
def callback_scintillawrapper_int_position_position(self, args):
self.test_scintillawrapper_int_position_position()
self.callbackCalled = True
def test_scintillawrapper_int_position_position_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_position_position(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write('0123456789')
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_int_int(self):
editor.write('line 1\r\nline 2\r\nline 3\r\nline 4\r\n')
handle = editor.markerAdd(2, 1)
self.assertNotEqual(handle, -1) # markerAdd() returns -1 if the line number is invalid or out of memory
editor.insertText(0, 'inserted line 1\r\n')
newLineNumber = editor.markerLineFromHandle(handle)
self.assertEqual(newLineNumber, 3)
def callback_scintillawrapper_int_int_int(self, args):
editor.clearCallbacks()
self.test_scintillawrapper_int_int_int()
self.callbackCalled = True
def test_scintillawrapper_int_int_int_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_int_int(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_keymod_int(self):
editor.assignCmdKey(77 | ((KEYMOD.ALT | KEYMOD.CTRL) << 16), SCINTILLAMESSAGE.SCI_COPYALLOWLINE)
# nothing to test
def callback_scintillawrapper_void_keymod_int(self, args):
editor.assignCmdKey(77 | ((KEYMOD.ALT | KEYMOD.CTRL) << 16), SCINTILLAMESSAGE.SCI_COPYALLOWLINE)
self.callbackCalled = True
def test_scintillawrapper_void_keymod_int_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_keymod_int(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_position_void_void(self):
editor.write("1234")
position = editor.getCurrentPos()
self.assertEqual(position, 4)
def callback_scintillawrapper_position_void_void(self, args):
if args["modificationType"] & MODIFICATIONFLAGS.INSERTTEXT == 0: # Ignore anything that isn't INSERTTEXT
return
editor.clearCallbacks()
editor.write("1234")
position = editor.getCurrentPos()
self.assertEqual(position, 8) # test1234|
self.callbackCalled = True
def test_scintillawrapper_position_void_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_position_void_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_string_stringresult(self):
editor.setProperty('pythonscript.unittest', 'test1234')
propertyValue = editor.getProperty('pythonscript.unittest')
self.assertEqual(propertyValue, 'test1234')
def callback_scintillawrapper_int_string_stringresult(self, args):
editor.setProperty('pythonscript.unittest', 'test1234')
propertyValue = editor.getProperty('pythonscript.unittest')
self.assertEqual(propertyValue, 'test1234')
self.callbackCalled = True
def test_scintillawrapper_int_string_stringresult_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_string_stringresult(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_position_bool(self):
editor.write('abcdef ghijkl mnopqrst')
wordStart = editor.wordStartPosition(10, False)
self.assertEqual(wordStart, 7)
def callback_scintillawrapper_int_position_bool(self, args):
editor.clearCallbacks()
editor.setText('abcdef ghijkl mnopqrst')
wordStart = editor.wordStartPosition(10, False)
self.assertEqual(wordStart, 7)
self.callbackCalled = True
def test_scintillawrapper_int_position_bool_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_position_bool(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_bool_void(self):
editor.setUndoCollection(False)
editor.emptyUndoBuffer() # recommended when disabling undo collection
editor.write('test_void_bool_void')
editor.setUndoCollection(True)
editor.undo()
afterUndoWithUndoDisabled = editor.getText()
# Now check undo is back on again
editor.write('extra')
beforeUndo = editor.getText()
editor.undo()
afterUndo = editor.getText()
self.assertEqual(afterUndoWithUndoDisabled, 'test_void_bool_void')
self.assertEqual(beforeUndo, 'test_void_bool_voidextra')
self.assertEqual(afterUndo, 'test_void_bool_void')
def callback_scintillawrapper_void_bool_void(self, args):
editor.clearCallbacks()
editor.setText('')
self.test_scintillawrapper_void_bool_void()
self.callbackCalled = True
def test_scintillawrapper_void_bool_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_bool_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_string(self):
editor.setText('abc123')
editor.gotoPos(3)
editor.addText('def')
resultText = editor.getText()
self.assertEqual(resultText, 'abcdef123')
def callback_scintillawrapper_void_int_string(self, args):
originalFontName = editor.styleGetFont(1)
editor.styleSetFont(1, 'Comic Sans MS') # what else?
newFontName = editor.styleGetFont(1)
editor.styleSetFont(1, originalFontName)
self.assertEqual(newFontName, 'Comic Sans MS')
# Check it wasn't already Comic Sans MS
self.assertNotEqual(originalFontName, newFontName)
self.callbackCalled = True
def test_scintillawrapper_void_int_string_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_string(args), [SCINTILLANOTIFICATION.MODIFIED])
original_mask = editor.getModEventMask()
editor.setModEventMask(MODIFICATIONFLAGS.INSERTTEXT)
editor.write("test")
self.poll_for_callback()
editor.setModEventMask(original_mask)
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_void_void(self):
editor.setText('12345')
length = editor.getLength()
self.assertEqual(length, 5)
def callback_scintillawrapper_int_void_void(self, args):
length = editor.getLength()
self.assertEqual(length, 5)
self.callbackCalled = True
def test_scintillawrapper_int_void_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_void_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("12345")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_position_int(self):
editor.setText('Hello world')
editor.setILexer(0)
editor.startStyling(0, 31)
editor.setStyling(5, 29)
styledText = editor.getStyledText(0, 5)
editor.setILexer(0)
self.assertEqual(styledText, ('Hello', [29, 29, 29, 29, 29]))
def callback_scintillawrapper_void_position_int(self, args):
editor.clearCallbacks()
self.test_scintillawrapper_void_position_int()
self.callbackCalled = True
def test_scintillawrapper_void_position_int_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_position_int(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_string_void(self):
editor.setProperty('pythonscript.unittest', '422')
result = editor.getPropertyInt('pythonscript.unittest', 0)
self.assertEqual(result, 422)
def callback_scintillawrapper_int_string_void(self, args):
self.test_scintillawrapper_int_string_void()
self.callbackCalled = True
def test_scintillawrapper_int_string_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_string_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_position_int_int(self):
editor.write('Hello World')
x = editor.pointXFromPosition(6) # X position of the W
y = editor.pointYFromPosition(6)
position = editor.positionFromPoint(x, y)
self.assertEqual(position, 6)
def callback_scintillawrapper_position_int_int(self, args):
x = editor.pointXFromPosition(6) # X position of the W
y = editor.pointYFromPosition(6)
position = editor.positionFromPoint(x, y)
self.assertEqual(position, 6)
self.callbackCalled = True
def test_scintillawrapper_position_int_int_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_position_int_int(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("Hello World")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_colour_void_void(self):
originalColour = editor.getCaretFore()
editor.setCaretFore((120, 130, 150))
newColour = editor.getCaretFore()
editor.setCaretFore(originalColour)
self.assertEqual(newColour, (120, 130, 150))
def callback_scintillawrapper_colour_void_void(self, args):
self.test_scintillawrapper_colour_void_void()
self.callbackCalled = True
def test_scintillawrapper_colour_void_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_colour_void_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_bool_void_void(self):
editor.setUndoCollection(True)
shouldBeTrue = editor.getUndoCollection()
editor.setUndoCollection(False)
shouldBeFalse = editor.getUndoCollection()
editor.setUndoCollection(True)
self.assertEqual(shouldBeTrue, True)
self.assertEqual(shouldBeFalse, False)
def callback_scintillawrapper_bool_void_void(self, args):
self.test_scintillawrapper_bool_void_void()
self.callbackCalled = True
def test_scintillawrapper_bool_void_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_bool_void_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
# There's a few of these tests for int_position_void, because they are key methods,
# and there's some odd return types (chars etc)
def test_scintillawrapper_int_position_void_getCharAt(self):
editor.write('Hello World\r\nCheese\r\nCheddar')
endOfHello = editor.getCharAt(4)
self.assertEqual(endOfHello, ord('o'))
def test_scintillawrapper_int_position_void_getColumn(self):
editor.write('Hello World\r\nCheese\r\nCheddar')
columnOfE = editor.getColumn(15) # the first 'e' in Cheese
self.assertEqual(columnOfE, 2)
def test_scintillawrapper_int_position_void_lineFromPosition(self):
editor.write('Hello World\r\nCheese\r\nCheddar')
lineOfCheddar = editor.lineFromPosition(24)
self.assertEqual(lineOfCheddar, 2)
def callback_scintillawrapper_int_position_void(self, args):
editor.clearCallbacks()
editor.setText('')
self.test_scintillawrapper_int_position_void_getColumn()
editor.setText('')
self.test_scintillawrapper_int_position_void_getCharAt()
editor.setText('')
self.test_scintillawrapper_int_position_void_lineFromPosition()
self.callbackCalled = True
def test_scintillawrapper_int_position_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_position_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
# self.poll_for_callback()
self.poll_for_callback()
def test_scintillawrapper_void_string_string(self):
editor.setProperty('pythonscript.unittest', 'void_string_string')
value = editor.getProperty('pythonscript.unittest')
editor.setProperty('pythonscript.unittest', '') # clear the property out again
self.assertEqual(value, 'void_string_string')
def callback_scintillawrapper_void_string_string(self, args):
self.test_scintillawrapper_void_string_string()
self.callbackCalled = True
def test_scintillawrapper_void_string_string_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_string_string(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_position_position(self):
editor.write('abc123 def456')
editor.copyRange(4, 10)
editor.paste()
text = editor.getText()
self.assertEqual(text, 'abc123 def45623 def')
def callback_scintillawrapper_void_position_position(self, args):
editor.clearCallbacks()
editor.setText('')
self.test_scintillawrapper_void_position_position()
self.callbackCalled = True
def test_scintillawrapper_void_position_position_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_position_position(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_bool_colour(self):
editor.setSelFore(True, (150,150,150))
editor.setSelFore(False, (0,0,0))
# nothing to test, we just check the command runs (there is no getSelFore())
def callback_scintillawrapper_void_bool_colour(self, args):
self.test_scintillawrapper_void_bool_colour()
self.callbackCalled = True
def test_scintillawrapper_void_bool_colour_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_bool_colour(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_position_position_void(self):
editor.write(u'äü')
result1 = editor.positionBefore(2)
result2 = editor.positionBefore(4)
# both chars are 2 bytes long, before(2) should 0, before(4) should be 2
self.assertEqual(result1, 0)
self.assertEqual(result2, 2)
def callback_scintillawrapper_position_position_void(self, args):
result1 = editor.positionBefore(2)
result2 = editor.positionBefore(4)
# both chars are 2 bytes long, before(2) should 0, before(4) should be 2
self.assertEqual(result1, 0)
self.assertEqual(result2, 2)
self.callbackCalled = True
def test_scintillawrapper_position_position_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_position_position_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write(u'äü')
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_keymod_void(self):
key = ((KEYMOD.SHIFT | KEYMOD.ALT | KEYMOD.ALT) << 16) | ord('P')
editor.assignCmdKey(key, SCINTILLAMESSAGE.SCI_COPYALLOWLINE)
editor.clearCmdKey(key)
def callback_scintillawrapper_void_keymod_void(self, args):
self.test_scintillawrapper_void_keymod_void()
self.callbackCalled = True
def test_scintillawrapper_void_keymod_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_keymod_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_void_void(self):
editor.write('Hello')
editor.write(' world')
before = editor.getText()
editor.clearAll()
after = editor.getText()
self.assertEqual(before, 'Hello world')
self.assertEqual(after, '')
def callback_scintillawrapper_void_void_void(self, args):
editor.clearCallbacks()
editor.setText('')
self.test_scintillawrapper_void_void_void()
self.callbackCalled = True
def test_scintillawrapper_void_void_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_void_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_int_stringresult_getCurLine(self):
editor.write('One\r\nTwo\r\nThree\r\n')
editor.gotoPos(6)
line = editor.getCurLine()
self.assertEqual(line, 'Two\r\n')
def test_scintillawrapper_int_int_stringresult_getLine(self):
editor.write('One\r\nTwo\r\nThree')
lineTwo = editor.getLine(1)
lineThree = editor.getLine(2)
self.assertEqual(lineTwo, 'Two\r\n')
self.assertEqual(lineThree, 'Three')
def test_scintillawrapper_int_int_stringresult_styleGetFont(self):
originalFontName = editor.styleGetFont(31)
editor.styleSetFont(31, 'Comic Sans MS')
fontName = editor.styleGetFont(31)
editor.styleSetFont(31, originalFontName)
self.assertEqual(fontName, 'Comic Sans MS')
self.assertNotEqual(originalFontName, fontName) # we assume no-one uses Comic Sans MS, but just in case...
def callback_scintillawrapper_int_int_stringresult_styleGetFont(self, args):
self.test_scintillawrapper_int_int_stringresult_styleGetFont()
self.callbackCalled = True
def test_scintillawrapper_int_int_stringresult_in_callback_styleGetFont(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_int_stringresult_styleGetFont(args), [SCINTILLANOTIFICATION.MODIFIED])
original_mask = editor.getModEventMask()
editor.setModEventMask(MODIFICATIONFLAGS.INSERTTEXT)
editor.write("test")
self.poll_for_callback()
editor.setModEventMask(original_mask)
self.assertEqual(self.callbackCalled, True)
def callback_scintillawrapper_int_int_stringresult_getLine(self, args):
lineTwo = editor.getLine(1)
lineThree = editor.getLine(2)
self.assertEqual(lineTwo, 'Two\r\n')
self.assertEqual(lineThree, 'Three')
self.callbackCalled = True
def test_scintillawrapper_int_int_stringresult_in_callback_getLine(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_int_stringresult_getLine(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("One\r\nTwo\r\nThree")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def callback_scintillawrapper_int_int_stringresult_getCurLine(self, args):
editor.gotoPos(6)
line = editor.getCurLine()
self.assertEqual(line, 'Two\r\n')
self.callbackCalled = True
def test_scintillawrapper_int_int_stringresult_in_callback_getCurLine(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_int_stringresult_getCurLine(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("One\r\nTwo\r\nThree")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_colour_void(self):
originalColour = editor.getCaretFore()
editor.setCaretFore((255,0,0))
newColour = editor.getCaretFore()
editor.setCaretFore(originalColour)
self.assertEqual(newColour, (255, 0, 0))
def callback_scintillawrapper_void_colour_void(self, args):
self.test_scintillawrapper_void_colour_void()
self.callbackCalled = True
def test_scintillawrapper_void_colour_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_colour_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_bool(self):
original = editor.styleGetBold(31)
editor.styleSetBold(31, True)
shouldBeTrue = editor.styleGetBold(31)
editor.styleSetBold(31, False)
shouldBeFalse = editor.styleGetBold(31)
editor.styleSetBold(31, original)
self.assertEqual(shouldBeTrue, True)
self.assertEqual(shouldBeFalse, False)
def callback_scintillawrapper_void_int_bool(self, args):
self.test_scintillawrapper_void_int_bool()
self.callbackCalled = True
def test_scintillawrapper_void_int_bool_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_bool(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_int_void(self):
editor.write('One\r\nTwo\r\nThree\r\nFour')
handle = editor.markerAdd(3, 4) # Add marker 4 at line 3
beforeMoveMarker = editor.markerGet(3)
editor.insertText(0, 'Add a line\r\n')
afterMove3 = editor.markerGet(3)
afterMove4 = editor.markerGet(4)
lineNumber = editor.markerLineFromHandle(handle)
self.assertEqual(beforeMoveMarker & 0x10, 0x10) # marker 4 is 0x10, and there could be other markers on the line
self.assertEqual(afterMove3 & 0x10, 0) # after the insert, line 3 should not contain the marker
self.assertEqual(afterMove4 & 0x10, 0x10) # it should be on line 4
self.assertEqual(lineNumber, 4) # The lineNumber obtained from the handle, should also be 4
def callback_scintillawrapper_int_int_void(self, args):
editor.clearCallbacks()
editor.clearAll()
self.test_scintillawrapper_int_int_void()
self.callbackCalled = True
def test_scintillawrapper_int_int_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_int_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_position_void(self):
editor.write('Hello world 12356')
editor.gotoPos(6)
afterGotoPos = editor.getCurrentPos()
editor.setCurrentPos(10)
afterSetCurrentPos = editor.getCurrentPos()
self.assertEqual(afterGotoPos, 6)
self.assertEqual(afterSetCurrentPos, 10)
def callback_scintillawrapper_void_position_void(self, args):
editor.clearCallbacks()
self.test_scintillawrapper_void_position_void()
self.callbackCalled = True
def test_scintillawrapper_void_position_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_position_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_position_int_void(self):
editor.write('Hello\r\n\t World')
indentPosition = editor.getLineIndentPosition(1)
self.assertEqual(indentPosition, 12)
def callback_scintillawrapper_position_int_void(self, args):
indentPosition = editor.getLineIndentPosition(1)
self.assertEqual(indentPosition, 12)
self.callbackCalled = True
def test_scintillawrapper_position_int_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_position_int_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write('Hello\r\n\t World')
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_position_int_findtext(self):
editor.write('ac123 def456\r\nghi11111 xl45')
result = editor.findText(FINDOPTION.REGEXP, 0, 30, '[a-z]{3}[0-9]{3}')
self.assertEqual(result, (6, 12))
def callback_scintillawrapper_position_int_findtext(self, args):
result = editor.findText(FINDOPTION.REGEXP, 0, 30, '[a-z]{3}[0-9]{3}')
self.assertEqual(result, (6, 12))
self.callbackCalled = True
def test_scintillawrapper_position_int_findtext_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_position_int_findtext(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write('ac123 def456\r\nghi11111 xl45')
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_colour_int_void(self):
original = editor.styleGetFore(4)
editor.styleSetFore(4, (191, 195, 198))
replaced = editor.styleGetFore(4)
editor.styleSetFore(4, original)
self.assertEqual(replaced, (191, 195, 198))
def callback_scintillawrapper_colour_int_void(self, args):
self.test_scintillawrapper_colour_int_void()
self.callbackCalled = True
def test_scintillawrapper_colour_int_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_colour_int_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_bool_int_void(self):
_ = editor.getMarginSensitiveN(1)
editor.setMarginSensitiveN(1, True)
shouldBeTrue = editor.getMarginSensitiveN(1)
editor.setMarginSensitiveN(1, False)
shouldBeFalse = editor.getMarginSensitiveN(1)
self.assertEqual(shouldBeTrue, True)
self.assertEqual(shouldBeFalse, False)
def callback_scintillawrapper_bool_int_void(self, args):
self.test_scintillawrapper_bool_int_void()
self.callbackCalled = True
def test_scintillawrapper_bool_int_void_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_bool_int_void(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_void_string_lexerLanguage(self):
_ = editor.getLexerLanguage()
#TODO check if a corresponding set could be achieved via menu or notpad object: editor.setLexerLanguage('python')
notepad.setLangType(LANGTYPE.PYTHON)
python = editor.getLexerLanguage()
self.assertEqual(python, 'python')
def callback_scintillawrapper_void_void_string_lexerLanguage(self, args):
self.test_scintillawrapper_void_void_string_lexerLanguage()
self.callbackCalled = True
def test_scintillawrapper_void_void_string_in_callback_lexerLanguage(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_void_string_lexerLanguage(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_void_string(self):
editor.setWordChars('dummy_input')
originalWordChars = editor.getWordChars()
editor.setWordChars('abcdefghijklmnop')
changedWordChars = editor.getWordChars()
editor.setWordChars(originalWordChars)
for ch in changedWordChars:
self.assertIn(ch, 'abcdefghijklmnop')
self.assertEqual(len(changedWordChars), len('abcdefghijklmnop'))
def callback_scintillawrapper_void_void_string(self, args):
self.test_scintillawrapper_void_void_string()
self.callbackCalled = True
def test_scintillawrapper_void_void_string_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_void_string(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_void_stringresult(self):
editor.write('abc123 def456 ghi789')
editor.setSel(7, 13)
text = editor.getSelText()
self.assertEqual(text, 'def456')
def callback_scintillawrapper_int_void_stringresult(self, args):
editor.clearCallbacks()
editor.setSel(7, 13)
text = editor.getSelText()
self.assertEqual(text, 'def456')
self.callbackCalled = True
def test_scintillawrapper_int_void_stringresult_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_void_stringresult(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write('abc123 def456 ghi789')
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_int_void_position(self):
# This test is actually identical to position_int_int
# That test is for positionFromPoint(), this is for pointXFromPosition()
# I'm leaving this in, so we've definitely got a covering test for int_void_position
editor.write('Hello World')
x = editor.pointXFromPosition(6) # X position of the W
y = editor.pointYFromPosition(6)
position = editor.positionFromPoint(x, y)
self.assertEqual(position, 6)
def callback_scintillawrapper_int_void_position(self, args):
x = editor.pointXFromPosition(6) # X position of the W
y = editor.pointYFromPosition(6)
position = editor.positionFromPoint(x, y)
self.assertEqual(position, 6)
self.callbackCalled = True
def test_scintillawrapper_int_void_position_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_int_void_position(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("Hello World")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_position(self):
editor.write('abc123 def456 ghi789 jk12 lmnop3456')
editor.setSel(7, 13)
editor.addSelection(14, 20)
editor.setSelectionNCaret(1, 16)
editor.setSelectionNAnchor(1, 18)
# Note: Do not attempt to call setSelectionNCaret on a selection that doesn't exist - it causes a crash.
# Always call addSelection first
caret = editor.getSelectionNCaret(1)
anchor = editor.getSelectionNAnchor(1)
self.assertEqual(caret, 16)
self.assertEqual(anchor, 18)
def callback_scintillawrapper_void_int_position(self, args):
editor.clearCallbacks()
self.test_scintillawrapper_void_int_position()
self.callbackCalled = True
def test_scintillawrapper_void_int_position_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_position(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_scintillawrapper_void_int_int(self):
editor.write('One\r\nTwo\r\nThree\r\nFour')
editor.markerAddSet(2, 0x11) # marker 4 (0x10) and 0 (0x01) on line 2
markersBeforeMove = editor.markerGet(2)
editor.insertText(0, 'Inserted\r\n')
markersAfterMove = editor.markerGet(2)
markersAfterMoveLine3 = editor.markerGet(3)
#see change history markers https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12046
#e.g. SC_MARKNUM_HISTORY_MODIFIED 23
#which need to be combined with the markers set above
self.assertEqual(markersBeforeMove, 0x800011)
self.assertEqual(markersAfterMove, 0x800000)
self.assertEqual(markersAfterMoveLine3, 0x800011)
def callback_scintillawrapper_void_int_int(self, args):
editor.clearCallbacks()
self.test_scintillawrapper_void_int_int()
self.callbackCalled = True
def test_scintillawrapper_void_int_int_in_callback(self):
editor.callback(lambda args: self.callback_scintillawrapper_void_int_int(args), [SCINTILLANOTIFICATION.MODIFIED])
editor.write("test")
self.poll_for_callback()
self.assertEqual(self.callbackCalled, True)
def test_annotationSetText_as_text(self):
editor.write('One\r\nTwo\r\nThree')
editor.annotationSetText(1, 'This is line two')
text = editor.annotationGetText(1)
self.assertEqual(text, 'This is line two')
def test_annotationSetText_clear(self):
editor.write('One\r\nTwo\r\nThree')
editor.annotationSetText(1, 'This is line two')
before = editor.annotationGetText(1)
editor.annotationSetText(1, None)
after = editor.annotationGetText(1)
self.assertEqual(before, 'This is line two')
self.assertEqual(after, '')
def test_getRangePointer(self):
editor.write('Hello world')
rangeText = editor.getRangePointer(3, 5)
self.assertEqual(rangeText, 'lo wo')
def test_getCharacterPointer(self):
editor.write('Hello world char pointer')
text = editor.getCharacterPointer()
self.assertEqual(text, 'Hello world char pointer')
def test_deleteLine_with_contents(self):
editor.write('Line 1\r\nLine 2\r\nLine 3\r\n')
editor.deleteLine(1)
text = editor.getText()
self.assertEqual(text, 'Line 1\r\nLine 3\r\n')
def test_deleteLine_middle_no_contents(self):
editor.write('Line 1\r\n\r\nLine 3\r\n')
editor.deleteLine(1)
text = editor.getText()
self.assertEqual(text, 'Line 1\r\nLine 3\r\n')