|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestConvertMarkdownToMrkdwn(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + name string |
| 10 | + markdown string |
| 11 | + expected string |
| 12 | + }{ |
| 13 | + { |
| 14 | + name: "bold with double asterisks", |
| 15 | + markdown: "This is **bold** text", |
| 16 | + expected: "This is *bold* text", |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "bold with double underscores", |
| 20 | + markdown: "This is __bold__ text", |
| 21 | + expected: "This is *bold* text", |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "strikethrough", |
| 25 | + markdown: "This is ~~strikethrough~~ text", |
| 26 | + expected: "This is ~strikethrough~ text", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "inline code", |
| 30 | + markdown: "This is `code` text", |
| 31 | + expected: "This is `code` text", |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "link", |
| 35 | + markdown: "Check out [Google](https://google.com)", |
| 36 | + expected: "Check out <https://google.com|Google>", |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "code block with language", |
| 40 | + markdown: "```python\nprint('hello')\n```", |
| 41 | + expected: "```\nprint('hello')\n```", |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "code block without language", |
| 45 | + markdown: "```\ncode here\n```", |
| 46 | + expected: "```\ncode here\n```", |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "unordered list with asterisk", |
| 50 | + markdown: "* Item 1\n* Item 2", |
| 51 | + expected: "• Item 1\n• Item 2", |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "unordered list with dash", |
| 55 | + markdown: "- Item 1\n- Item 2", |
| 56 | + expected: "• Item 1\n• Item 2", |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "ordered list", |
| 60 | + markdown: "1. First\n2. Second", |
| 61 | + expected: "1. First\n2. Second", |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "mixed formatting", |
| 65 | + markdown: "This is **bold** and ~~strike~~ with a [link](https://example.com)", |
| 66 | + expected: "This is *bold* and ~strike~ with a <https://example.com|link>", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "italic with single asterisk", |
| 70 | + markdown: "This is *italic* text", |
| 71 | + expected: "This is _italic_ text", |
| 72 | + }, |
| 73 | + { |
| 74 | + name: "code block with complex language specifier", |
| 75 | + markdown: "```c++\nint main() {}\n```", |
| 76 | + expected: "```\nint main() {}\n```", |
| 77 | + }, |
| 78 | + { |
| 79 | + name: "code block with c# language", |
| 80 | + markdown: "```c#\npublic void Main() {}\n```", |
| 81 | + expected: "```\npublic void Main() {}\n```", |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "code block with hyphenated language", |
| 85 | + markdown: "```objective-c\n@interface MyClass\n```", |
| 86 | + expected: "```\n@interface MyClass\n```", |
| 87 | + }, |
| 88 | + } |
| 89 | + |
| 90 | + for _, tt := range tests { |
| 91 | + t.Run(tt.name, func(t *testing.T) { |
| 92 | + result := convertMarkdownToMrkdwn(tt.markdown) |
| 93 | + if result != tt.expected { |
| 94 | + t.Errorf("convertMarkdownToMrkdwn() = %q, want %q", result, tt.expected) |
| 95 | + } |
| 96 | + }) |
| 97 | + } |
| 98 | +} |
0 commit comments