mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
12f4029610
* feat: telegram use parse mode ModeMarkdownV2 instead of ModeHTML * handle expandable block quotation starts, add test for all md2 formats * fix: linter issue * feat: added flag use_markdown_v2, corrected config, updated documentation * move parseChatID to parser_markdown_to_html * fix: tests and linter issues * fix: case with ~ * test: fixed Test_markdownToTelegramMarkdownV2 * fix: regex block-quote line > * fix: linter issues * fix: send chunk param mismatched, in edit msg use HTML parse mode too * fix: remove from .gitignore redundant comment
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package telegram
|
|
|
|
import (
|
|
_ "embed"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
//go:embed testdata/md2_all_formats.txt
|
|
var md2AllFormats string
|
|
|
|
func Test_markdownToTelegramMarkdownV2(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "heading -> bolding",
|
|
input: `## HeadingH2 #`,
|
|
expected: "*HeadingH2 \\#*",
|
|
},
|
|
{
|
|
name: "strikethrough",
|
|
input: "~strikethroughMD~",
|
|
expected: "~strikethroughMD~",
|
|
},
|
|
{
|
|
name: "inline URL",
|
|
input: "[inline URL](http://www.example.com/)",
|
|
expected: "[inline URL](http://www.example.com/)",
|
|
},
|
|
{
|
|
name: "all telegram formats",
|
|
input: md2AllFormats,
|
|
expected: md2AllFormats,
|
|
},
|
|
{
|
|
name: "empty",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "one letter",
|
|
input: "o",
|
|
expected: "o",
|
|
},
|
|
{
|
|
name: "",
|
|
input: "*Last update: ~10 24h*",
|
|
expected: "*Last update: \\~10 24h*",
|
|
},
|
|
{
|
|
name: "",
|
|
input: "<Market Capitalization>",
|
|
expected: "\\<Market Capitalization\\>",
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
actual := markdownToTelegramMarkdownV2(tc.input)
|
|
|
|
require.EqualValues(t, tc.expected, actual)
|
|
})
|
|
}
|
|
}
|