Skip to content

Commit f103d6a

Browse files
Copilotjackfirth
andcommitted
Add test for filtering out-of-syntax properties
Co-authored-by: jackfirth <[email protected]>
1 parent e2ff6fb commit f103d6a

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

private/analysis.rkt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,40 @@
278278
#:analyzers (list identifier-usage-analyzer
279279
ignored-result-values-analyzer
280280
variable-mutability-analyzer)))
281-
(check-true (source-code-analysis? analysis-default))))
281+
(check-true (source-code-analysis? analysis-default)))
282+
283+
(test-case "source-analyze filters out properties with invalid paths"
284+
;; Create a test analyzer that returns properties with both valid and invalid paths
285+
(define test-source (string-source "#lang racket/base (define x 1)"))
286+
287+
(define bad-analyzer
288+
(make-expansion-analyzer
289+
#:name 'bad-analyzer
290+
(λ (expanded)
291+
(syntax-property-bundle
292+
;; Valid path - the root
293+
(syntax-property-entry empty-syntax-path 'valid-prop #true)
294+
;; Invalid path - way out of bounds
295+
(syntax-property-entry (syntax-path (list 999)) 'invalid-prop #true)
296+
;; Another invalid path
297+
(syntax-property-entry (syntax-path (list 0 999)) 'another-invalid-prop #true)))))
298+
299+
;; Run analysis with the bad analyzer - should not crash
300+
(define analysis (source-analyze test-source #:analyzers (list bad-analyzer)))
301+
302+
;; Check that the analysis completed successfully
303+
(check-true (source-code-analysis? analysis))
304+
305+
;; Check that the valid property is present in the result
306+
(define props (source-code-analysis-added-syntax-properties analysis))
307+
(check-true (syntax-property-bundle? props))
308+
309+
;; The valid property at the root should be present
310+
(define root-props (syntax-property-bundle-get-immediate-properties props empty-syntax-path))
311+
(check-equal? (hash-ref root-props 'valid-prop #false) #true)
312+
313+
;; The invalid properties should NOT be present
314+
;; Check that path /999 is not in the bundle
315+
(define path-999-props
316+
(syntax-property-bundle-get-immediate-properties props (syntax-path (list 999))))
317+
(check-true (hash-empty? path-999-props))))

0 commit comments

Comments
 (0)