z_8_filetest.gno
1.72 Kb ยท 49 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 rid boards.PostID
19)
20
21func init() {
22 testing.SetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))) // so that CurrentRealm.Addr() matches OrigCaller
23 users.Register("gnouser123")
24
25 bid = boards.CreateBoard("test_board")
26 boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)")
27 pid = boards.CreateThread(bid, "Second Post (title)", "Body of the second post. (body)")
28 rid = boards.CreateReply(bid, pid, pid, "Reply of the second post")
29}
30
31func main() {
32 testing.SetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")))
33 boards.CreateReply(bid, pid, pid, "Second reply of the second post\n")
34 rid2 := boards.CreateReply(bid, pid, rid, "First reply of the first reply\n")
35 println(boards.Render("test_board/" + strconv.Itoa(int(pid)) + "/" + strconv.Itoa(int(rid2))))
36}
37
38// Output:
39// _[see thread](/r/demo/boards:test_board/2)_
40//
41// Reply of the second post
42// \- [@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)]
43//
44// _[see all 1 replies](/r/demo/boards:test_board/2/3)_
45//
46// > First reply of the first reply
47// >
48// > \- [@gnouser123](/u/gnouser123), [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)]
49//