z_6_filetest.gno

2.21 Kb ยท 56 lines
 1// PKGPATH: gno.land/r/demo/boards_test
 2package boards_test
 3
 4// SEND: 200000000ugnot
 5
 6import (
 7	"std"
 8	"strconv"
 9
10	"gno.land/p/demo/testutils"
11	"gno.land/r/demo/boards"
12	"gno.land/r/demo/users"
13)
14
15var (
16	bid boards.BoardID
17	pid boards.PostID
18	rid boards.PostID
19)
20
21func init() {
22	caller := testutils.TestAddress("caller")
23	std.TestSetRealm(std.NewUserRealm(caller))
24	users.Register("", "gnouser", "my profile")
25
26	bid = boards.CreateBoard("test_board")
27	boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
28	pid = boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
29	rid = boards.CreateReply(bid, pid, pid, "Reply of the second post")
30}
31
32func main() {
33	caller := testutils.TestAddress("caller")
34	std.TestSetRealm(std.NewUserRealm(caller))
35	boards.CreateReply(bid, pid, pid, "Second reply of the second post\n")
36	boards.CreateReply(bid, pid, rid, "First reply of the first reply\n")
37	println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
38}
39
40// Output:
41// # Second Post (title)
42//
43// Body of the second post. (body)
44// \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/2) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&postid=2&threadid=2)] \[[repost](/r/demo/boards$help&func=CreateRepost&bid=1&postid=2)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&postid=2&threadid=2)]
45//
46// > Reply of the second post
47// > \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/2/3) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&postid=3&threadid=2)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&postid=3&threadid=2)]
48// >
49// > > First reply of the first reply
50// > >
51// > > \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/2/5) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&postid=5&threadid=2)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&postid=5&threadid=2)]
52//
53// > Second reply of the second post
54// >
55// > \- [@gnouser](/r/demo/users:gnouser), [2009-02-13 11:31pm (UTC)](/r/demo/boards:test_board/2/4) \[[reply](/r/demo/boards$help&func=CreateReply&bid=1&postid=4&threadid=2)] \[[x](/r/demo/boards$help&func=DeletePost&bid=1&postid=4&threadid=2)]
56//