summaryrefslogtreecommitdiffstats
path: root/packages/gitbook/src/templating/__tests__/replaceShortcuts.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook/src/templating/__tests__/replaceShortcuts.js')
-rw-r--r--packages/gitbook/src/templating/__tests__/replaceShortcuts.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/gitbook/src/templating/__tests__/replaceShortcuts.js b/packages/gitbook/src/templating/__tests__/replaceShortcuts.js
new file mode 100644
index 0000000..1126f91
--- /dev/null
+++ b/packages/gitbook/src/templating/__tests__/replaceShortcuts.js
@@ -0,0 +1,31 @@
+const Immutable = require('immutable');
+
+const TemplateBlock = require('../../models/templateBlock');
+const replaceShortcuts = require('../replaceShortcuts');
+
+describe('replaceShortcuts', function() {
+ const blocks = Immutable.List([
+ TemplateBlock.create('math', {
+ shortcuts: {
+ start: '$$',
+ end: '$$',
+ parsers: ['markdown']
+ }
+ })
+ ]);
+
+ it('should correctly replace inline matches by block', function() {
+ const content = replaceShortcuts(blocks, 'test.md', 'Hello $$a = b$$');
+ expect(content).toBe('Hello {% math %}a = b{% endmath %}');
+ });
+
+ it('should correctly replace multiple inline matches by block', function() {
+ const content = replaceShortcuts(blocks, 'test.md', 'Hello $$a = b$$ and $$c = d$$');
+ expect(content).toBe('Hello {% math %}a = b{% endmath %} and {% math %}c = d{% endmath %}');
+ });
+
+ it('should correctly replace block matches', function() {
+ const content = replaceShortcuts(blocks, 'test.md', 'Hello\n$$\na = b\n$$\n');
+ expect(content).toBe('Hello\n{% math %}\na = b\n{% endmath %}\n');
+ });
+});