Files
gemigreerd-js-maker/testing/jsmaker-regression.rkt
T
2026-06-08 12:55:08 +02:00

36 lines
1.2 KiB
Racket

#lang racket/base
(require rackunit
racket/runtime-path
"../main.rkt"
"jsmaker-test-framework.rkt")
(provide regression-tests)
(define-runtime-path main-module "../main.rkt")
(define regression-tests
(test-suite
"core js macro output"
(test-case "the public API exports js only"
(check-exn exn:fail? (lambda () (dynamic-require main-module 'js1)))
(check-exn exn:fail? (lambda () (dynamic-require main-module 'js/expression))))
(test-case "arithmetic and boolean expressions can be emitted as statements"
(check-js-equal? (js (+ 1 2)) "1 + 2;\n")
(check-js-equal? (js (and a b)) "a && b;\n")
(check-js-equal? (js (not ready)) "!(ready);\n"))
(test-case "value and function definitions"
(check-js-equal? (js (define answer 42)) "let answer = 42;\n")
(check-js-contains?
(js (define (square x) (return (* x x))))
"function square(x)"))
(test-case "conditionals and begin blocks"
(define out (js (if (> x 0) (return x) (return 0))))
(check-js-contains? out "if (x > 0)")
(check-js-contains? out "return x;")
(check-js-contains? (js (begin (set! x 1) (return x))) "x = 1;"))))
(module+ test
(require rackunit/text-ui)
(run-tests regression-tests))