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
+38-13
Original file line number
Diff line number
Diff line change
@@ -85,22 +85,20 @@ <h2 id="writing-tests-creating-your-test-case-file">Creating your test case file
85
85
86
86
87
87
<h2id="writing-tests-writing-your-test">Writing your test</h2>
88
-
<p>The structure of a test case file is as follows:</p>
89
-
<pre><code>
90
-
... language snippet...
91
-
----
92
-
... the simplified token stream you expect ...</code></pre>
93
88
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>
89
+
<p>A test case file is built up of two or three sections separated by ten or more dashes <code>-</code> starting at the begin of the line. The sections are the following:</p>
90
+
95
91
<ol>
96
92
<li>Your language snippet. The code you want to tokenize using Prism. (<strong>required</strong>)</li>
97
93
<li>
98
94
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.
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.
100
97
</li>
101
-
<li>A comment explaining the test case. (<em>optional</em>)</li>
98
+
<li>A brief comment explaining the test case. (<em>optional</em>)</li>
102
99
</ol>
103
-
<p>The easiest way would be to look at an existing test file:</p>
<h2id="writing-tests-the-easy-way">The easy way to write tests</h2>
121
119
<p>The easy way to create one or multiple new test case(s) is this:</p>
122
120
123
121
<ol>
124
-
<li>Create a new file for a new test case in<code>tests/languages/${language}</code>.</li>
122
+
<li>Create a new test case file<codeclass="language-none">tests/languages/{language}/{test-case}.test</code>.</li>
125
123
<li>Insert the code you want to test (and nothing more).</li>
126
124
<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>
125
+
<li>Run <codeclass="language-bash">npm run test:languages -- --insert</code>.</li>
126
+
<li>Done.</li>
127
+
</ol>
128
+
129
+
<p>Updating existing test case files is easy too!</p>
130
+
131
+
<ol>
132
+
<li>Run <codeclass="language-bash">npm run test:languages -- --update</code>.</li>
128
133
<li>Done.</li>
129
134
</ol>
130
135
131
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>
132
137
133
-
<p>Optionally, you can then also add comments to test cases.</p>
138
+
<p>More details about the command can be found <ahref="#writing-tests-insert-and-update">here</a>.</p>
139
+
140
+
<h2id="writing-tests-insert-and-update">Insert and update expected token streams</h2>
141
+
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>
143
+
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>
154
+
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>
134
158
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>
135
160
136
161
<h2id="writing-tests-explaining-the-simplified-token-stream">Explaining the simplified token stream</h2>
0 commit comments