Elffuss BraidHub

kikocis/continue public

7aa6d9f92b99 · 2.7 KiBRawPermalink
1import { headerIsMarkdown } from './headerIsMarkdown';
2
3describe('headerIsMarkdown', () => {
4 // Test exact match with common Markdown identifiers
5 it('should identify exact matches with common Markdown identifiers', () => {
6 expect(headerIsMarkdown('md')).toBe(true);
7 expect(headerIsMarkdown('markdown')).toBe(true);
8 expect(headerIsMarkdown('gfm')).toBe(true);
9 expect(headerIsMarkdown('github-markdown')).toBe(true);
10 });
11
12 // Test identifiers preceded by a space
13 it('should identify identifiers preceded by a space', () => {
14 expect(headerIsMarkdown('lang md')).toBe(true);
15 expect(headerIsMarkdown('something markdown')).toBe(true);
16 expect(headerIsMarkdown('language gfm')).toBe(true);
17 expect(headerIsMarkdown('spec github-markdown')).toBe(true);
18 });
19
20 // Test file extensions
21 it('should identify file names with markdown extensions', () => {
22 expect(headerIsMarkdown('example.md')).toBe(true);
23 expect(headerIsMarkdown('document.markdown')).toBe(true);
24 expect(headerIsMarkdown('readme.gfm')).toBe(true);
25 });
26
27 // Test more complex cases with extensions
28 it('should identify file names with markdown extensions followed by other text', () => {
29 expect(headerIsMarkdown('example.md additional text')).toBe(true);
30 expect(headerIsMarkdown('document.markdown with some description')).toBe(true);
31 expect(headerIsMarkdown('readme.gfm v2.0')).toBe(true);
32 });
33
34 // Test non-markdown cases
35 it('should not identify non-markdown headers', () => {
36 expect(headerIsMarkdown('javascript')).toBe(false);
37 expect(headerIsMarkdown('typescript')).toBe(false);
38 expect(headerIsMarkdown('plain')).toBe(false);
39 expect(headerIsMarkdown('python')).toBe(false);
40 });
41
42 // Test edge cases
43 it('should handle edge cases correctly', () => {
44 expect(headerIsMarkdown('')).toBe(false);
45 expect(headerIsMarkdown('mdx')).toBe(false); // Similar but not exactly "md"
46 expect(headerIsMarkdown('readme md')).toBe(true);
47 expect(headerIsMarkdown('md.js')).toBe(false); // "md" is not the extension
48 });
49
50 // Test case sensitivity
51 it('should respect case sensitivity', () => {
52 expect(headerIsMarkdown('MD')).toBe(false);
53 expect(headerIsMarkdown('MARKDOWN')).toBe(false);
54 expect(headerIsMarkdown('example.MD')).toBe(false);
55 expect(headerIsMarkdown('lang MD')).toBe(false);
56 });
57
58 // Test with special characters and spacing
59 it('should handle special characters and spacing correctly', () => {
60 expect(headerIsMarkdown(' md')).toBe(true); // Space before "md"
61 expect(headerIsMarkdown('md ')).toBe(true); // Space after "md"
62 expect(headerIsMarkdown('hello-md')).toBe(false); // "md" with hyphen prefix
63 expect(headerIsMarkdown('markdown:')).toBe(false); // "markdown" with suffix
64 });
65});