Skip to content

Commit 65a32fa

Browse files
committed
Finish tests; fix code so they should work with Prism
1 parent 1df873a commit 65a32fa

File tree

4 files changed

+247
-169
lines changed

4 files changed

+247
-169
lines changed

code-input.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var codeInput = {
1919
observedAttributes: [
2020
"value",
2121
"placeholder",
22+
"language",
2223
"lang",
2324
"template"
2425
],
@@ -417,10 +418,6 @@ var codeInput = {
417418
constructor() {
418419
super(); // Element
419420
}
420-
/**
421-
* Store value internally
422-
*/
423-
_value = '';
424421

425422
/**
426423
* Exposed child textarea element for user to input code in
@@ -633,7 +630,7 @@ var codeInput = {
633630

634631
if (this.template.isCode) {
635632
if (lang != undefined && lang != "") {
636-
code.classList.add("language-" + lang);
633+
code.classList.add("language-" + lang.toLowerCase());
637634
}
638635
}
639636

@@ -733,7 +730,6 @@ var codeInput = {
733730

734731
case "lang":
735732
case "language":
736-
737733
let code = this.codeElement;
738734
let mainTextarea = this.textareaElement;
739735

@@ -849,7 +845,8 @@ var codeInput = {
849845
* Get the text contents of the code-input element.
850846
*/
851847
get value() {
852-
return this._value;
848+
// Get from editable textarea element
849+
return this.textareaElement.value;
853850
}
854851
/**
855852
* Set the text contents of the code-input element.
@@ -859,7 +856,9 @@ var codeInput = {
859856
if (val === null || val === undefined) {
860857
val = "";
861858
}
862-
this._value = val;
859+
// Save in editable textarea element
860+
this.textareaElement.value = val;
861+
// Trigger highlight
863862
this.needsHighlight = true;
864863
return val;
865864
}

tests/hljs.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@
3535
<!--TODO: Fix for hljs popup &
3636
(optional) In new branch, make Ctrl+F/H functionality like gotoline (finds in value, "string combinatorics" in pre code, Regex/case-insensitive accepted); Add tests for Ctrl+F/H
3737
(optional) In new branch, add one-line (input) option
38-
Add tests for form/value/language functionality-->
38+
Make tester async function using await?-->
3939
<h1>code-input Tester (highlight.js)</h1>
4040
<h4><a href="prism.html">Test for Prism.js</a></h4>
4141
<p>This page carries out automated tests for the code-input library to check that both the core components and the plugins work in some ways. It doesn't fully cover every scenario so you should test any code you change by hand, but it's good for quickly checking a wide range of functionality works.</p>
4242

4343
<details id="collapse-results"><summary>Test Results</summary><pre id="test-results"></pre></details>
44-
<code-input language="JavaScript">console.log("Hello, World!");</code-input>
44+
<form method="GET" action="https://google.com/search" target="_blank">
45+
<code-input language="JavaScript" name="q">console.log("Hello, World!");
46+
// A second line
47+
// A third line with &lt;html> tags</code-input>
48+
<input type="submit" value="Search Google For Code"/>
49+
</form>
4550

4651
<script>
4752
beginTest(true);

tests/prism.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ <h4><a href="hljs.html">Test for highlight.js</a></h4>
3232
<p>This page carries out automated tests for the code-input library to check that both the core components and the plugins work in some ways. It doesn't fully cover every scenario so you should test any code you change by hand, but it's good for quickly checking a wide range of functionality works.</p>
3333

3434
<details id="collapse-results"><summary>Test Results</summary><pre id="test-results"></pre></details>
35-
<code-input language="JavaScript">console.log("Hello, World!");</code-input>
36-
35+
<form method="GET" action="https://google.com/search" target="_blank">
36+
<code-input language="JavaScript" name="q">console.log("Hello, World!");
37+
// A second line
38+
// A third line with &lt;html> tags</code-input>
39+
<input type="submit" value="Search Google For Code"/>
40+
</form>
3741
<script>
3842
// TODO: Delete this testing code
3943
var Prism = {

0 commit comments

Comments
 (0)