PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/onbloc/json/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
onbloc / json
Files
24 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/onbloc/json/v0
gno
0.9

Files (24)

  • README.mdmarkdown
  • gnomod.tomltoml
  • buffer.gnogno
  • builder.gnogno
  • decode.gnogno
  • encode.gnogno
  • errors.gnogno
  • escape.gnogno
  • indent.gnogno
  • internal.gnogno
  • node.gnogno
  • parser.gnogno
  • path.gnogno
  • token.gnogno
  • buffer_test.gnogno
  • builder_test.gnogno
  • decode_test.gnogno
  • encode_test.gnogno
  • escape_test.gnogno
  • indent_test.gnogno
  • node_test.gnogno
  • parser_test.gnogno
  • path_test.gnogno
  • LICENSEother
  • path_test.gnogno
    1package json23import "testing"45func TestParseJSONPath(t *testing.T) {6	tests := []struct {7		name     string8

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    path string
    9 expected []string
    10 }{
    11 {name: "Empty string path", path: "", expected: []string{}},
    12 {name: "Root only path", path: "$", expected: []string{"$"}},
    13 {name: "Root with dot path", path: "$.", expected: []string{"$"}},
    14 {name: "All objects in path", path: "$..", expected: []string{"$", ".."}},
    15 {name: "Only children in path", path: "$.*", expected: []string{"$", "*"}},
    16 {name: "All objects' children in path", path: "$..*", expected: []string{"$", "..", "*"}},
    17 {name: "Simple dot notation path", path: "$.root.element", expected: []string{"$", "root", "element"}},
    18 {name: "Complex dot notation path with wildcard", path: "$.root.*.element", expected: []string{"$", "root", "*", "element"}},
    19 {name: "Path with array wildcard", path: "$.phoneNumbers[*].type", expected: []string{"$", "phoneNumbers", "*", "type"}},
    20 {name: "Path with filter expression", path: "$.store.book[?(@.price < 10)].title", expected: []string{"$", "store", "book", "?(@.price < 10)", "title"}},
    21 {name: "Path with formula", path: "$..phoneNumbers..('ty' + 'pe')", expected: []string{"$", "..", "phoneNumbers", "..", "('ty' + 'pe')"}},
    22 {name: "Simple bracket notation path", path: "$['root']['element']", expected: []string{"$", "'root'", "'element'"}},
    23 {name: "Complex bracket notation path with wildcard", path: "$['root'][*]['element']", expected: []string{"$", "'root'", "*", "'element'"}},
    24 {name: "Bracket notation path with integer index", path: "$['store']['book'][0]['title']", expected: []string{"$", "'store'", "'book'", "0", "'title'"}},
    25 {name: "Complex path with wildcard in bracket notation", path: "$['root'].*['element']", expected: []string{"$", "'root'", "*", "'element'"}},
    26 {name: "Mixed notation path with dot after bracket", path: "$.['root'].*.['element']", expected: []string{"$", "'root'", "*", "'element'"}},
    27 {name: "Mixed notation path with dot before bracket", path: "$['root'].*.['element']", expected: []string{"$", "'root'", "*", "'element'"}},
    28 {name: "Single character path with root", path: "$.a", expected: []string{"$", "a"}},
    29 {name: "Multiple characters path with root", path: "$.abc", expected: []string{"$", "abc"}},
    30 {name: "Multiple segments path with root", path: "$.a.b.c", expected: []string{"$", "a", "b", "c"}},
    31 {name: "Multiple segments path with wildcard and root", path: "$.a.*.c", expected: []string{"$", "a", "*", "c"}},
    32 {name: "Multiple segments path with filter and root", path: "$.a[?(@.b == 'c')].d", expected: []string{"$", "a", "?(@.b == 'c')", "d"}},
    33 {name: "Complex path with multiple filters", path: "$.a[?(@.b == 'c')].d[?(@.e == 'f')].g", expected: []string{"$", "a", "?(@.b == 'c')", "d", "?(@.e == 'f')", "g"}},
    34 {name: "Complex path with multiple filters and wildcards", path: "$.a[?(@.b == 'c')].*.d[?(@.e == 'f')].g", expected: []string{"$", "a", "?(@.b == 'c')", "*", "d", "?(@.e == 'f')", "g"}},
    35 {name: "Path with array index and root", path: "$.a[0].b", expected: []string{"$", "a", "0", "b"}},
    36 {name: "Path with multiple array indices and root", path: "$.a[0].b[1].c", expected: []string{"$", "a", "0", "b", "1", "c"}},
    37 {name: "Path with array index, wildcard and root", path: "$.a[0].*.c", expected: []string{"$", "a", "0", "*", "c"}},
    38 }
    39
    40 for _, tt := range tests {
    41 t.Run(tt.name, func(t *testing.T) {
    42 reult, _ := ParsePath(tt.path)
    43 if !isEqualSlice(reult, tt.expected) {
    44 t.Errorf("ParsePath(%s) expected: %v, got: %v", tt.path, tt.expected, reult)
    45 }
    46 })
    47 }
    48}
    49
    50func isEqualSlice(a, b []string) bool {
    51 if len(a) != len(b) {
    52 return false
    53 }
    54
    55 for i, v := range a {
    56 if v != b[i] {
    57 return false
    58 }
    59 }
    60
    61 return true
    62}
    63