File: casual_date_test.go

package info (click to toggle)
golang-github-olebedev-when 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 488 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package zh_test

import (
	"testing"
	"time"

	"github.com/olebedev/when"
	"github.com/olebedev/when/rules"
	"github.com/olebedev/when/rules/zh"
)

func TestCasualDate(t *testing.T) {
	fixt := []Fixture{
		{"后天中午", 0, "后天", (2 * 24) * time.Hour},
		{"大后天中午", 0, "大后天", (3 * 24) * time.Hour},
		{"昨天", 0, "昨天", (-1 * 24) * time.Hour},
		{"前天", 0, "前天", (-2 * 24) * time.Hour},
		{"大前天", 0, "大前天", (-3 * 24) * time.Hour},
		{"下月", 0, "下月", (31 * 24) * time.Hour},
		{"下个月", 0, "下个月", (31 * 24) * time.Hour},
		{"下下月", 0, "下下月", (31*24 + 30*24) * time.Hour},
		{"下下个月", 0, "下下个月", (31*24 + 30*24) * time.Hour},
		{"明年", 0, "明年", (365 * 24) * time.Hour},
		{"后年", 0, "后年", now.AddDate(2, 0, 0).Sub(now)},
		{"下月6号", 0, "下月6号", 552 * time.Hour},
	}

	w := when.New(nil)

	w.Add(zh.CasualDate(rules.Override))

	ApplyFixtures(t, "zh.TestCasualDate", w, fixt)
}

/*
	(([1-9](?:月|-|/|\.|))|1[0-2])\s*(月|-|/|\.|)\s*([1-9]|1[0-9]|2[0-9]|3[0-1])\s*(日|号)?(?:\W|$)
*/