Skip to content

Commit 74b0e4c

Browse files
Automated Resyntax fixes (#737)
* Fix 3 occurrences of `send-chain-to-send+` This method chain made of nested `send` expressions can be written more clearly as a `send+` expression. * Fix 1 occurrence of `hash-set!-ref-to-hash-update!` This expression can be replaced with a simpler, equivalent `hash-update!` expression. * Fix 1 occurrence of `unless-expression-in-for-loop-to-unless-keyword` Use the `#:unless` keyword instead of `unless` to reduce loop body indentation. * Fix 1 occurrence of `hash-for-each-to-for` This `hash-for-each` operation can be replaced with a `for` loop. * Fix 2 occurrences of `if-let-to-cond` `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting * Fix 10 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Fix 1 occurrence of `sort-with-keyed-comparator-to-sort-by-key` This `sort` expression can be replaced with a simpler, equivalent expression. * Fix 1 occurrence of `if-then-true-else-false-to-condition` The condition of this `if` expression is already a boolean and can be used directly. --------- Co-authored-by: resyntax-ci[bot] <181813515+resyntax-ci[bot]@users.noreply.github.com>
1 parent 74c174d commit 74b0e4c

File tree

4 files changed

+179
-183
lines changed

4 files changed

+179
-183
lines changed

drracket-test/tests/drracket/language-test.rkt

+78-84
Original file line numberDiff line numberDiff line change
@@ -1532,11 +1532,11 @@ the settings above should match r5rs
15321532

15331533

15341534
(define (prepare-for-test-expression)
1535-
(let ([drs (wait-for-drracket-frame)])
1536-
(clear-definitions drs)
1537-
(set-language #t)
1538-
(sleep 1) ;; this shouldn't be neccessary....
1539-
(do-execute drs)))
1535+
(define drs (wait-for-drracket-frame))
1536+
(clear-definitions drs)
1537+
(set-language #t)
1538+
(sleep 1) ;; this shouldn't be neccessary....
1539+
(do-execute drs))
15401540

15411541
;; test-setting : (-> void) string string string -> void
15421542
;; opens the language dialog, runs `set-setting'
@@ -1552,34 +1552,37 @@ the settings above should match r5rs
15521552
(let ([f (test:get-active-top-level-window)])
15531553
(fw:test:button-push "OK")
15541554
(wait-for-new-frame f))
1555-
(let* ([drs (test:get-active-top-level-window)]
1556-
[interactions (send drs get-interactions-text)])
1557-
(clear-definitions drs)
1558-
(insert-in-definitions drs expression)
1559-
(do-execute drs)
1560-
(when interactions-expr
1561-
(insert-in-interactions drs interactions-expr)
1562-
(alt-return-in-interactions drs)
1563-
(wait-for-computation drs))
1564-
(let* ([got (fetch-output/should-be-tested drs)])
1565-
(unless (if (regexp? result)
1566-
(regexp-match? result got)
1567-
(string=? result got))
1568-
(eprintf "FAILED: ~s ~s ~s test\n expected: ~s\n got: ~s\n"
1569-
(language) setting-name expression result got)))))
1555+
(define drs (test:get-active-top-level-window))
1556+
(send drs get-interactions-text)
1557+
(clear-definitions drs)
1558+
(insert-in-definitions drs expression)
1559+
(do-execute drs)
1560+
(when interactions-expr
1561+
(insert-in-interactions drs interactions-expr)
1562+
(alt-return-in-interactions drs)
1563+
(wait-for-computation drs))
1564+
(define got (fetch-output/should-be-tested drs))
1565+
(unless (if (regexp? result)
1566+
(regexp-match? result got)
1567+
(string=? result got))
1568+
(eprintf "FAILED: ~s ~s ~s test\n expected: ~s\n got: ~s\n"
1569+
(language)
1570+
setting-name
1571+
expression
1572+
result
1573+
got)))
15701574

15711575
(define (test-hash-bang)
1572-
(let* ([expression "#!/bin/sh\n1"]
1573-
[result "1"]
1574-
[drs (test:get-active-top-level-window)]
1575-
[interactions (queue-callback (λ () (send drs get-interactions-text)))])
1576-
(clear-definitions drs)
1577-
(insert-in-definitions drs expression)
1578-
(do-execute drs)
1579-
(let* ([got (fetch-output/should-be-tested drs)])
1580-
(unless (string=? "1" got)
1581-
(eprintf "FAILED: ~s ~a test\n expected: ~s\n got: ~s\n"
1582-
(language) expression result got)))))
1576+
(define expression "#!/bin/sh\n1")
1577+
(define result "1")
1578+
(define drs (test:get-active-top-level-window))
1579+
(queue-callback (λ () (send drs get-interactions-text)))
1580+
(clear-definitions drs)
1581+
(insert-in-definitions drs expression)
1582+
(do-execute drs)
1583+
(define got (fetch-output/should-be-tested drs))
1584+
(unless (string=? "1" got)
1585+
(eprintf "FAILED: ~s ~a test\n expected: ~s\n got: ~s\n" (language) expression result got)))
15831586

