Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Playground

contract.gno

package render

import "strings"

func Hello() string {
	return "Hello World!"
}

func greetings(name string) string { // private
	return "Welcome, " + name + "!"
}

func Render(path string) string {
	switch {
	case path == "hello":
		return Hello()
	case strings.HasPrefix(path, "greetings/"):
		name := strings.Split(path, "/")[1] // take string after slash
		name = strings.Title(name)          // capitalize first letter
		return greetings(name)
	case path == "":
		out := "- [hello](/r/moul_basics_004:hello)\n"
		out += "- [greetings/Manfred](/r/moul_basics_004:greetings/Manfred)\n"
		return out
	}
	return "404"
}

contract_test.gno

package render

import "testing"

func Test(t *testing.T) {
	shouldEqual(t, "hello", "Hello World!")
	shouldEqual(t, "greetings/Manfred", "Welcome, Manfred!")
	shouldEqual(t, "foobar", "404")
}

func shouldEqual(t *testing.T, path string, expected string) {
	t.Helper()

	got := Render(path)
	if got != expected {
		t.Fatalf("expected %d, got %d.", expected, got)
	}
}

gnomod.toml

module = "gno.land/r/nym-moultest123/demo/render/v0"
gno = "0.9"

[addpkg]
  creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv"
  height = 186406
  max_deposit = "5000000ugnot"

render_example_test.gno

package render

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// - [hello](/r/moul_basics_004:hello)
	// - [greetings/Manfred](/r/moul_basics_004:greetings/Manfred)
}