Skip to content

fix(render): replace rune cast with IndexByte and add autolink unit tests#146

Open
shayne-snap wants to merge 1 commit into
mainfrom
fix/markdown-rendering
Open

fix(render): replace rune cast with IndexByte and add autolink unit tests#146
shayne-snap wants to merge 1 commit into
mainfrom
fix/markdown-rendering

Conversation

@shayne-snap
Copy link
Copy Markdown
Contributor

变更内容

修复代码审查中发现的两个问题:

1. 使用 strings.IndexByte 替代 rune(input[i]) 模式

internal/tui/render/markdown.goescapeMarkdownLiteral 函数中将 strings.ContainsRune(markdownSpecialChars, rune(input[i])) 改为 strings.IndexByte(markdownSpecialChars, input[i]) >= 0,消除误导性的 rune(input[i]) 模式(对 ASCII 字符串逐字节操作)。

2. 新增 autolink 解析独立单元测试

新增 internal/tui/render/markdown_autolink_test.go,为三个核心函数添加表格驱动测试(共 33 个用例):

  • TestIsMarkdownAutolinkTarget — 协议检测(http/https/mailto)、大小写不敏感、无效输入
  • TestEscapeMarkdownLiteral — 所有 markdown 特殊字符转义
  • TestParseMarkdownAutolink — 两种转义模式、空/false 边界、HTML 标签排除、多个 autolink、blockquote 内、后接标点

测试

所有 37 个 render 包测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant