--[[-- 拷贝漫画 chapter2 图片排序用例。 @module tests.moonsource_copymanga.protocol_spec --]] ---@diagnostic disable: undefined-field, missing-fields, redundant-parameter, missing-parameter, inject-field, assign-type-mismatch, param-type-mismatch, cast-type-mismatch, return-type-mismatch, cast-local-type local Assert = require("support.assert") local Protocol = require("moonsource_copymanga.protocol") do local images, err = Protocol.chapterImages({ results = { chapter = { contents = { { url = "https://img.example/002.c800x.webp" }, { url = "https://img.example/001.c800x.webp" }, }, words = { 1, 0 }, }, }, }) Assert.is_nil(err) Assert.len(images, 2) Assert.eq(images[1], "https://img.example/001.c800x.jpg") Assert.eq(images[2], "https://img.example/002.c800x.jpg") end do local images, err = Protocol.chapterImages({ chapter = { contents = { { url = "https://img.example/a.webp.c1500x.webp" }, { url = "https://img.example/b.jpg.c2000x.jpg" }, }, }, }) Assert.is_nil(err) Assert.eq(images[1], "https://img.example/a.jpg.c800x.jpg") Assert.eq(images[2], "https://img.example/b.jpg.c800x.jpg") end do local images, err = Protocol.chapterImages({ chapter = { contents = { { url = "https://img.example/001.webp" }, { url = "https://img.example/002.webp" }, }, }, }) Assert.is_nil(err) Assert.eq(images[1], "https://img.example/001.webp") Assert.eq(images[2], "https://img.example/002.webp") end do local images, err = Protocol.chapterImages({}) Assert.is_nil(images) Assert.eq(err, "章节图片解析失败") end do local images, err = Protocol.chapterImages({ chapter = { contents = { { url = "not-a-url" } }, words = { 0 } }, }) Assert.is_nil(images) Assert.eq(err, "章节图片解析失败") end