15841587
(define (fetch-output/should-be-tested . args)
15851588
(regexp-replace (regexp
@@ -1683,13 +1686,13 @@ the settings above should match r5rs
16831686
(when (and has-sharing? show-sharing)
16841687
(fw:test:set-check-box!
16851688
"Show sharing in values"
1686-
(if (eq? show-sharing 'on) #t #f)))
1689+
(eq? show-sharing 'on)))
16871690
(fw:test:set-check-box!
16881691
"Insert newlines in printed values"
16891692
pretty?)
1690-
(let ([f (test:get-active-top-level-window)])
1691-
(fw:test:button-push "OK")
1692-
(wait-for-new-frame f)))
1693+
(define f (test:get-active-top-level-window))
1694+
(fw:test:button-push "OK")
1695+
(wait-for-new-frame f))
16931696
(define (shorten str)
16941697
(if ((string-length str) . <= . 45)
16951698
str
@@ -1774,15 +1777,14 @@ the settings above should match r5rs
17741777
(unless (member #\newline (string->list got))
17751778
(eprintf "long output should have contained newlines, got ~s\n" got)))
17761779

1777-
(let ()
1778-
(clear-definitions drr)
1779-
(insert-in-definitions drr (defs-prefix))
1780-
(insert-in-definitions drr "(print-value-columns 1000)")
1781-
(insert-in-definitions drr "(build-list 100 values)")
1782-
(do-execute drr)
1783-
(define got (fetch-output/should-be-tested drr))
1784-
(when (member #\newline (string->list got))
1785-
(eprintf "long output should not have contained newlines, got ~s\n" got)))))
1780+
(clear-definitions drr)
1781+
(insert-in-definitions drr (defs-prefix))
1782+
(insert-in-definitions drr "(print-value-columns 1000)")
1783+
(insert-in-definitions drr "(build-list 100 values)")
1784+
(do-execute drr)
1785+
(define got (fetch-output/should-be-tested drr))
1786+
(when (member #\newline (string->list got))
1787+
(eprintf "long output should not have contained newlines, got ~s\n" got))))
17861788

17871789
(define (find-output-radio-box label)
17881790
(define frame (test:get-active-top-level-window))
@@ -1818,26 +1820,24 @@ the settings above should match r5rs
18181820
"WARNING: Interactions window is out of sync with the definitions window\\."))
18191821

18201822
(define (test-error-after-definition)
1821-
(let* ([drs (wait-for-drracket-frame)]
1822-
[interactions-text (queue-callback/res (λ () (send drs get-interactions-text)))])
1823-
(clear-definitions drs)
1824-
(insert-in-definitions drs (defs-prefix))
1825-
(insert-in-definitions drs "(define y 0) (define (f x) (/ x y)) (f 2)")
1826-
(do-execute drs)
1827-
(let ([last-para (queue-callback/res (λ () (send interactions-text last-paragraph)))])
1828-
(type-in-interactions drs "y\n")
1829-
(wait-for-computation drs)
1830-
(let ([got
1831-
(fetch-output/should-be-tested
1832-
drs
1833-
(queue-callback/res
1834-
(λ () (send interactions-text paragraph-start-position (+ last-para 1))))
1835-
(queue-callback/res
1836-
(λ ()
1837-
(send interactions-text paragraph-end-position
1838-
(- (send interactions-text last-paragraph) 1)))))])
1839-
(unless (equal? got "0")
1840-
(eprintf "FAILED: test-error-after-definition failed, expected 0, got ~s\n" got))))))
1823+
(define drs (wait-for-drracket-frame))
1824+
(define interactions-text (queue-callback/res (λ () (send drs get-interactions-text))))
1825+
(clear-definitions drs)
1826+
(insert-in-definitions drs (defs-prefix))
1827+
(insert-in-definitions drs "(define y 0) (define (f x) (/ x y)) (f 2)")
1828+
(do-execute drs)
1829+
(define last-para (queue-callback/res (λ () (send interactions-text last-paragraph))))
1830+
(type-in-interactions drs "y\n")
1831+
(wait-for-computation drs)
1832+
(define got
1833+
(fetch-output/should-be-tested
1834+
drs
1835+
(queue-callback/res (λ () (send interactions-text paragraph-start-position (+ last-para 1))))
1836+
(queue-callback/res (λ ()
1837+
(send interactions-text paragraph-end-position
1838+
(- (send interactions-text last-paragraph) 1))))))
1839+
(unless (equal? got "0")
1840+
(eprintf "FAILED: test-error-after-definition failed, expected 0, got ~s\n" got)))
18411841

18421842

18431843
;; test-expression : (union string 'xml 'image (listof (union string 'xml 'image)))
@@ -1915,26 +1915,20 @@ the settings above should match r5rs
19151915
(send interactions-text last-position))
19161916
(send interactions-text paste))))
19171917

