A mostly AI coded js-maker, supervised by me.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#lang racket/base
|
||||
|
||||
(require json
|
||||
"jsmaker-test-framework.rkt"
|
||||
"jsmaker-executors.rkt"
|
||||
"../demo/dom-exercises.rkt")
|
||||
|
||||
(define (dom-preamble paragraph-text)
|
||||
(format #<<JS
|
||||
const state = { afterParagraph: [], afterHeading: [] };
|
||||
const paragraph = {
|
||||
innerHTML: ~a,
|
||||
get textContent() { return String(this.innerHTML).replace(/<[^>]*>/g, ''); },
|
||||
set textContent(v) { this.innerHTML = String(v); },
|
||||
insertAdjacentHTML: (position, html) => { state.afterParagraph.push([position, html]); }
|
||||
};
|
||||
const heading = {
|
||||
insertAdjacentHTML: (position, html) => { state.afterHeading.push([position, html]); }
|
||||
};
|
||||
const document = {
|
||||
querySelector: (selector) => {
|
||||
if (selector === 'p') return paragraph;
|
||||
if (selector === 'h1') return heading;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
JS
|
||||
(jsexpr->string paragraph-text)))
|
||||
|
||||
(define tests
|
||||
(list
|
||||
(js-program-test
|
||||
'dom-ex01-highlight-long-words
|
||||
exercise01
|
||||
"paragraph.innerHTML"
|
||||
(jsexpr->string "Short <span style=\"background: yellow\">extraordinary</span> words remain.")
|
||||
#:preamble (dom-preamble "Short extraordinary words remain."))
|
||||
|
||||
(js-program-test
|
||||
'dom-ex02-add-source-link
|
||||
exercise02
|
||||
"state.afterParagraph"
|
||||
(jsexpr->string '(("afterend" "<a href=\"https://forcemipsum.com/\">Source: ForceM Ipsum</a>")))
|
||||
#:preamble (dom-preamble "Force ipsum text."))
|
||||
|
||||
(js-program-test
|
||||
'dom-ex03-split-sentences
|
||||
exercise03
|
||||
"paragraph.innerHTML"
|
||||
(jsexpr->string "First sentence.<br>Second sentence.<br>Third.<br>")
|
||||
#:preamble (dom-preamble "First sentence. Second sentence. Third."))
|
||||
|
||||
(js-program-test
|
||||
'dom-ex04-count-words-after-heading
|
||||
exercise04
|
||||
"state.afterHeading"
|
||||
(jsexpr->string '(("afterend" "<p>4 words</p>")))
|
||||
#:preamble (dom-preamble "These are four words"))
|
||||
|
||||
(js-program-test
|
||||
'dom-ex05-replace-punctuation-faces
|
||||
exercise05
|
||||
"paragraph.innerHTML"
|
||||
(jsexpr->string "Really🤔 Yes😲 No🤔")
|
||||
#:preamble (dom-preamble "Really? Yes! No?"))))
|
||||
|
||||
(define engine (find-js-engine))
|
||||
(run-jsmaker-regression 'jsmaker-dom-exercises tests "/tmp/jsmaker-dom-exercises.js" #:engine engine)
|
||||
Reference in New Issue
Block a user