Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

test(util): cover empty, nested and mismatched JSON boundaries

askalfba4cc5432ec7
diff --git a/runtime/krillinai/pkg/util/json_test.go b/runtime/krillinai/pkg/util/json_test.go
index 4b8765ac..9857141d 100644
--- a/runtime/krillinai/pkg/util/json_test.go
+++ b/runtime/krillinai/pkg/util/json_test.go
@@ -86,6 +86,31 @@ func TestExtractJSON(t *testing.T) {
response: `{"short_sentences":[{"text":"a"}`,
want: `{"short_sentences":[{"text":"a"}`,
},
+ {
+ name: "空对象",
+ response: "{}",
+ want: "{}",
+ },
+ {
+ name: "空数组",
+ response: "[]",
+ want: "[]",
+ },
+ {
+ name: "嵌套结构的多处尾随逗号",
+ response: `{"a":{"b":[{"c":1},]},}`,
+ want: `{"a":{"b":[{"c":1}]}}`,
+ },
+ {
+ name: "连续逗号一并去除",
+ response: `{"a":1,,}`,
+ want: `{"a":1}`,
+ },
+ {
+ name: "结束符不匹配时不做猜测",
+ response: "[}",
+ want: "[}",
+ },
}
for _, tt := range tests {