You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-suite.html
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -93,8 +93,11 @@ <h2 id="writing-tests-writing-your-test">Writing your test</h2>
93
93
94
94
<p>Your file is built up of two or three sections, separated by ten or more dashes <code>-</code>, starting at the begin of the line:</p>
95
95
<ol>
96
-
<li>Your language snippet. The code you want to compile using Prism. (<strong>required</strong>)</li>
97
-
<li>The simplified token stream you expect. Needs to be valid JSON. (<strong>required</strong>)</li>
96
+
<li>Your language snippet. The code you want to tokenize using Prism. (<strong>required</strong>)</li>
97
+
<li>
98
+
The simplified token stream you expect. Needs to be valid JSON. (<em>optional</em>) <br>
99
+
If there no token stream defined, the test case will fail unless the <code>--accept</code> flag is present when running the test command (e.g. <code>npm run test:languages -- --accept</code>). If the flag is present and there is no expected token stream, the runner will insert the actual token stream into the test case file, changing it.
100
+
</li>
98
101
<li>A comment explaining the test case. (<em>optional</em>)</li>
99
102
</ol>
100
103
<p>The easiest way would be to look at an existing test file:</p>
@@ -114,10 +117,25 @@ <h2 id="writing-tests-writing-your-test">Writing your test</h2>
114
117
115
118
This is a comment explaining this test case.</code></pre>
<p>The easy way to create one or multiple new test case(s) is this:</p>
122
+
123
+
<ol>
124
+
<li>Create a new file for a new test case in <code>tests/languages/${language}</code>.</li>
125
+
<li>Insert the code you want to test (and nothing more).</li>
126
+
<li>Repeat the first two steps for as many test cases as you want.</li>
127
+
<li>Run <code>npm run test:languages -- --accept</code>.</li>
128
+
<li>Done.</li>
129
+
</ol>
130
+
131
+
<p>This works by making the test runner insert the actual token stream of you test code as the expected token stream. <strong>Carefully check that the inserted token stream is actually what you expect or else the test is meaningless!</strong></p>
132
+
133
+
<p>Optionally, you can then also add comments to test cases.</p>
134
+
117
135
118
136
<h2id="writing-tests-explaining-the-simplified-token-stream">Explaining the simplified token stream</h2>
119
137
120
-
<p>While compiling, Prism transforms your source code into a token stream. This is basically a tree of nested tokens (or arrays, or strings).</p>
138
+
<p>While highlighting, Prism transforms your source code into a token stream. This is basically a tree of nested tokens (or arrays, or strings).</p>
121
139
<p>As these trees are hard to write by hand, the test runner uses a simplified version of it.</p>
0 commit comments