From cee2bec9a59875519b663e9791cf62abe4cd0055 Mon Sep 17 00:00:00 2001 From: Norman Meier Date: Thu, 13 Jul 2023 19:18:35 +0200 Subject: [PATCH] bug examples Signed-off-by: Norman Meier --- .../gno.land/r/demo/bugs/bugmin/bugmin.gno | 22 +++++++++++++++++++ examples/gno.land/r/demo/bugs/bugmin/gno.mod | 1 + .../gno.land/r/demo/bugs/slice_splice/gno.mod | 1 + .../r/demo/bugs/slice_splice/slice_splice.gno | 20 +++++++++++++++++ .../r/demo/bugs/two_slices_one_array/gno.mod | 1 + .../two_slices_one_array.gno | 20 +++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 examples/gno.land/r/demo/bugs/bugmin/bugmin.gno create mode 100644 examples/gno.land/r/demo/bugs/bugmin/gno.mod create mode 100644 examples/gno.land/r/demo/bugs/slice_splice/gno.mod create mode 100644 examples/gno.land/r/demo/bugs/slice_splice/slice_splice.gno create mode 100644 examples/gno.land/r/demo/bugs/two_slices_one_array/gno.mod create mode 100644 examples/gno.land/r/demo/bugs/two_slices_one_array/two_slices_one_array.gno diff --git a/examples/gno.land/r/demo/bugs/bugmin/bugmin.gno b/examples/gno.land/r/demo/bugs/bugmin/bugmin.gno new file mode 100644 index 00000000000..74d658193bb --- /dev/null +++ b/examples/gno.land/r/demo/bugs/bugmin/bugmin.gno @@ -0,0 +1,22 @@ +package bugmin + +import ( + "strconv" + "strings" +) + +var slice = []string{"undead-element"} + +func Pop() { + slice = slice[:len(slice)-1] +} + +func Push() { + slice = append(slice, "new-element") +} + +func Render(path string) string { + str := strings.Join(slice, ", ") + "\n\n" + str += "len: " + strconv.Itoa(len(slice)) + "\n\n" + return str +} diff --git a/examples/gno.land/r/demo/bugs/bugmin/gno.mod b/examples/gno.land/r/demo/bugs/bugmin/gno.mod new file mode 100644 index 00000000000..36cdd9d76a0 --- /dev/null +++ b/examples/gno.land/r/demo/bugs/bugmin/gno.mod @@ -0,0 +1 @@ +module "gno.land/r/demo/bugs/bugmin" \ No newline at end of file diff --git a/examples/gno.land/r/demo/bugs/slice_splice/gno.mod b/examples/gno.land/r/demo/bugs/slice_splice/gno.mod new file mode 100644 index 00000000000..f7a638504d0 --- /dev/null +++ b/examples/gno.land/r/demo/bugs/slice_splice/gno.mod @@ -0,0 +1 @@ +module "gno.land/r/demo/bugs/slice_splice" \ No newline at end of file diff --git a/examples/gno.land/r/demo/bugs/slice_splice/slice_splice.gno b/examples/gno.land/r/demo/bugs/slice_splice/slice_splice.gno new file mode 100644 index 00000000000..aa7a2eb03ba --- /dev/null +++ b/examples/gno.land/r/demo/bugs/slice_splice/slice_splice.gno @@ -0,0 +1,20 @@ +package slice_splice + +import ( + "strings" +) + +var slice = []string{} + +func Push() { + slice = append(slice, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") +} + +func Splice() []string { + slice = slice[4:5] + return slice +} + +func Render(path string) string { + return strings.Join(slice, ",") +} diff --git a/examples/gno.land/r/demo/bugs/two_slices_one_array/gno.mod b/examples/gno.land/r/demo/bugs/two_slices_one_array/gno.mod new file mode 100644 index 00000000000..acc48a55204 --- /dev/null +++ b/examples/gno.land/r/demo/bugs/two_slices_one_array/gno.mod @@ -0,0 +1 @@ +module "gno.land/r/demo/bugs/two_slices_one_array" \ No newline at end of file diff --git a/examples/gno.land/r/demo/bugs/two_slices_one_array/two_slices_one_array.gno b/examples/gno.land/r/demo/bugs/two_slices_one_array/two_slices_one_array.gno new file mode 100644 index 00000000000..3799f569e6b --- /dev/null +++ b/examples/gno.land/r/demo/bugs/two_slices_one_array/two_slices_one_array.gno @@ -0,0 +1,20 @@ +package two_slices_one_array + +import ( + "strings" +) + +var ( + slice = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"} + sub1 []string = nil + sub2 []string = nil +) + +func Split() { + sub1 = slice[0:5] + sub2 = slice[5:] +} + +func Render(path string) string { + return "slice: " + strings.Join(slice, ",") + "\n\n" + "sub1: " + strings.Join(sub1, ",") + "\n\n" + "sub2: " + strings.Join(sub2, ",") +}