;; ;; MIT License ;; ;; Copyright (c) 2018 Thomas Chust ;; ;; Permission is hereby granted, free of charge, to any person obtaining a copy ;; of this software and associated documentation files (the "Software"), to deal ;; in the Software without restriction, including without limitation the rights ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ;; copies of the Software, and to permit persons to whom the Software is ;; furnished to do so, subject to the following conditions: ;; ;; The above copyright notice and this permission notice shall be included in ;; all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;; (require-library utf8 webview) (import (only (chicken port) call-with-output-string) utf8-srfi-14 webview-content test) (define (js-escape s) (call-with-output-string (cut write-js s <> #f))) (test-group "JavaScript strings" (test-assert (char-set-contains? char-set:no-js-escape #\+)) (test-assert (char-set-contains? char-set:no-js-escape #\-)) (test-assert (char-set-contains? char-set:no-js-escape #\space)) (test-assert (char-set-contains? char-set:no-js-escape #\A)) (test-assert (char-set-contains? char-set:no-js-escape #\B)) (test-assert (char-set-contains? char-set:no-js-escape #\x30AB)) (test-assert (not (char-set-contains? char-set:no-js-escape #\tab))) (test-assert (not (char-set-contains? char-set:no-js-escape #\newline))) (test-assert (not (char-set-contains? char-set:no-js-escape #\return))) (test-assert (not (char-set-contains? char-set:no-js-escape #\alarm))) (test "foo" (js-escape "foo")) (test "f\\\"o" (js-escape "f\"o")) (test "\\'o" (js-escape "'o")) (test "\\u0007foo\\nbar" (js-escape "\afoo\nbar")) (test "カタカナ\\u270d!" (js-escape "カタカナ✍!"))) (define (html->string html) (call-with-output-string (cut write-html html <>))) (test-group "HTML content" (test 'normal (html-tag-rule 'p)) (test 'raw (html-tag-rule 'script)) (test 'void (html-tag-rule 'br)) (test "\n\n" (html->string '(html))) (test "
" (html->string '(br))) (test "

Hello world!

" (html->string '(p "Hello world!"))) (test "&" (html->string '(span amp))) (test "" (html->string '(span #x270d))) (test "" (html->string '(meta ([charset "utf-8"])))) (test "blah ×" (html->string '(span ([class "close"]) "blah " times))) (test "fooxbar" (html->string '(begin (em "foo") "x" (tt "bar"))))) ;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;