|
218 | 218 |
|
219 | 219 |
|
220 | 220 | (define (syntax-path->string path) |
221 | | - (if (empty-syntax-path? path) |
222 | | - "/" |
223 | | - (string-append |
224 | | - "/" |
225 | | - (string-join |
226 | | - (for/list ([elem (in-treelist (syntax-path-elements path))]) |
227 | | - (number->string elem)) |
228 | | - "/")))) |
| 221 | + (string-join |
| 222 | + (for/list ([elem (in-treelist (syntax-path-elements path))]) |
| 223 | + (number->string elem)) |
| 224 | + "/" |
| 225 | + #:before-first "/")) |
229 | 226 |
|
230 | 227 |
|
231 | 228 | (module+ test |
|
284 | 281 | (check-equal? (string->syntax-path "/42/99/1000") (syntax-path (list 42 99 1000)))) |
285 | 282 |
|
286 | 283 | (test-case "error on missing leading slash" |
287 | | - (check-exn exn:fail:contract? |
288 | | - (λ () (string->syntax-path "0/1/2")))) |
| 284 | + (define input "0/1/2") |
| 285 | + (define thrown |
| 286 | + (with-handlers ([(λ (_) #true) values]) |
| 287 | + (string->syntax-path input) |
| 288 | + #false)) |
| 289 | + (check-pred exn:fail:contract? thrown) |
| 290 | + (check-regexp-match #rx"string->syntax-path:" (exn-message thrown)) |
| 291 | + (check-regexp-match #rx"given: \"0/1/2\"" (exn-message thrown)) |
| 292 | + (check-regexp-match #rx"syntax path string must start with /" (exn-message thrown))) |
289 | 293 |
|
290 | 294 | (test-case "error on trailing slash" |
291 | | - (check-exn exn:fail:contract? |
292 | | - (λ () (string->syntax-path "/0/1/")))) |
| 295 | + (define input "/0/1/") |
| 296 | + (define thrown |
| 297 | + (with-handlers ([(λ (_) #true) values]) |
| 298 | + (string->syntax-path input) |
| 299 | + #false)) |
| 300 | + (check-pred exn:fail:contract? thrown) |
| 301 | + (check-regexp-match #rx"string->syntax-path:" (exn-message thrown)) |
| 302 | + (check-regexp-match #rx"given: \"/0/1/\"" (exn-message thrown)) |
| 303 | + (check-regexp-match #rx"syntax path string must not end with /" (exn-message thrown))) |
293 | 304 |
|
294 | 305 | (test-case "error on invalid element" |
295 | | - (check-exn exn:fail:contract? |
296 | | - (λ () (string->syntax-path "/0/abc/2")))) |
| 306 | + (define input "/0/abc/2") |
| 307 | + (define thrown |
| 308 | + (with-handlers ([(λ (_) #true) values]) |
| 309 | + (string->syntax-path input) |
| 310 | + #false)) |
| 311 | + (check-pred exn:fail:contract? thrown) |
| 312 | + (check-regexp-match #rx"string->syntax-path:" (exn-message thrown)) |
| 313 | + (check-regexp-match #rx"given: \"/0/abc/2\"" (exn-message thrown)) |
| 314 | + (check-regexp-match #rx"syntax path string contains invalid element" (exn-message thrown)) |
| 315 | + (check-regexp-match #rx"invalid element: \"abc\"" (exn-message thrown))) |
297 | 316 |
|
298 | 317 | (test-case "error on negative number" |
299 | | - (check-exn exn:fail:contract? |
300 | | - (λ () (string->syntax-path "/0/-1/2")))) |
| 318 | + (define input "/0/-1/2") |
| 319 | + (define thrown |
| 320 | + (with-handlers ([(λ (_) #true) values]) |
| 321 | + (string->syntax-path input) |
| 322 | + #false)) |
| 323 | + (check-pred exn:fail:contract? thrown) |
| 324 | + (check-regexp-match #rx"string->syntax-path:" (exn-message thrown)) |
| 325 | + (check-regexp-match #rx"given: \"/0/-1/2\"" (exn-message thrown)) |
| 326 | + (check-regexp-match #rx"syntax path string contains invalid element" (exn-message thrown)) |
| 327 | + (check-regexp-match #rx"invalid element: \"-1\"" (exn-message thrown))) |
301 | 328 |
|
302 | 329 | (test-case "error on float" |
303 | | - (check-exn exn:fail:contract? |
304 | | - (λ () (string->syntax-path "/0/1.5/2")))))) |
| 330 | + (define input "/0/1.5/2") |
| 331 | + (define thrown |
| 332 | + (with-handlers ([(λ (_) #true) values]) |
| 333 | + (string->syntax-path input) |
| 334 | + #false)) |
| 335 | + (check-pred exn:fail:contract? thrown) |
| 336 | + (check-regexp-match #rx"string->syntax-path:" (exn-message thrown)) |
| 337 | + (check-regexp-match #rx"given: \"/0/1.5/2\"" (exn-message thrown)) |
| 338 | + (check-regexp-match #rx"syntax path string contains invalid element" (exn-message thrown)) |
| 339 | + (check-regexp-match #rx"invalid element: \"1.5\"" (exn-message thrown))))) |
305 | 340 |
|
306 | 341 |
|
307 | 342 | (module+ test |
|
0 commit comments