1. 修复swiper箭头点击动画丢失问题 - 改用固定7天窗口,滑动到边缘时整体滚动数据 - 保持dayIndex连续,确保swiper平滑动画 2. 修复宜忌两行显示压在一起 - 设置item固定高度32rpx和行距12rpx - 超出2行显示...省略号 3. 修复月历数字竖向排列问题 - 修正wxml嵌套结构,让42个格子正确排成6行7列 - 压缩格子高度,放大数字字体 4. 节日速查功能优化 - 默认显示3条,右侧添加更多
114 lines
3.6 KiB
Go
114 lines
3.6 KiB
Go
package service
|
||
|
||
import (
|
||
"encoding/json"
|
||
"os"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// 取自 zh.wikipedia.org「8月10日」页面的真实片段
|
||
const sampleWikitext = `'''8月10日'''是[[阳历]]年的第222天。
|
||
|
||
== 大事记 ==
|
||
=== 19世紀以前 ===
|
||
* [[前612年]]:[[亚述]]最后一位君主[[辛·沙里施昆]]死于[[尼尼微]],王国灭亡。
|
||
* [[955年]]:[[鄂圖一世 (神聖羅馬帝國)|鄂圖一世]]麾下的軍隊在[[第二次萊希菲爾德之戰 (955)|萊希菲爾德之戰]]中取得勝利。<ref>注释</ref>
|
||
=== 20世紀 ===
|
||
* [[1912年]]:[[威廉·布利斯]]出版了第一本关于[[童子军]]的书。
|
||
* [[1945年]]:{{le|蒙古}}对日宣战。
|
||
* [[2002年]]:-{zh-hans:凯尔·斯科特;zh-hk:卡爾·史葛;zh-tw:凱爾·斯科特;}-,英國職業足球運動員。
|
||
* 年份不详:某件无法确定年份的事情发生了。
|
||
|
||
== 出生 ==
|
||
* [[前156年]]:[[汉武帝]]刘彻,[[西汉]]皇帝([[前87年]]逝世)
|
||
* [[前156年]]:[[汉武帝]]刘彻,[[西汉]]皇帝([[前87年]]逝世)
|
||
* [[1874年]]:[[赫伯特·胡佛]],美国第31任[[总统]]([[1964年]]逝世)
|
||
|
||
== 逝世 ==
|
||
* [[258年]]:[[羅馬的聖老楞佐]],基督教殉道者
|
||
|
||
== 节假日和习俗 ==
|
||
* {{flag|厄瓜多尔}}:独立日
|
||
* 世界[[狮子]]日
|
||
|
||
==参考资料==
|
||
{{Commonscat}}
|
||
`
|
||
|
||
func TestParseDayPage(t *testing.T) {
|
||
items := parseDayPage(sampleWikitext)
|
||
|
||
count := func(kind string) int {
|
||
n := 0
|
||
for _, it := range items {
|
||
if it.Kind == kind {
|
||
n++
|
||
}
|
||
}
|
||
return n
|
||
}
|
||
|
||
if got := count("event"); got != 6 {
|
||
t.Errorf("event 条目数 = %d, 期望 6", got)
|
||
}
|
||
if got := count("birth"); got != 2 { // 重复条目应去重
|
||
t.Errorf("birth 条目数 = %d, 期望 2", got)
|
||
}
|
||
if got := count("death"); got != 1 {
|
||
t.Errorf("death 条目数 = %d, 期望 1", got)
|
||
}
|
||
if got := count("festival"); got != 2 {
|
||
t.Errorf("festival 条目数 = %d, 期望 2", got)
|
||
}
|
||
|
||
// 校验具体条目的年份与文本清洗
|
||
assertItem := func(kind string, wantYear int, wantContent string) {
|
||
for _, it := range items {
|
||
if it.Kind == kind && it.Content == wantContent {
|
||
if it.Year != wantYear {
|
||
t.Errorf("%q 年份 = %d, 期望 %d", wantContent, it.Year, wantYear)
|
||
}
|
||
return
|
||
}
|
||
}
|
||
t.Errorf("未找到条目: kind=%s content=%q", kind, wantContent)
|
||
}
|
||
assertItem("event", -612, "亚述最后一位君主辛·沙里施昆死于尼尼微,王国灭亡。")
|
||
assertItem("event", 955, "鄂圖一世麾下的軍隊在萊希菲爾德之戰中取得勝利。")
|
||
assertItem("event", 0, "某件无法确定年份的事情发生了。")
|
||
assertItem("event", 2002, "凯尔·斯科特,英國職業足球運動員。")
|
||
assertItem("festival", 0, "厄瓜多尔:独立日")
|
||
assertItem("birth", -156, "汉武帝刘彻,西汉皇帝(前87年逝世)")
|
||
assertItem("festival", 0, "世界狮子日")
|
||
|
||
// 不应包含 wiki 语法残留
|
||
for _, it := range items {
|
||
if strings.Contains(it.Content, "[[") || strings.Contains(it.Content, "{{") ||
|
||
strings.Contains(it.Content, "<ref") {
|
||
t.Errorf("条目残留 wiki 语法: %q", it.Content)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestParseRealPage 若本地存在真实抓取的样本文件则验证(可选)
|
||
func TestParseRealPage(t *testing.T) {
|
||
data, err := os.ReadFile("/tmp/wiki_810.json")
|
||
if err != nil {
|
||
t.Skip("无真实样本文件,跳过")
|
||
}
|
||
var d struct {
|
||
Parse struct {
|
||
Wikitext string `json:"wikitext"`
|
||
} `json:"parse"`
|
||
}
|
||
if err := json.Unmarshal(data, &d); err != nil {
|
||
t.Fatalf("样本解析失败: %v", err)
|
||
}
|
||
items := parseDayPage(d.Parse.Wikitext)
|
||
if len(items) < 20 {
|
||
t.Errorf("真实页面解析条目过少: %d", len(items))
|
||
}
|
||
t.Logf("真实页面共解析 %d 条", len(items))
|
||
}
|