From f984ee1b24543497d2d97f01fe2f7df6a54e0e72 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Wed, 18 Sep 2024 20:40:11 +0200 Subject: [PATCH 1/2] feat(examples): add simplest "counter" realm --- examples/gno.land/r/demo/counter/counter.gno | 14 ++++++++++++++ examples/gno.land/r/demo/counter/gno.mod | 1 + 2 files changed, 15 insertions(+) create mode 100644 examples/gno.land/r/demo/counter/counter.gno create mode 100644 examples/gno.land/r/demo/counter/gno.mod diff --git a/examples/gno.land/r/demo/counter/counter.gno b/examples/gno.land/r/demo/counter/counter.gno new file mode 100644 index 00000000000..43943e114dc --- /dev/null +++ b/examples/gno.land/r/demo/counter/counter.gno @@ -0,0 +1,14 @@ +package counter + +import "strconv" + +var counter int + +func Increment() int { + counter++ + return counter +} + +func Render(_ string) string { + return strconv.Itoa(counter) +} diff --git a/examples/gno.land/r/demo/counter/gno.mod b/examples/gno.land/r/demo/counter/gno.mod new file mode 100644 index 00000000000..332d4e6da6a --- /dev/null +++ b/examples/gno.land/r/demo/counter/gno.mod @@ -0,0 +1 @@ +module gno.land/r/demo/counter From 00d32b5d958d1f7974d20c524005ffa3465122ed Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Fri, 20 Sep 2024 10:42:21 +0200 Subject: [PATCH 2/2] add test file --- .../gno.land/r/demo/counter/counter_test.gno | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/gno.land/r/demo/counter/counter_test.gno diff --git a/examples/gno.land/r/demo/counter/counter_test.gno b/examples/gno.land/r/demo/counter/counter_test.gno new file mode 100644 index 00000000000..352889f7e59 --- /dev/null +++ b/examples/gno.land/r/demo/counter/counter_test.gno @@ -0,0 +1,22 @@ +package counter + +import "testing" + +func TestIncrement(t *testing.T) { + counter = 0 + val := Increment() + if val != 1 { + t.Fatalf("result from Increment(): %d != 1", val) + } + if counter != val { + t.Fatalf("counter (%d) != val (%d)", counter, val) + } +} + +func TestRender(t *testing.T) { + counter = 1337 + res := Render("") + if res != "1337" { + t.Fatalf("render result %q != %q", res, "1337") + } +}