1918-
(let ([last-para (queue-callback/res (λ () (send interactions-text last-paragraph)))])
1919-
(alt-return-in-interactions drs)
1920-
(wait-for-computation drs)
1921-
(let ([got
1922-
(fetch-output
1923-
drs
1924-
(queue-callback/res
1925-
(λ ()
1926-
(send interactions-text paragraph-start-position (+ last-para 1))))
1927-
(queue-callback/res
1928-
(λ ()
1929-
(send interactions-text paragraph-end-position
1930-
(- (send interactions-text last-paragraph) 1)))))])
1931-
(when (regexp-match re:out-of-sync got)
1932-
(error 'text-expression "got out of sync message"))
1933-
(unless (check-expectation repl-expected got)
1934-
(eprintf (make-err-msg repl-expected)
1935-
'interactions
1936-
(language)
1937-
expression repl-expected got))))))
1918+
(define last-para (queue-callback/res (λ () (send interactions-text last-paragraph))))
1919+
(alt-return-in-interactions drs)
1920+
(wait-for-computation drs)
1921+
(define got
1922+
(fetch-output
1923+
drs
1924+
(queue-callback/res (λ () (send interactions-text paragraph-start-position (+ last-para 1))))
1925+
(queue-callback/res (λ ()
1926+
(send interactions-text paragraph-end-position
1927+
(- (send interactions-text last-paragraph) 1))))))
1928+
(when (regexp-match re:out-of-sync got)
1929+
(error 'text-expression "got out of sync message"))
1930+
(unless (check-expectation repl-expected got)
1931+
(eprintf (make-err-msg repl-expected) 'interactions (language) expression repl-expected got))))
19381932

19391933
(define (test-undefined-var id #:icon+in? [icon+in? #f])
19401934
(test-expression

drracket-test/tests/drracket/no-write-and-frame-leak.rkt

+16-14
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ This test checks:
6363
(sync (system-idle-evt))
6464

6565
(define drs-tabb (make-weak-box (send drs-frame1 get-current-tab)))
66-
(define tab-nsb (make-weak-box (send (send (send drs-frame1 get-current-tab) get-ints)
67-
get-user-namespace)))
66+
(define tab-nsb (make-weak-box (send+ drs-frame1
67+
(get-current-tab)
68+
(get-ints)
69+
(get-user-namespace))))
6870

6971
(test:menu-select "File" (if (eq? (system-type) 'unix) "Close" "Close Tab"))
7072
(sync (system-idle-evt))
@@ -74,12 +76,16 @@ This test checks:
7476

7577
(define drs-frame2b (make-weak-box (wait-for-new-frame drs-frame1)))
7678
(define frame2-nsb (make-weak-box
77-
(send (send (send (weak-box-value drs-frame2b) get-current-tab) get-ints)
78-
get-user-namespace)))
79+
(send+ (weak-box-value drs-frame2b)
80+
(get-current-tab)
81+
(get-ints)
82+
(get-user-namespace))))
7983

8084
(queue-callback/res
81-
(λ () (send (send (send (weak-box-value drs-frame2b) get-current-tab) get-defs) load-file
82-
(collection-file-path "rep.rkt" "drracket" "private"))))
85+
(λ () (send+ (weak-box-value drs-frame2b)
86+
(get-current-tab)
87+
(get-defs)
88+
(load-file (collection-file-path "rep.rkt" "drracket" "private")))))
8389
(sleep 2)
8490
(extra-waiting (weak-box-value drs-frame2b))
8591
(sync (system-idle-evt))
@@ -139,10 +145,7 @@ This test checks:
139145
string<=?
140146
#:key symbol->string)
141147
(list (send item get-shortcut))))
142-
(hash-set! shortcuts
143-
k
144-
(cons (send item get-label)
145-
(hash-ref shortcuts k '()))))))
148+
(hash-update! shortcuts k (λ (v) (cons (send item get-label) v)) '()))))
146149

147150
(define (get-lab item)
148151
(cond
@@ -162,10 +165,9 @@ This test checks:
162165
'()])))
163166

164167
(define (check-shortcuts)
165-
(for ([(k v) (in-hash shortcuts)])
166-
(unless (= 1 (length v))
167-
(eprintf "found multiple menu items with the shortcut ~s: ~s\n"
168-
k v))))
168+
(for ([(k v) (in-hash shortcuts)]
169+
#:unless (= 1 (length v)))
170+
(eprintf "found multiple menu items with the shortcut ~s: ~s\n" k v)))
169171

170172
(process-container (send frame get-menu-bar))
171173
(check-shortcuts))

0 commit comments

Comments
 (0)