chore: 规范标点
This commit is contained in:
1 parent
e54390a9f8
commit
15e79887fa
84 files changed
+5439
-5398
No files matched your search
+16
-16
@@ -1,7 +1,7 @@
|
||||
/* test_attach.c - /include 的暂存、glob 展开与体积/类型判断
|
||||
*
|
||||
* 交互式挑选(attach_pick)要真终端才能测,由 e2e 第 55 段覆盖;
|
||||
* 这里测的是不需要人操作的那一半。
|
||||
* 交互式挑选 (attach_pick)要真终端才能测, 由 e2e 第 55 段覆盖;
|
||||
* 这里测的是不需要人操作的那一半.
|
||||
*/
|
||||
#include "attach.h"
|
||||
#include "image.h"
|
||||
@@ -52,8 +52,8 @@ static size_t count_type(const JsonValue *parts, const char *type)
|
||||
return n;
|
||||
}
|
||||
|
||||
/* 记一下回调被问了几次 —— 它只在遇到图片时该被问到。
|
||||
* 答案和计数放在一起,免得"计数版只实现了一种答案"这种测试自己的错。 */
|
||||
/* 记一下回调被问了几次 —— 它只在遇到图片时该被问到.
|
||||
* 答案和计数放在一起, 免得"计数版只实现了一种答案"这种测试自己的错. */
|
||||
static int ask_count;
|
||||
static int ask_answer;
|
||||
static int counting_ask(void *ud) { (void)ud; ask_count++; return ask_answer; }
|
||||
@@ -64,7 +64,7 @@ int main(void)
|
||||
char *dir = mkdtemp(tmpl);
|
||||
if (!dir) { perror("mkdtemp"); return 2; }
|
||||
|
||||
/* 备份目录也指到临时目录,别污染仓库 */
|
||||
/* 备份目录也指到临时目录, 别污染仓库 */
|
||||
image_set_bindir(dir);
|
||||
|
||||
char *f_c = xasprintf("%s/a.c", dir);
|
||||
@@ -78,7 +78,7 @@ int main(void)
|
||||
write_file(f_bin, "\x00\x01\x02binary", 9);
|
||||
write_file(f_png, PNG, sizeof PNG);
|
||||
{
|
||||
/* 超过单个文件上限(256 KB) */
|
||||
/* 超过单个文件上限 (256 KB) */
|
||||
size_t n = ATTACH_MAX_FILE + 1024;
|
||||
char *big = xmalloc(n);
|
||||
memset(big, 'x', n);
|
||||
@@ -103,13 +103,13 @@ int main(void)
|
||||
CHECK(txt && strstr(txt, "int main") != NULL, "内容带上了");
|
||||
CHECK(txt && strncmp(txt, "===== ", 6) == 0, "块开头标了来源路径");
|
||||
CHECK(txt && strchr(txt, '\n') != NULL, "结尾有换行");
|
||||
/* 只在本地记的来源,绝不能进块里(那会跟着发给服务端) */
|
||||
/* 只在本地记的来源, 绝不能进块里 (那会跟着发给服务端) */
|
||||
CHECK(p0 && json_get_string(p0, "source") == NULL,
|
||||
"块里不该有自造的 source 字段");
|
||||
json_free(parts);
|
||||
CHECK(attach_count() == 0, "取走之后暂存清空");
|
||||
|
||||
puts("取走即清空,clear 也是");
|
||||
puts("取走即清空, clear 也是");
|
||||
attach_glob(f_c, NULL, NULL, &skipped, err, sizeof err);
|
||||
CHECK(attach_count() == 1, "再附带一次");
|
||||
attach_clear();
|
||||
@@ -119,15 +119,15 @@ int main(void)
|
||||
puts("二进制文件跳过");
|
||||
attach_clear();
|
||||
added = attach_glob(f_bin, NULL, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 0 && skipped == 1, "二进制被跳过(added=%d skipped=%zu)",
|
||||
CHECK(added == 0 && skipped == 1, "二进制被跳过 (added=%d skipped=%zu)",
|
||||
added, skipped);
|
||||
|
||||
puts("超过单个文件上限的跳过");
|
||||
attach_clear();
|
||||
added = attach_glob(f_big, NULL, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 0 && skipped == 1, "太大的文本被跳过(added=%d)", added);
|
||||
CHECK(added == 0 && skipped == 1, "太大的文本被跳过 (added=%d)", added);
|
||||
|
||||
puts("图片:认内容不认扩展名,并走备份引用");
|
||||
puts("图片:认内容不认扩展名, 并走备份引用");
|
||||
attach_clear();
|
||||
added = attach_glob(f_png, NULL, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 1, "png 被收下");
|
||||
@@ -136,17 +136,17 @@ int main(void)
|
||||
CHECK(count_type(parts, "ligent_image") == 1, "应当是一个 ligent_image 引用块");
|
||||
json_free(parts);
|
||||
|
||||
puts("模型不收图时跳过图片(回调只在遇到图片时被问)");
|
||||
puts("模型不收图时跳过图片 (回调只在遇到图片时被问)");
|
||||
attach_clear();
|
||||
ask_count = 0; ask_answer = 1;
|
||||
added = attach_glob(f_txt, counting_ask, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 1, "纯文本照带");
|
||||
CHECK(ask_count == 0, "纯文本不该去问'能不能收图'(问了一次就是白探测)");
|
||||
CHECK(ask_count == 0, "纯文本不该去问'能不能收图' (问了一次就是白探测)");
|
||||
attach_clear();
|
||||
ask_count = 0; ask_answer = 0;
|
||||
added = attach_glob(f_png, counting_ask, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 0 && skipped == 1, "回调说不行就跳过");
|
||||
CHECK(ask_count == 1, "遇到图片时问了一次,实际 %d", ask_count);
|
||||
CHECK(ask_count == 1, "遇到图片时问了一次, 实际 %d", ask_count);
|
||||
|
||||
puts("匹配不到 / 参数非法");
|
||||
attach_clear();
|
||||
@@ -161,7 +161,7 @@ int main(void)
|
||||
attach_clear();
|
||||
char *pat = xasprintf("%s/*.txt", dir);
|
||||
added = attach_glob(pat, NULL, NULL, &skipped, err, sizeof err);
|
||||
CHECK(added == 1, "只有 b.txt 能带(big.txt 超限),实际 %d", added);
|
||||
CHECK(added == 1, "只有 b.txt 能带 (big.txt 超限), 实际 %d", added);
|
||||
CHECK(skipped == 1, "big.txt 被跳过");
|
||||
free(pat);
|
||||
attach_clear();
|
||||
@@ -172,6 +172,6 @@ int main(void)
|
||||
if (system(cmd) != 0) { }
|
||||
free(cmd);
|
||||
|
||||
printf("\n%d 项检查,%d 项失败\n", checks, failures);
|
||||
printf("\n%d 项检查, %d 项失败\n", checks, failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Reference in new issue
Block a user