(import (scheme base) test matchertext) (current-test-comparator string=?) (define (test-syntax-error name str) (test-error name (read (open-input-string str)))) (test-group "basic functionality" (test "Empty string" "" #M"()") (test "No matchers" "Hello, world!" #M"(Hello, world!)") (test "Special char" "\\" #M"(\)") (test "One matching pair" "()" #M"(())") (test "Many unnested matching pairs" "()[]{}" #M"(()[]{})") (test "Deep nesting" "([{{}}])" #M"(([{{}}]))") (test "Mixed matching pairs" "()[{}]" #M"(()[{}])") (test "Mixed matchers and text" "a(bb)c[dd{e}ff]g" #M"(a(bb)c[dd{e}ff]g)") (test-syntax-error "Missing quotes" "#M()") (test-syntax-error "Missing delimiting brackets" "#M\"\"") (test-syntax-error "Premature EOF" "#M\"(") (test-syntax-error "Unmatched bracket" "#M\"([)\"")) (define greeting "Hello") (test-group "interpolation" (test "No interpolation" "Hello, world!" #M{}"(Hello, world!)") (test "One variable interpolation" "Hello, world!" #M{}"({greeting}, world!)") (test "Constant interpolation" "hello" #M{}"({"hello"})") (test "Many interpolations" "Hello-Hello-Hello" #M{}"({greeting}-{greeting}-{greeting})") (test "Interpolate s-expression" "2" #M{}"({(number->string (+ 1 1))})") (test "Deep nesting" "Hello" #M([{{}}])"(([{{greeting}}]))") (test "Nested quoters" "2" #M()"(((number->string (+ 1 1))))") (test "Whitespace" "Hello" #M{}"({ greeting })") (test-syntax-error "More than one expression" "#M{}\"({greeting greeting})\"") (test-syntax-error "Unmatched quoters in declaration" "#M{}}\"({greeting})\"") (test-error "Interpolate non-string" #M{}"({3})")) (test-exit)