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
<p>All tests are sorted into directories in the <code>tests/languages</code> directory. Each directory name encodes, which language you are currently testing.</p>
53
-
<p><strong>All language names must match the names from the definition in <code>components.js</code>.</strong></p>
53
+
<p><strong>All language names must match the names from the definition in <code>components.json</code>.</strong></p>
54
54
55
55
<h3>Example 1: testing a language in isolation (default use case)</h3>
56
56
<p>Just put your test file into the directory of the language you want to test.</p>
@@ -92,8 +92,8 @@ <h2 id="writing-tests-writing-your-test">Writing your test</h2>
92
92
<li>Your language snippet. The code you want to tokenize using Prism. (<strong>required</strong>)</li>
93
93
<li>
94
94
The simplified token stream you expect. Needs to be valid JSON. (<em>optional</em>) <br>
95
-
Instead of manually inserting the expected token stream yourself, prefer using the <codeclass="language-bash">npm run test:languages -- --insert</code> command. You can read more about this and related commands <ahref="#writing-tests-insert-and-update">here</a>. <br>
96
-
If there no token stream defined, the test case will fail unless the <code>--insert</code> or <code>--update</code> flag is present when running the test command.
95
+
The test runner will automatically insert this if not present. <strong>Carefully check</strong> that the inserted token stream is what you expected. <br>
96
+
If the test case fails because the JSON is present but incorrect, then you can use the <ahref="#writing-tests-update"><code>--update</code> flag</a> to overwrite it.
97
97
</li>
98
98
<li>A brief comment explaining the test case. (<em>optional</em>)</li>
99
99
</ol>
@@ -122,7 +122,7 @@ <h2 id="writing-tests-the-easy-way">The easy way to write tests</h2>
122
122
<li>Create a new test case file <codeclass="language-none">tests/languages/{language}/{test-case}.test</code>.</li>
123
123
<li>Insert the code you want to test (and nothing more).</li>
124
124
<li>Repeat the first two steps for as many test cases as you want.</li>
125
-
<li>Run <codeclass="language-bash">npm run test:languages -- --insert</code>.</li>
125
+
<li>Run <codeclass="language-bash">npm run test:languages</code>.</li>
126
126
<li>Done.</li>
127
127
</ol>
128
128
@@ -135,28 +135,16 @@ <h2 id="writing-tests-the-easy-way">The easy way to write tests</h2>
135
135
136
136
<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>
137
137
138
-
<p>More details about the command can be found <ahref="#writing-tests-insert-and-update">here</a>.</p>
139
138
140
-
<h2id="writing-tests-insert-and-update">Insert and update expected token streams</h2>
139
+
<h2id="writing-tests-update">Updating tests</h2>
141
140
142
-
<p>When creating and changing languages, their test files have to be updated to properly test the language. The rather tedious task of updating test files can be automated using the following commands:</p>
141
+
<p>When creating and changing languages, their test files have to be updated to properly test the language. The rather tedious task of updating test files can be automated using the following command:</p>
143
142
144
-
<ul>
145
-
<li>
146
-
<pre><codeclass="language-bash">npm run test:languages -- --insert</code></pre>
147
-
148
-
<p>This will insert the current actual token stream into all test files without an expected token stream. Test files that have an expected token stream are not affected.</p>
149
-
150
-
<p>This command is intended to be used when you want to create new test files while not updating existing ones.</p>
151
-
</li>
152
-
<li>
153
-
<pre><codeclass="language-bash">npm run test:languages -- --update</code></pre>
143
+
<pre><codeclass="language-bash">npm run test:languages -- --update</code></pre>
154
144
155
-
<p>Updates (overwrites) the expected token stream of all failing test files and all test files that do not have an expected token stream. The language tests are guaranteed to pass after running this command.</p>
156
-
</li>
157
-
</ul>
145
+
<p>Updates (overwrites) the expected token stream of all failing test files. The language tests are guaranteed to pass after running this command.</p>
158
146
159
-
<p><em>Keep in mind:</em>Both commands make it easy to create/update test files but this doesn't mean that the tests will be correct. <strong>Always carefully check the inserted/updated token streams!</strong></p>
147
+
<p><em>Keep in mind:</em>This command makes it easy to create/update test files but this doesn't mean that the tests will be correct. <strong>Always carefully check the inserted/updated token streams!</strong></p>
160
148
161
149
<h2id="writing-tests-explaining-the-simplified-token-stream">Explaining the simplified token stream</h2>
162
150
@@ -169,7 +157,7 @@ <h2 id="writing-tests-explaining-the-simplified-token-stream">Explaining the sim
169
157
<li>All empty structures are removed.</li>
170
158
</ul>
171
159
172
-
<p>Note: The pretty-printed simplified token stream is indented using 4 spaces. You have to convert these to tabs after you copy-pasted the JSON. (Most editors today have an option that handles the conversion for you.)</p>
160
+
<p>The simplified token stream does not contain the aliases of a token.</p>
173
161
174
162
<p>For further information: reading the tests of the test runner (<code>tests/testrunner-tests.js</code>) will help you understand the transformation.</p>
0 commit comments