Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions grimoire/syntax-path.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@
(check-equal? (syntax-path-remove-prefix path prefix) expected))))


(module+ test
(test-case "syntax-path-remove-prefix errors"

(test-case "path shorter than prefix"
(check-exn #rx"path is shorter than prefix"
(λ () (syntax-path-remove-prefix (syntax-path (list 1)) (syntax-path (list 1 2 3))))))

(test-case "path does not start with prefix"
(check-exn #rx"path does not start with given prefix"
(λ () (syntax-path-remove-prefix (syntax-path (list 1 2 3)) (syntax-path (list 9))))))))


(define (syntax-path-last-element path)
(treelist-last (syntax-path-elements path)))

Expand Down Expand Up @@ -592,6 +604,30 @@
(check-regexp-match #rx"path is inconsistent" (exn-message thrown)))))


(module+ test
(test-case "syntax-ref errors"

(test-case "vector index out of bounds"
(check-exn #rx"path is inconsistent"
(λ () (syntax-ref #'#[a b c] (syntax-path (list 5))))))

(test-case "box index out of bounds"
(check-exn #rx"path is inconsistent"
(λ () (syntax-ref #'#&a (syntax-path (list 1))))))

(test-case "prefab field index out of bounds"
(check-exn #rx"path is inconsistent"
(λ () (syntax-ref #'#s(point 10 20) (syntax-path (list 5))))))

(test-case "improper list index out of bounds"
(check-exn #rx"path is inconsistent"
(λ () (syntax-ref #'(a b . c) (syntax-path (list 5))))))

(test-case "path into non-compound datum"
(check-exn #rx"path is inconsistent"
(λ () (syntax-ref #'(a b c) (syntax-path (list 0 0))))))))


(define (syntax-contains-path? init-stx path)
(let/ec return
(for/fold ([stx init-stx])
Expand Down Expand Up @@ -876,6 +912,14 @@
(check-equal? (syntax->datum actual) '(a b c FOO e)))))


(module+ test
(test-case "syntax-set errors"

(test-case "path into non-compound datum"
(check-exn #rx"path is inconsistent"
(λ () (syntax-set #'(a b c) (syntax-path (list 0 0)) #'FOO))))))


(define/guard (syntax-remove-splice stx path children-count)
(unless (syntax-contains-path? stx path)
(raise-arguments-error 'syntax-remove-splice
Expand Down
Loading