-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnow_test.go
56 lines (39 loc) · 879 Bytes
/
now_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package hype
import (
"context"
"io/fs"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_NowNodes(t *testing.T) {
t.Parallel()
r := require.New(t)
tm, err := time.Parse(time.RFC822, "24 Aug 76 12:34 UTC")
r.NoError(err)
p := testParser(t, "testdata/now")
p.NowFn = func() time.Time {
return tm
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
doc, err := p.ParseExecuteFile(ctx, "hype.md")
r.NoError(err)
act := doc.String()
act = strings.TrimSpace(act)
// fmt.Println(act)
b, err := fs.ReadFile(p.FS, "hype.gold")
r.NoError(err)
exp := string(b)
exp = strings.TrimSpace(exp)
r.Equal(exp, act)
}
func Test_Now_MarshalJSON(t *testing.T) {
t.Parallel()
n := &Now{
Element: NewEl("now", nil),
}
n.Nodes = append(n.Nodes, Text("1/2/2006"))
testJSON(t, "now", n)
}