File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -427,6 +427,41 @@ test: "always-throwing unless before returning condition variable refactorable t
427427--------------------
428428
429429
430+ test: "refactoring always-throwing unless to or doesn't reformat surrounding context "
431+ --------------------
432+ (define (f s)
433+
434+ ( define foo 42 )
435+
436+ (define x (string->number s))
437+ (unless x
438+ (error "string that is not a num " ))
439+ x)
440+ --------------------
441+ --------------------
442+ (define (f s)
443+
444+ ( define foo 42 )
445+
446+ (or (string->number s) (error "string that is not a num " )))
447+ --------------------
448+
449+
450+ test: "refactoring always-throwing unless to or can reformat when its the only body "
451+ --------------------
452+ (define (f s)
453+ (λ (v)
454+ (define x (string->number s))
455+ (unless x
456+ (error "string that is not a num " ))
457+ x))
458+ --------------------
459+ --------------------
460+ (define (f s)
461+ (λ (v) (or (string->number s) (error "string that is not a num " ))))
462+ --------------------
463+
464+
430465test: "cond with nested else-cond can be flattened "
431466------------------------------
432467(define (f a b)
Original file line number Diff line number Diff line change 1010
1111
1212(require (for-syntax racket/base)
13+ racket/list
1314 resyntax/base
1415 resyntax/default-recommendations/private/boolean
1516 resyntax/default-recommendations/private/exception
156157 (~and def (define truthy-var:id truthy-expr))
157158 (~and check (unless truthy-var2:id fail:always-throwing-expression))
158159 truthy-var3:id)
160+
159161 #:when (free-identifier=? #'truthy-var #'truthy-var2 )
160162 #:when (free-identifier=? #'truthy-var #'truthy-var3 )
161- (body-before ...
162- (~focus-replacement-on
163- (~replacement (or truthy-expr fail) #:original-splice (def check truthy-var3)))))
163+ #:with or-expression
164+ #'(~replacement (or truthy-expr fail) #:original-splice (def check truthy-var3))
165+ #:with focused-or-expression
166+ (if (empty? (attribute body-before))
167+ #'or-expression
168+ #'(~focus-replacement-on or-expression))
169+
170+ (body-before ... focused-or-expression))
164171
165172
166173(define-refactoring-rule cond-else-cond-to-cond
You can’t perform that action at this time.
0 commit comments