Skip to content

Commit 154b75a

Browse files
Input2 rm yaml (#732)
* Remove YAML from input2.html Move YAML information into input2.html. Then we don't need to process YAML. Signed-off-by: David A. Wheeler <[email protected]> * Improve input2 hint regular expressions Signed-off-by: David A. Wheeler <[email protected]> --------- Signed-off-by: David A. Wheeler <[email protected]>
1 parent 9ff8b38 commit 154b75a

File tree

2 files changed

+80
-60
lines changed

2 files changed

+80
-60
lines changed

docs/labs/input2.html

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="stylesheet" href="checker.css">
88
<script src="js-yaml.min.js"></script>
99
<script src="checker.js"></script>
10+
<script src="input2.js"></script>
1011
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
1112

1213
<!-- Sample expected answer -->
@@ -33,66 +34,6 @@
3334
\) , \s*
3435
</script>
3536

36-
<!--
37-
The following define hints. Hints are expressed in a JSON array, so:
38-
- \ in a regex is written as \\
39-
- " in a regex is written as \"
40-
- All field names and value strings must be quoted
41-
- commas must *separate* the entries - last one must NOT have a comma.
42-
-->
43-
<script id="info" type="application/yaml">
44-
---
45-
hints:
46-
- absent: ", $"
47-
text: This is a parameter, it must end with a comma.
48-
- absent: |
49-
query \( ["'`]id["'`] \)
50-
text: "Use query() with an 'id' parameter."
51-
- present: |
52-
query \( ["'`]id["'`] \) [^. ]
53-
text: 'After query("id") use a period to invoke a verification method.'
54-
- present: |
55-
(islength|Islength|IsLength|ISLENGTH)
56-
text: >
57-
JavaScript is case-sensitive. Use isLength instead of the case you have.
58-
- absent: isLength
59-
text: "Use isLength()."
60-
- present: |
61-
isLength \( m
62-
text: "You need to pass isLength() an object within {...}."
63-
- absent: matches
64-
text: "Use matches()."
65-
- present: |
66-
matches \( /[^^]
67-
text: "Match the whole string - begin the regular expression with ^"
68-
- present: |
69-
matches \( /.*[^$]/
70-
text: "Match the whole string - end the regular expression with $"
71-
- present: |
72-
matches \( /.*[^$]/
73-
text: Match the whole string - end the regular expression with $
74-
- present: |
75-
matches \( /\^\[A-Z\]-
76-
text: That would match only one letter before the dash, you need two.
77-
- present: |
78-
matches \( /.*(\[0-9\]|\d)\*
79-
text: >
80-
You need to match one or more digits; * allows 0 or more.
81-
A + would be better suited for this task.
82-
- present: |
83-
\s*, , $
84-
text: >
85-
You have two commas at the end. Use only one. You may need to
86-
scroll or increase the text area to see both of them.
87-
successes:
88-
- - query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\d+-[0-9]+$/),
89-
- - ' query (`id`) . isLength( {max:80}).matches(/^[A-Z]{2}-\d+-[0-9]+$/ ) , '
90-
failures:
91-
- - query('id').isLength({max:80}).matches( /^[A-Z]{2}-[0-9]+- [0-9]+$/ ),
92-
- - query('id').isLength().matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),
93-
- - query('id').isLength({max:80}).matches( /[A-Z]{2}-[0-9]+-[0-9]+/ ),
94-
- - query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\d+-[0-9]+$/)
95-
</script>
9637
</head>
9738
<body>
9839
<!-- For GitHub Pages formatting: -->

docs/labs/input2.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
info =
2+
{
3+
hints: [
4+
{
5+
absent: ", $",
6+
text: "This is a parameter, it must end with a comma."
7+
},
8+
{
9+
absent: String.raw`query \( ["'${BACKQUOTE}]id["'${BACKQUOTE}] \)`,
10+
text: "Use query() with an 'id' parameter."
11+
},
12+
{
13+
present: String.raw`query \( ["'${BACKQUOTE}]id["'${BACKQUOTE}] \) [^. ]`,
14+
text: "After query(\"id\") use a period to invoke a verification method."
15+
},
16+
{
17+
present: "(islength|Islength|IsLength|ISLENGTH)",
18+
text: "JavaScript is case-sensitive. Use isLength instead of the case you have.\n"
19+
},
20+
{
21+
absent: "isLength",
22+
text: "Use isLength()."
23+
},
24+
{
25+
present: String.raw`isLength \( [a-z]`,
26+
text: "You need to pass isLength() an object within {...}."
27+
},
28+
{
29+
absent: "matches",
30+
text: "Use matches()."
31+
},
32+
{
33+
present: String.raw`matches \( /[^^]`,
34+
text: "Match the whole string - begin the regular expression with ^"
35+
},
36+
{
37+
present: String.raw`matches \( /[^$/]*[^$]/`,
38+
text: "Match the whole string - end the regular expression with $"
39+
},
40+
{
41+
present: String.raw`matches \( /[^$/]*[^$]/`,
42+
text: "Match the whole string - end the regular expression with $"
43+
},
44+
{
45+
present: String.raw`matches \( /\^\[A-Z\]-`,
46+
text: "That would match only one letter before the dash, you need two."
47+
},
48+
{
49+
present: String.raw`matches \( /.*(\[0-9\]|\d)\*`,
50+
text: "You need to match one or more digits; * allows 0 or more. A + would be better suited for this task.\n"
51+
},
52+
{
53+
present: String.raw`\s*, , $`,
54+
text: "You have two commas at the end. Use only one. You may need to scroll or increase the text area to see both of them.\n"
55+
}
56+
],
57+
successes: [
58+
[
59+
"query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\\d+-[0-9]+$/),"
60+
],
61+
[
62+
" query (`id`) . isLength( {max:80}).matches(/^[A-Z]{2}-\\d+-[0-9]+$/ ) , "
63+
]
64+
],
65+
failures: [
66+
[
67+
"query('id').isLength({max:80}).matches( /^[A-Z]{2}-[0-9]+- [0-9]+$/ ),"
68+
],
69+
[
70+
"query('id').isLength().matches( /^[A-Z]{2}-[0-9]+-[0-9]+$/ ),"
71+
],
72+
[
73+
"query('id').isLength({max:80}).matches( /[A-Z]{2}-[0-9]+-[0-9]+/ ),"
74+
],
75+
[
76+
"query(`id`).isLength( {max:80}).matches(/^[A-Z]{2}-\\d+-[0-9]+$/)"
77+
]
78+
]
79+
}

0 commit comments

Comments
 (0)