markdowncodeblocks.spec.ts 1.4 KB

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