test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var tester = require('gitbook-tester');
  2. var test = require('tape');
  3. var pkg = require('./package.json');
  4. test('highlight javascript code block', function (t) {
  5. t.plan(1);
  6. tester.builder()
  7. .withContent('```js\nfunction() { return true };\n```')
  8. .withLocalPlugin(__dirname)
  9. .withBookJson({
  10. gitbook: pkg.engines.gitbook,
  11. plugins: ['prism', '-highlight']
  12. })
  13. .create()
  14. .then(function(result) {
  15. 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></code></pre>';
  16. t.equal(result[0].content, expected);
  17. })
  18. .done();
  19. });
  20. test('highlight csharp code using shortcut', function (t) {
  21. t.plan(1);
  22. tester.builder()
  23. .withContent('```cs\nusing System; class Program {public static void Main(string[] args) {Console.WriteLine("Hello, world!"); } }\n```')
  24. .withLocalPlugin(__dirname)
  25. .withBookJson({
  26. gitbook: pkg.engines.gitbook,
  27. plugins: ['prism', '-highlight']
  28. })
  29. .create()
  30. .then(function(result) {
  31. 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></code></pre>';
  32. t.equal(result[0].content, expected);
  33. })
  34. .done();
  35. });