|
14 | 14 | (contract-out |
15 | 15 | [refactoring-rule? (-> any/c boolean?)] |
16 | 16 | [refactoring-rule-description (-> refactoring-rule? immutable-string?)] |
17 | | - [refactoring-rule-analyzers (-> refactoring-rule? (listof expansion-analyzer?))] |
| 17 | + [refactoring-rule-analyzers (-> refactoring-rule? (set/c expansion-analyzer?))] |
18 | 18 | [refactoring-suite? (-> any/c boolean?)] |
19 | 19 | [refactoring-suite |
20 | 20 | (->* () |
21 | 21 | (#:rules (sequence/c refactoring-rule?) #:name (or/c interned-symbol? #false)) |
22 | 22 | refactoring-suite?)] |
23 | 23 | [refactoring-suite-rules (-> refactoring-suite? (listof refactoring-rule?))] |
24 | | - [refactoring-suite-analyzers (-> refactoring-suite? (listof expansion-analyzer?))])) |
| 24 | + [refactoring-suite-analyzers (-> refactoring-suite? (set/c expansion-analyzer?))])) |
25 | 25 |
|
26 | 26 |
|
27 | 27 | (module+ private |
|
37 | 37 | resyntax/private/more-syntax-parse-classes) |
38 | 38 | racket/list |
39 | 39 | racket/sequence |
| 40 | + racket/set |
40 | 41 | rebellion/base/immutable-string |
41 | 42 | rebellion/base/option |
42 | 43 | rebellion/base/symbol |
|
156 | 157 | #:name 'id |
157 | 158 | #:description (string->immutable-string description.c) |
158 | 159 | #:uses-universal-tagged-syntax? (~? uses-universal-tagged-syntax? #false) |
159 | | - #:analyzers (list identifier-usage-analyzer |
160 | | - ignored-result-values-analyzer |
161 | | - variable-mutability-analyzer) |
| 160 | + #:analyzers (set identifier-usage-analyzer |
| 161 | + ignored-result-values-analyzer |
| 162 | + variable-mutability-analyzer) |
162 | 163 | #:transformer |
163 | 164 | (λ (stx) |
164 | 165 | (syntax-parse stx |
|
236 | 237 | (define (refactoring-suite #:rules [rules '()] #:name [name #false]) |
237 | 238 | (define rule-list (sequence->list rules)) |
238 | 239 | (define combined-analyzers |
239 | | - (remove-duplicates |
240 | | - (append-map refactoring-rule-analyzers rule-list))) |
| 240 | + (for*/set ([rule (in-list rule-list)] |
| 241 | + [analyzer (in-set (refactoring-rule-analyzers rule))]) |
| 242 | + analyzer)) |
241 | 243 | (constructor:refactoring-suite #:rules rule-list #:analyzers combined-analyzers #:name name)) |
242 | 244 |
|
243 | 245 |
|
|
276 | 278 | replacement) |
277 | 279 |
|
278 | 280 | (check-true (refactoring-rule? test-rule)) |
279 | | - (check-equal? (length (refactoring-rule-analyzers test-rule)) 3) |
280 | | - (check-true (andmap expansion-analyzer? (refactoring-rule-analyzers test-rule)))) |
| 281 | + (check-true (set? (refactoring-rule-analyzers test-rule))) |
| 282 | + (check-equal? (set-count (refactoring-rule-analyzers test-rule)) 3) |
| 283 | + (check-true (for/and ([analyzer (in-set (refactoring-rule-analyzers test-rule))]) |
| 284 | + (expansion-analyzer? analyzer)))) |
281 | 285 |
|
282 | 286 | (test-case "refactoring-suite combines analyzers from rules" |
283 | 287 | (define-refactoring-rule rule1 |
|
294 | 298 |
|
295 | 299 | (check-true (refactoring-suite? suite)) |
296 | 300 | (check-equal? (length (refactoring-suite-rules suite)) 2) |
297 | | - ;; All rules have the same analyzers, so the combined list should have 3 unique analyzers |
298 | | - (check-equal? (length (refactoring-suite-analyzers suite)) 3) |
299 | | - (check-true (andmap expansion-analyzer? (refactoring-suite-analyzers suite)))) |
| 301 | + (check-true (set? (refactoring-suite-analyzers suite))) |
| 302 | + ;; All rules have the same analyzers, so the combined set should have 3 unique analyzers |
| 303 | + (check-equal? (set-count (refactoring-suite-analyzers suite)) 3) |
| 304 | + (check-true (for/and ([analyzer (in-set (refactoring-suite-analyzers suite))]) |
| 305 | + (expansion-analyzer? analyzer)))) |
300 | 306 |
|
301 | 307 | (test-case "nested suites combine analyzers correctly" |
302 | 308 | (define-refactoring-rule inner-rule |
|
313 | 319 |
|
314 | 320 | (define outer-suite (refactoring-suite #:rules (list outer-rule inner-rule))) |
315 | 321 |
|
316 | | - (check-equal? (length (refactoring-suite-analyzers inner-suite)) 3) |
| 322 | + (check-equal? (set-count (refactoring-suite-analyzers inner-suite)) 3) |
317 | 323 | ;; Both rules have the same analyzers, so deduplicated should still be 3 |
318 | | - (check-equal? (length (refactoring-suite-analyzers outer-suite)) 3)) |
| 324 | + (check-equal? (set-count (refactoring-suite-analyzers outer-suite)) 3)) |
319 | 325 |
|
320 | 326 | (test-case "define-refactoring-suite with nested suites preserves analyzers" |
321 | 327 | (define-refactoring-rule rule-a |
|
338 | 344 | ;; Suite B should have both rules |
339 | 345 | (check-equal? (length (refactoring-suite-rules suite-b)) 2) |
340 | 346 | ;; And should have 3 analyzers (deduplicated from both rules) |
341 | | - (check-equal? (length (refactoring-suite-analyzers suite-b)) 3) |
342 | | - (check-true (andmap expansion-analyzer? (refactoring-suite-analyzers suite-b))))) |
| 347 | + (check-equal? (set-count (refactoring-suite-analyzers suite-b)) 3) |
| 348 | + (check-true (for/and ([analyzer (in-set (refactoring-suite-analyzers suite-b))]) |
| 349 | + (expansion-analyzer? analyzer))))) |
0 commit comments