From 269e2f583c4ff5d7906d7c02db04b4d029d396da Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 27 Oct 2014 17:21:24 -0500 Subject: [PATCH] move find-string tests into the wxme test suite original commit: 6d4b708851cd0a16d7e476746ef1c66a2665bb8b --- pkgs/gui-pkgs/gui-test/tests/gracket/wxme.rkt | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/pkgs/gui-pkgs/gui-test/tests/gracket/wxme.rkt b/pkgs/gui-pkgs/gui-test/tests/gracket/wxme.rkt index 583fa56e..4666e063 100644 --- a/pkgs/gui-pkgs/gui-test/tests/gracket/wxme.rkt +++ b/pkgs/gui-pkgs/gui-test/tests/gracket/wxme.rkt @@ -356,6 +356,144 @@ (expect (send t find-next-non-string-snip #f) #f) +(let () + (define (txt s) + (define t (new text%)) + (send t insert s) + (send t set-position 0 0) + t) + (define (kmp-search txt str all?) + (send txt do-find-string-all str 'forward 0 (send txt last-position) (not all?) #t #t #f)) + + (expect (kmp-search (txt "x") "x" #f) 0) + (expect (kmp-search (txt "yx") "x" #f) 1) + (expect (kmp-search (txt "yx") "yx" #f) 0) + (expect (kmp-search (txt "zyx") "yx" #f) 1) + (expect (kmp-search (txt "yyx") "yx" #f) 1) + (expect (kmp-search (txt "qqq") "yx" #f) #f) + (expect (kmp-search (txt "ABC ABCDAB ABCDABCDABDE") "ABCDABD" #f) 15) + (expect (kmp-search (txt "xxxx") "y" #t) '()) + (expect (kmp-search (txt "xxxx") "x" #t) '(0 1 2 3)) + (expect (kmp-search (txt "xyxy") "x" #t) '(0 2)) + (expect (kmp-search (txt " x\n ") "x" #t) '(1)) + (expect (kmp-search (txt "") "x" #t) '()) + (expect (send (txt " x\n ") do-find-string-all "X" 'forward 0 'eof #f #t #f #f) + '(1)) + (expect (send (txt "xXxXxX") do-find-string-all "x" 'forward 0 'eof #f #t #f #f) + '(0 1 2 3 4 5)) + (expect (send (txt "xXxXxX") do-find-string-all "x" 'forward 2 4 #f #t #f #f) + '(2 3)) + (expect (send (txt "xyxyxyxyxyx") do-find-string-all "xy" 'forward 2 5 #f #t #t #f) + '(2)) + (expect (send (txt "abcdabcdabcd") do-find-string-all "abcd" 'forward 0 'eof #f #f #t #f) + '(4 8 12)) + (expect (send (txt "qqabcdabcdabcd") do-find-string-all "abcd" 'forward 0 'eof #t #f #t #f) + 6) + (expect (send (txt "qqabcdabcdabcd") do-find-string-all "abcd" 'forward 0 'eof #t #t #t #f) + 2) + (expect (send (txt "abcdabcdabcd") do-find-string-all "abcd" 'backward 12 0 #f #t #t #f) + '(12 8 4)) + (expect (send (txt "abcdabcdabcd") do-find-string-all "abcd" 'backward 12 0 #f #f #t #f) + '(8 4 0)) + (expect (send (txt "abcd\nabcdabcd") do-find-string-all "abcd" 'backward 12 0 #f #t #t #f) + '(9 4)) + (expect (send (txt "abcd\nabcdabcd") do-find-string-all "abcd" 'backward 13 0 #f #t #t #f) + '(13 9 4)) + (expect (send (txt "abcdabcd\nabcd") do-find-string-all "abcd" 'backward 12 0 #f #t #t #f) + '(8 4)) + (expect (send (txt "abcdabcd\nabcd") do-find-string-all "abcd" 'backward 13 0 #f #t #t #f) + '(13 8 4)) + (expect (send (txt "abcdabcd\nabcd") do-find-string-all "abcd" 'backward 8 0 #f #t #t #f) + '(8 4)) + (expect (send (txt "abcdabcd\nabcd") do-find-string-all "abcd" 'forward 4 13 #f #t #t #f) + '(4 9)) + (expect (send (txt "xyz") do-find-string-all "xyz" 'backward 3 0 #t #f #t #f) + 0) + (expect (send (txt "xyz") do-find-string-all "xyz" 'backward 3 0 #t #t #t #f) + 3) + + (let ([t1 (new text%)] + [t2 (new text%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor t2])) + (send t1 insert "abc") + (send t2 insert "abc") + (expect (send t1 do-find-string-all "abc" 'forward 0 (send t1 last-position) #f #t #t #t) + (list 0 (list t2 0) 4))) + + (let ([t1 (new text%)] + [t2 (new text%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor t2])) + (send t1 insert "abc") + (send t2 insert "abc") + (expect (send t1 do-find-string-all "abc" 'backward (send t1 last-position) 0 #f #t #t #t) + (list 7 (list t2 3) 3))) + + (let ([t1 (new text%)] + [t2 (new text%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor t2])) + (send t1 insert "abcd") + (send t2 insert "abc") + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #t #t #t #t) + 4)) + + (let ([t1 (new text%)] + [t2 (new text%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor t2])) + (send t1 insert "abc") + (send t2 insert "abcd") + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #t #t #t #t) + (cons t2 0))) + + (let ([t1 (new text%)] + [t2 (new text%)] + [pb (new pasteboard%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor pb])) + (send pb insert (new editor-snip% [editor t2])) + (send t1 insert "abc") + (send t2 insert "abcd") + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #t #t #t #t) + (list* pb t2 0))) + + (let ([t1 (new text%)] + [t2 (new text%)] + [t3 (new text%)] + [pb (new pasteboard%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor pb])) + (send pb insert (new editor-snip% [editor t2])) + (send pb insert (new editor-snip% [editor t3])) + (send t1 insert "abc") + (send t2 insert "abcd") + (send t3 insert "abcd") + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #f #t #t #t) + (list (list pb (list t2 0) (list t3 0))))) + + (let ([t1 (new text%)]) + (send t1 insert "abc") + (define es (new editor-snip%)) + (send t1 insert es) + (send t1 insert "abc") + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #f #t #t #t) + '())) + + (let ([t1 (new text%)] + [pb (new pasteboard%)]) + (send t1 insert "abc") + (send t1 insert (new editor-snip% [editor pb])) + (send t1 insert "abc") + (send pb insert (new editor-snip%)) + (send pb insert (new editor-snip%)) + (expect (send t1 do-find-string-all "abcd" 'forward 0 (send t1 last-position) #f #t #t #t) + '())) + + (expect (send (txt "aaa") find-string-all "a") '(0 1 2))) + + ;; ---------------------------------------- ;; Insert very long strings to test max-string-length handling