markdowncodeblocks.spec.ts 1.4 KB

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