--[[-- moonsource_legadorule.parser 离线用例:搜索、详情、目录翻页、正文翻页与取消,http 走脚本化桩。 @module tests.legadorule.parser_spec --]] ---@diagnostic disable: undefined-field, missing-fields, redundant-parameter, missing-parameter, inject-field, assign-type-mismatch, param-type-mismatch local Assert = require("support.assert") local pages, calls = {}, {} package.preload["http.request"] = function() local function respond(url, cb) calls[#calls + 1] = url local body = pages[url] if body == nil then return cb(nil, "HTTP 404", { code = 404 }) end cb(body, nil, { code = 200 }) end return { header = function() return nil end, get = function(url, _opts, cb) respond(url, cb) return { cancel = function() end } end, post = function(url, _body, _opts, cb) respond(url, cb) return { cancel = function() end } end, } end package.preload["http.cookie_jar"] = function() return { new = function() return {} end } end local Parser = require("moonsource_legadorule.parser") local Client = require("moonsource_legadorule.client") local rule = { bookSourceUrl = "https://a.com", searchUrl = "/s?q={{key}}", ruleSearch = { bookList = ".r li", name = "a@text", bookUrl = "a@href", author = "span@text##作者:" }, ruleBookInfo = { name = "h1@text", intro = ".intro@text", tocUrl = ".toc@href" }, ruleToc = { chapterList = ".c a", chapterName = "text", chapterUrl = "href", nextTocUrl = ".next@href" }, ruleContent = { content = "#t@html", nextContentUrl = ".np@href" }, } local function wait(fn) local a, b fn(function(x, y) a, b = x, y end) return a, b end pages["https://a.com/s?q=%E6%96%97"] = '
' pages["https://a.com/b/1"] = '