markdowncodeblocks.spec.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { MarkdownCodeBlocks } from '@jupyterlab/coreutils';
  4. const MULTI_LINE_BLOCK =
  5. 'Here is text\n\n```\na = 10\nb = 20\n```\n\nMore text.';
  6. const SINGLE_LINE_BLOCK = 'Here is text\n\n```a = 10```\n\nMore text.';
  7. const MULTI_LINE_BLOCK_WITH_LANGUAGE =
  8. 'Here is text\n\n```python\na = 10\nb = 20\n```\n\nMore text.';
  9. describe('@jupyterlab/coreutils', () => {
  10. describe('MarkdownCodeBlocks', () => {
  11. describe('.isMarkdown()', () => {
  12. it('should return true for a valid markdown extension', () => {
  13. const isMarkdown = MarkdownCodeBlocks.isMarkdown('.md');
  14. expect(isMarkdown).toBe(true);
  15. });
  16. });
  17. describe('.findMarkdownCodeBlocks()', () => {
  18. it('should find a simple block', () => {
  19. const codeblocks = MarkdownCodeBlocks.findMarkdownCodeBlocks(
  20. MULTI_LINE_BLOCK
  21. );
  22. expect(codeblocks.length).toBe(1);
  23. expect(codeblocks[0].code).toBe('a = 10\nb = 20\n');
  24. });
  25. it('should find a single line block', () => {
  26. const codeblocks = MarkdownCodeBlocks.findMarkdownCodeBlocks(
  27. SINGLE_LINE_BLOCK
  28. );
  29. expect(codeblocks.length).toBe(1);
  30. expect(codeblocks[0].code).toBe('a = 10');
  31. });
  32. it('should find a block with a language', () => {
  33. const codeblocks = MarkdownCodeBlocks.findMarkdownCodeBlocks(
  34. MULTI_LINE_BLOCK_WITH_LANGUAGE
  35. );
  36. expect(codeblocks.length).toBe(1);
  37. expect(codeblocks[0].code).toBe('a = 10\nb = 20\n');
  38. });
  39. });
  40. });
  41. });