z_3_filetest.gno

1.52 Kb ยท 45 lines
 1// PKGPATH: gno.land/r/demo/boards_test
 2package boards_test
 3
 4// SEND: 1000000ugnot
 5
 6import (
 7	"std"
 8	"strconv"
 9	"testing"
10
11	"gno.land/r/demo/boards"
12	users "gno.land/r/gnoland/users/v1"
13)
14
15var (
16	bid boards.BoardID
17	pid boards.PostID
18)
19
20func init() {
21	testing.SetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
22	users.Register("gnouser123")
23
24	bid = boards.CreateBoard("test_board")
25	boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
26	pid = boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
27}
28
29func main() {
30	testing.SetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")))
31	rid := boards.CreateReply(bid, pid, pid, "Reply of the second post")
32	println(rid)
33	println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
34}
35
36// Output:
37// 3
38// # Second Post (title)
39//
40// Body of the second post. (body)
41// \- [@gnouser123](/u/gnouser123), [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)]
42//
43// > Reply of the second post
44// > \- [@gnouser123](/u/gnouser123), [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)]
45//