79 lines
2.8 KiB
Racket
79 lines
2.8 KiB
Racket
#lang racket/base
|
|
|
|
(require "../main.rkt"
|
|
"jsmaker-test-framework.rkt")
|
|
|
|
(check-public-api)
|
|
|
|
(define simple-function
|
|
(js (define (add1 x) (return (+ x 1)))))
|
|
(check-contains 'simple-function "function add1(x)" simple-function)
|
|
(check-contains 'simple-function-return "return x + 1;" simple-function)
|
|
|
|
(define escaped-string
|
|
(js (define (message) (return "regel 1\nregel 2 \"ok\""))))
|
|
(check-contains 'string-newline "regel 1\\nregel 2" escaped-string)
|
|
(check-contains 'string-quote "\\\"ok\\\"" escaped-string)
|
|
|
|
(define list-program
|
|
(js (define (values) (return (list 1 "a" #t #f)))))
|
|
(check-contains 'list-literal "return [1, \"a\", true, false];" list-program)
|
|
|
|
(define cons-program
|
|
(js (define (prepend xs) (return (cons 1 xs)))))
|
|
(check-contains 'cons-generation "[1].concat(xs)" cons-program)
|
|
|
|
(define send-program
|
|
(js (define (unique xs) (return (send Array from (new Set xs))))))
|
|
(check-contains 'send-generation "Array.from(new Set(xs))" send-program)
|
|
|
|
(define dot-set-program
|
|
(js (define (setHtml el html) (set! (js-dot el innerHTML) html) (return (js-dot el innerHTML)))))
|
|
(check-contains 'dot-set "el.innerHTML = html;" dot-set-program)
|
|
(check-contains 'dot-return "return el.innerHTML;" dot-set-program)
|
|
|
|
(define ref-program
|
|
(js (define (at xs i) (return (js-ref xs i)))))
|
|
(check-contains 'ref-variable-index "return xs[i];" ref-program)
|
|
|
|
(define ref-string-key-program
|
|
(js (define (nameOf obj) (return (js-ref obj "name")))))
|
|
(check-contains 'ref-string-key "return obj[\"name\"];" ref-string-key-program)
|
|
|
|
(define ref-set-program
|
|
(js (define (put xs i value) (set! (js-ref xs i) value) (return xs))))
|
|
(check-contains 'ref-set "xs[i] = value;" ref-set-program)
|
|
|
|
(define ref-nested-program
|
|
(js (define (nested matrix r c) (return (js-ref matrix r c)))))
|
|
(check-contains 'ref-nested "return matrix[r][c];" ref-nested-program)
|
|
|
|
(define ordinary-let
|
|
(js (define (ordinaryLet x)
|
|
(let ([x 1] [y x])
|
|
(return y)))))
|
|
(check-matches 'ordinary-let-temp #rx"const .* = 1;" ordinary-let)
|
|
(check-contains 'ordinary-let-inner "{\nlet x =" ordinary-let)
|
|
(check-contains 'ordinary-let-inner-y "\nlet y =" ordinary-let)
|
|
(check-contains 'ordinary-let-return "return y;" ordinary-let)
|
|
|
|
(define let-star
|
|
(js (define (sequentialLet x)
|
|
(let* ([x 1] [y x])
|
|
(return y)))))
|
|
(check-contains 'let-star-x "let x = 1;" let-star)
|
|
(check-contains 'let-star-y "let y = x;" let-star)
|
|
|
|
(define named-let
|
|
(js (define (sumTo n)
|
|
(let loop ([i 0] [acc 0])
|
|
(if (> i n)
|
|
(return acc)
|
|
(loop (+ i 1) (+ acc i)))))))
|
|
(check-contains 'named-let-while "while (true)" named-let)
|
|
(check-contains 'named-let-continue "continue;" named-let)
|
|
(check-matches 'named-let-parallel-update #rx"const .* = i \\+ 1;" named-let)
|
|
|
|
(module+ main
|
|
(test-summary 'jsmaker-regression))
|