Skip to content

Commit

Permalink
chore: Merge remote-tracking branch 'origin/master' into genesis-stdlibs
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz committed Nov 26, 2024
2 parents 8943a68 + 4004ba1 commit 1231f81
Show file tree
Hide file tree
Showing 21 changed files with 1,016 additions and 77 deletions.
5 changes: 1 addition & 4 deletions examples/gno.land/p/demo/groups/gno.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module gno.land/p/demo/groups

require (
gno.land/p/demo/rat v0.0.0-latest
gno.land/r/demo/boards v0.0.0-latest
)
require gno.land/p/demo/rat v0.0.0-latest
8 changes: 0 additions & 8 deletions examples/gno.land/p/demo/groups/groups.gno

This file was deleted.

1 change: 0 additions & 1 deletion examples/gno.land/p/demo/tests/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ module gno.land/p/demo/tests
require (
gno.land/p/demo/tests/subtests v0.0.0-latest
gno.land/p/demo/uassert v0.0.0-latest
gno.land/r/demo/tests v0.0.0-latest
)
13 changes: 0 additions & 13 deletions examples/gno.land/p/demo/tests/tests.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ import (
"std"

psubtests "gno.land/p/demo/tests/subtests"
"gno.land/r/demo/tests"
rtests "gno.land/r/demo/tests"
)

const World = "world"

// IncCounter demonstrates that it's possible to call a realm function from
// a package. So a package can potentially write into the store, by calling
// an other realm.
func IncCounter() {
tests.IncCounter()
}

func CurrentRealmPath() string {
return std.CurrentRealm().PkgPath()
}
Expand Down Expand Up @@ -64,10 +55,6 @@ func GetPSubtestsPrevRealm() std.Realm {
return psubtests.GetPrevRealm()
}

func GetRTestsGetPrevRealm() std.Realm {
return rtests.GetPrevRealm()
}

// Warning: unsafe pattern.
func Exec(fn func()) {
fn()
Expand Down
16 changes: 0 additions & 16 deletions examples/gno.land/p/demo/tests/z0_filetest.gno

This file was deleted.

84 changes: 84 additions & 0 deletions examples/gno.land/p/n2p5/chonk/chonk.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Package chonk provides a simple way to store arbitrarily large strings
// in a linked list across transactions for efficient storage and retrieval.
// A Chonk support three operations: Add, Flush, and Scanner.
// - Add appends a string to the Chonk.
// - Flush clears the Chonk.
// - Scanner is used to iterate over the chunks in the Chonk.
package chonk

// Chonk is a linked list string storage and
// retrieval system for fine bois.
type Chonk struct {
first *chunk
last *chunk
}

// chunk is a linked list node for Chonk
type chunk struct {
text string
next *chunk
}

// New creates a reference to a new Chonk
func New() *Chonk {
return &Chonk{}
}

// Add appends a string to the Chonk. If the Chonk is empty,
// the string will be the first and last chunk. Otherwise,
// the string will be appended to the end of the Chonk.
func (c *Chonk) Add(text string) {
next := &chunk{text: text}
if c.first == nil {
c.first = next
c.last = next
return
}
c.last.next = next
c.last = next
}

// Flush clears the Chonk by setting the first and last
// chunks to nil. This will allow the garbage collector to
// free the memory used by the Chonk.
func (c *Chonk) Flush() {
c.first = nil
c.last = nil
}

// Scanner returns a new Scanner for the Chonk. The Scanner
// is used to iterate over the chunks in the Chonk.
func (c *Chonk) Scanner() *Scanner {
return &Scanner{
next: c.first,
}
}

// Scanner is a simple string scanner for Chonk. It is used
// to iterate over the chunks in a Chonk from first to last.
type Scanner struct {
current *chunk
next *chunk
}

// Scan advances the scanner to the next chunk. It returns
// true if there is a next chunk, and false if there is not.
func (s *Scanner) Scan() bool {
if s.next != nil {
s.current = s.next
s.next = s.next.next
return true
}
return false
}

// Text returns the current chunk. It is only valid to call
// this method after a call to Scan returns true. Expected usage:
//
// scanner := chonk.Scanner()
// for scanner.Scan() {
// fmt.Println(scanner.Text())
// }
func (s *Scanner) Text() string {
return s.current.text
}
54 changes: 54 additions & 0 deletions examples/gno.land/p/n2p5/chonk/chonk_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package chonk

import (
"testing"
)

func TestChonk(t *testing.T) {
t.Parallel()
c := New()
testTable := []struct {
name string
chunks []string
}{
{
name: "empty",
chunks: []string{},
},
{
name: "single chunk",
chunks: []string{"a"},
},
{
name: "multiple chunks",
chunks: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
},
{
name: "multiline chunks",
chunks: []string{"1a\nb\nc\n\n", "d\ne\nf", "g\nh\ni", "j\nk\nl\n\n\n\n"},
},
{
name: "empty",
chunks: []string{},
},
}
testChonk := func(t *testing.T, c *Chonk, chunks []string) {
for _, chunk := range chunks {
c.Add(chunk)
}
scanner := c.Scanner()
i := 0
for scanner.Scan() {
if scanner.Text() != chunks[i] {
t.Errorf("expected %s, got %s", chunks[i], scanner.Text())
}
i++
}
}
for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {
testChonk(t, c, test.chunks)
c.Flush()
})
}
}
1 change: 1 addition & 0 deletions examples/gno.land/p/n2p5/chonk/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/n2p5/chonk
7 changes: 7 additions & 0 deletions examples/gno.land/p/n2p5/mgroup/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/p/n2p5/mgroup

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/ownable v0.0.0-latest
gno.land/p/demo/testutils v0.0.0-latest
)
Loading

0 comments on commit 1231f81

Please sign in to comment.