1package gnopm23import (4 "testing"56 "gno.land/p/nt/uassert/v0"7)89func TestValidPkgPath(t *testing.T) {10 cases := []struct {11 name string12 in string13 want bool14 }{15 {"versioned package", "gno.land/p/moul/md/v1", true},16 {"versioned realm", "gno.land/r/moul/gnopm/registry/v0", true},17 {"unversioned realm", "gno.land/r/sys/users", true},18 {"address namespace", "gno.land/r/" + addrNS + "/scratch/v0", true},1920 {"empty", "", false},21 {"too few elements", "gno.land/p/moul", false},22 {"domain without a dot", "gnoland/p/moul/md/v1", false},23 {"unknown kind", "gno.land/x/moul/md/v1", false},24 {"leading slash", "/gno.land/p/moul/md/v1", false},25 {"trailing slash", "gno.land/p/moul/md/v1/", false},26 {"double slash", "gno.land/p//moul/md", false},27 {"parent traversal", "gno.land/p/moul/../md", false},28 {"space", "gno.land/p/moul/m d", false},29 }30 for _, tc := range cases {31 uassert.Equal(t, tc.want, ValidPkgPath(tc.in), tc.name)32 }33}3435func TestSplitPkgPath(t *testing.T) {36 domain, kind, ns, rest, ok := SplitPkgPath("gno.land/r/moul/gnopm/registry/v0")37 uassert.True(t, ok, "splits")38 uassert.Equal(t, "gno.land", domain)39 uassert.Equal(t, "r", kind)40 uassert.Equal(t, "moul", ns)41 uassert.Equal(t, "gnopm/registry/v0", rest)4243 _, _, _, _, ok = SplitPkgPath("nonsense")44 uassert.False(t, ok, "rejects a non-path")4546 uassert.Equal(t, "moul", Namespace("gno.land/p/moul/md/v1"))47 uassert.Equal(t, "", Namespace("nonsense"))48}4950func TestVersion(t *testing.T) {51 cases := []struct {52 in, want string53 }{54 {"gno.land/p/moul/md/v1", "v1"},55 {"gno.land/p/moul/md/v0", "v0"},56 {"gno.land/p/moul/md/v10", "v10"},57 {"gno.land/r/sys/users", ""}, // unversioned is legal58 {"gno.land/r/moul/home", ""}, // the one path that can never carry one59 {"gno.land/p/moul/md/vx", ""}, // not a number60 {"gno.land/p/moul/md/v", ""}, // no digits61 {"short", ""},62 }63 for _, tc := range cases {64 uassert.Equal(t, tc.want, Version(tc.in), tc.in)65 }66}6768func TestAddressNamespace(t *testing.T) {69 uassert.True(t, AddressNamespace(addrNS), "a real address")70 uassert.False(t, AddressNamespace("moul"), "a name")71 uassert.False(t, AddressNamespace(""), "empty")72 // b, i, o and 1 are exactly the characters bech32 drops.73 uassert.False(t, AddressNamespace("g1bbbfred47kzduec920z88wfr64ylksmdcedlf5"), "wrong length")74}75Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.