package dingtalk import "testing" func TestSanitizeDisplayAnswerRemovesInternalReferenceMarkers(t *testing.T) { tests := []struct { name string input string want string }{ { name: "adjacent inline markers", input: "结论支持该功能[[ref id=\"c2\"]][[ref id=\"c4\"]]。", want: "结论支持该功能。", }, { name: "leading marker group and chinese colon", input: "[[ref id=\"c2\"]][[ref id=\"c4\"]]:建议先检查配置。", want: "建议先检查配置。", }, { name: "leading marker group and ascii colon on second line", input: "第一段。\n[[ref id='c12']] : Second paragraph.", want: "第一段。\nSecond paragraph.", }, { name: "normal punctuation remains natural", input: "标题:[[ref id=\"c1\"]] 详细说明", want: "标题:详细说明", }, { name: "spaces around marker collapse to one", input: "Feature A [[ref id=\"c3\"]] remains supported.", want: "Feature A remains supported.", }, { name: "unrelated double bracket syntax is preserved", input: "请保留 [[wiki|页面名称]] 和 [普通链接](https://example.com)。", want: "请保留 [[wiki|页面名称]] 和 [普通链接](https://example.com)。", }, { name: "content without references remains byte for byte unchanged", input: "Protocol: value ; keep spacing\n indented", want: "Protocol: value ; keep spacing\n indented", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := sanitizeDisplayAnswer(tt.input); got != tt.want { t.Fatalf("sanitizeDisplayAnswer()=%q, want %q", got, tt.want) } }) } } func TestSanitizeDisplayAnswerHoldsBackDanglingStreamingReference(t *testing.T) { for _, input := range []string{ "答案正文[[ref", "答案正文[[ref id=\"c", "答案正文[[ref id=\"c2\"", } { if got := sanitizeDisplayAnswer(input); got != "答案正文" { t.Fatalf("sanitizeDisplayAnswer(%q)=%q", input, got) } } }