From 716a40773f79d72b93a0fc88ca1502a7d58703fe Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 22 Jul 2013 11:41:14 -0500 Subject: [PATCH] adjust backward-containing-sexp so that it returns #f when there is no containing paren it used to return the beginning of the region (usually 0) (this adjusts backward-containing-sexp to agree with the docs) original commit: e1f4547ea99200c6ad0e9c34a76d3eb19eb906b6 --- .../gui-lib/framework/private/color.rkt | 8 +++++--- .../gui-test/framework/tests/racket.rkt | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt b/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt index ec00fcbd..71461487 100644 --- a/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt +++ b/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt @@ -825,7 +825,7 @@ added get-regions (define/public (backward-match position cutoff) (let ((x (internal-backward-match position cutoff))) (cond - ((eq? x 'open) #f) + ((or (eq? x 'open) (eq? x 'beginning)) #f) (else x)))) (define/private (internal-backward-match position cutoff) @@ -855,9 +855,10 @@ added get-regions (values (send (lexer-state-tokens ls) get-root-start-position) (send (lexer-state-tokens ls) get-root-end-position))))) (cond - ((or (send (lexer-state-parens ls) is-open-pos? tok-start) - (= (+ start-pos tok-start) position)) + ((send (lexer-state-parens ls) is-open-pos? tok-start) 'open) + ((= (+ start-pos tok-start) position) + 'beginning) (else (+ start-pos tok-start)))))))))) @@ -874,6 +875,7 @@ added get-regions ;; the docs seem to indicate it ;; does, but it doesn't really cur-pos) + ((eq? 'beginning p) #f) ((not p) #f) (else (loop p)))))) diff --git a/pkgs/gui-pkgs/gui-test/framework/tests/racket.rkt b/pkgs/gui-pkgs/gui-test/framework/tests/racket.rkt index 4502fe48..fa3f9022 100644 --- a/pkgs/gui-pkgs/gui-test/framework/tests/racket.rkt +++ b/pkgs/gui-pkgs/gui-test/framework/tests/racket.rkt @@ -94,7 +94,9 @@ (test-magic-square-bracket 'local2 "(local [(define x 1)] " "(local [(define x 1)] (") -(define (test-message-send/proc line before after pos msg . args) +(define (test-message-send/proc line before expected pos msg + #:check-result? [check-result? #f] + . args) (define (maybe-quote x) (cond [(or (number? x) (boolean? x) (string? x)) x] @@ -103,7 +105,7 @@ (string->symbol (format "line ~a: ~s" line `(,msg ,@(map maybe-quote args)))) - (λ (x) (equal? x after)) + (λ (x) (equal? x expected)) (λ () (queue-sexp-to-mred `(let () @@ -112,13 +114,15 @@ (define ec (new editor-canvas% [parent f] [editor t])) (send t insert ,before) (send t set-position ,pos) - (send t ,msg ,@(map maybe-quote args)) - (send t get-text)))))) + (define ans (send t ,msg ,@(map maybe-quote args))) + ,(if check-result? + 'ans + '(send t get-text))))))) (define-syntax (test-message-send stx) (syntax-case stx () - [(_ before after pos mth . args) + [(_ before expected pos mth . args) (with-syntax ([line (syntax-line stx)]) - #'(test-message-send/proc line before after pos 'mth . args))])) + #'(test-message-send/proc line before expected pos 'mth . args))])) (test-message-send "" "]" 0 insert-close-paren 0 #\] #t #t 'adjacent) (test-message-send "" "]" 0 insert-close-paren 0 #\] #t #t #f) @@ -131,6 +135,8 @@ (test-message-send "()" "" 1 kill-enclosing-parens 1) (test-message-send "(1\n 2\n 3)" "1\n2\n3" 1 kill-enclosing-parens 1) ;; test tabify call +(test-message-send "abc" #f 1 backward-containing-sexp #:check-result? #t 1 3) + ;; tests what happens when a given key/s is/are typed in an editor with initial ;; text and cursor position, under different settings of the auto-parentheses and ;; smart-skip-parentheses preferences .nah.