Skip to content

Commit 573c066

Browse files
Copilotjackfirth
andcommitted
Add tests for source-can-expand? function
Co-authored-by: jackfirth <[email protected]>
1 parent 89ebfa7 commit 573c066

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

private/source.rkt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,23 @@
126126
(check-equal? (source-read-language (string-source "#lang scribble/manual")) 'scribble/manual)
127127
(check-equal? (source-read-language (string-source "#lang info")) 'info)
128128
(check-equal? (source-read-language (string-source "#lang setup/infotab")) 'setup/infotab)
129-
(check-equal? (source-read-language (string-source "(void)")) #false)))
129+
(check-equal? (source-read-language (string-source "(void)")) #false))
130+
131+
(test-case "source-can-expand?"
132+
;; Valid racket code should expand successfully
133+
(check-true (source-can-expand? (string-source "#lang racket/base\n(define x 42)")))
134+
(check-true (source-can-expand? (string-source "#lang racket\n(or 1 2 3)")))
135+
136+
;; Invalid racket code should not expand
137+
(check-false (source-can-expand? (string-source "#lang racket/base\n(if)")))
138+
(check-false (source-can-expand? (string-source "#lang racket/base\n(define)")))
139+
140+
;; Modified sources should also be testable
141+
(define orig (string-source "#lang racket/base\n(define foo 42)"))
142+
(define valid-mod (modified-source orig "#lang racket/base\n(define foo 43)"))
143+
(define invalid-mod (modified-source orig "#lang racket/base\n(if)"))
144+
(check-true (source-can-expand? valid-mod))
145+
(check-false (source-can-expand? invalid-mod))))
130146

131147

132148
(define (source-expand code)

0 commit comments

Comments
 (0)