test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var tester = require('gitbook-tester');
  2. var test = require('tape');
  3. function expect(t, version, content, expected) {
  4. tester.builder()
  5. .withContent(content)
  6. .withLocalPlugin(__dirname)
  7. .withBookJson({
  8. gitbook: version,
  9. plugins: ['prism', '-highlight']
  10. })
  11. .create()
  12. .then(function(result) {
  13. t.equal(result[0].content, expected, 'gitbook version ' + version);
  14. })
  15. .done();
  16. }
  17. test('highlight javascript code block', function (t) {
  18. t.plan(2);
  19. var content = '```js\nfunction() { return true };\n```';
  20. var expected = '<pre class="language-"><code class="lang-js"><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>\n</code></pre>';
  21. expect(t, '>=2.4.1', content, expected);
  22. expect(t, '>=3.0.0', content, expected);
  23. });
  24. test('highlight csharp code using shortcut', function (t) {
  25. t.plan(2);
  26. var content = '```cs\nusing System; class Program {public static void Main(string[] args) {Console.WriteLine("Hello, world!"); } }\n```';
  27. var expected = '<pre class="language-"><code class="lang-cs"><span class="token keyword">using</span> System<span class="token punctuation">;</span> <span class="token keyword">class</span> <span class="token class-name">Program</span> <span class="token punctuation">{</span><span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">Main</span><span class="token punctuation">(</span><span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span><span class="token string">&quot;Hello, world!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>\n</code></pre>';
  28. expect(t, '>=2.4.1', content, expected);
  29. expect(t, '>=3.0.0', content, expected);
  30. });