File tree Expand file tree Collapse file tree 4 files changed +38
-8
lines changed Expand file tree Collapse file tree 4 files changed +38
-8
lines changed Original file line number Diff line number Diff line change @@ -106,3 +106,16 @@ test: "inlining immediately returned variable definition doesn't reformat entire
106106
107107 1 )
108108------------------------------
109+
110+
111+ test: "inlining immediately returned variable definition in empty context does reformat "
112+ ------------------------------
113+ (map (λ (x)
114+ (define y (* x 2 ))
115+ y)
116+ (list 1 2 3 ))
117+ ------------------------------
118+ ------------------------------
119+ (map (λ (x) (* x 2 ))
120+ (list 1 2 3 ))
121+ ------------------------------
Original file line number Diff line number Diff line change 1010
1111
1212(require (for-syntax racket/base)
13+ racket/list
1314 rebellion/private/static-name
1415 resyntax/base
1516 syntax/parse)
3233 #:literals (define )
3334 (~seq body-before ... (~and definition (define id1:id expr)) id2:id)
3435 #:when (free-identifier=? #'id1 #'id2 )
35- (body-before ... (~focus-replacement-on (~replacement expr #:original-splice (definition id2)))))
36+ #:with replacement #'(~replacement expr #:original-splice (definition id2))
37+ #:with focused (if (empty? (attribute body-before))
38+ #'replacement
39+ #'(~focus-replacement-on replacement))
40+ (body-before ... focused))
3641
3742
3843(define-refactoring-suite definition-shortcuts
Original file line number Diff line number Diff line change @@ -51,6 +51,19 @@ test: "migrating single-clause match expressions to match-define doesn't reforma
5151------------------------------
5252
5353
54+ test: "migrating single-clause match expressions in single-form contexts does reformat "
55+ ------------------------------
56+ (map (λ (x) (match x [(list a b c) (+ a b c)]))
57+ (list (list 1 2 3 ) (list 4 5 6 )))
58+ ------------------------------
59+ ------------------------------
60+ (map (λ (x)
61+ (match-define (list a b c) x)
62+ (+ a b c))
63+ (list (list 1 2 3 ) (list 4 5 6 )))
64+ ------------------------------
65+
66+
5467test: "single-clause match expressions inside cond can be replaced with match-define expressions "
5568------------------------------
5669(define (foo x condition)
Original file line number Diff line number Diff line change 99 [match-shortcuts refactoring-suite?]))
1010
1111
12- (require ( for-syntax racket/base)
12+ (require racket/list
1313 racket/match
1414 racket/set
15- rebellion/private/static-name
1615 resyntax/base
17- resyntax/default-recommendations/private/definition-context
1816 resyntax/default-recommendations/private/syntax-identifier-sets
19- resyntax/default-recommendations/private/syntax-lines
20- resyntax/default-recommendations/private/syntax-tree
21- resyntax/private/syntax-neighbors
2217 syntax/parse)
2318
2419
4136 (~seq body-before ... match-expression:single-clause-match)
4237 #:when (set-empty? (set-intersect (syntax-bound-identifiers #'(body-before ... ))
4338 (syntax-bound-identifiers #'match-expression.match-pattern )))
44- (body-before ... (~@ . (~focus-replacement-on (match-expression.as-definition-context-body ... )))))
39+ #:with (new-body ... ) (if (empty? (attribute body-before))
40+ (attribute match-expression.as-definition-context-body)
41+ #'(~focus-replacement-on
42+ (match-expression.as-definition-context-body ... )))
43+ (body-before ... new-body ... ))
4544
4645
4746(define-refactoring-suite match-shortcuts
You can’t perform that action at this time.
0 commit comments