Skip to content

Commit

Permalink
Test rePkgOrRlmPath
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Apr 9, 2024
1 parent 7286ca7 commit f98e509
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions tm2/pkg/std/memfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,145 @@ func TestMemPackage_Validate(t *testing.T) {
})
}
}

func TestRePkgOrRlmPath(t *testing.T) {
for _, tc := range []struct {
desc, in string
expected bool
}{
{
desc: "Valid p",
in: "gno.land/p/path/path",
expected: true,
},
{
desc: "Valid r",
in: "gno.land/r/path/path",
expected: true,
},
{
desc: "Leading Underscore",
in: "gno.land/r/path/_path",
expected: true,
},
{
desc: "Trailing Underscore",
in: "gno.land/r/path/path_",
expected: true,
},
{
desc: "Underscore in Between",
in: "gno.land/r/path/p_ath",
expected: true,
},
{
desc: "Invalid With Underscore 1",
in: "gno.land/r/path/_",
expected: false, // fails
},
{
desc: "Invalid With Underscore 2",
in: "gno.land/r/path/_/_",
expected: false, // fails
},
{
desc: "Invalid With Underscore 3",
in: "gno.land/r/path/__/path",
expected: false, // fails
},
{
desc: "Invalid With Hyphen",
in: "gno.land/r/path/pa-th",
expected: false, // fails
},
{
desc: "Invalid x",
in: "gno.land/x/path/path",
expected: false,
},
{
desc: "Missing Path 1",
in: "gno.land/p",
expected: false,
},
{
desc: "Missing Path 2",
in: "gno.land/p/",
expected: false,
},
{
desc: "Invalid domain",
in: "github.com/p/path/path",
expected: false,
},
{
desc: "Special Character 1",
in: "gno.land/p/p@th/abc/def",
expected: false, // fails
},
{
desc: "Special Character 2",
in: "gno.land/p/p&th/abc/def",
expected: false, // fails
},
{
desc: "Special Character 3",
in: "gno.land/p/p&%$#h/abc/def",
expected: false, // fails
},
{
desc: "Leading Number",
in: "gno.land/p/1Path/abc/def",
expected: false,
},
{
desc: "Uppercase Letters",
in: "gno.land/p/PaTh/abc/def",
expected: false,
},
{
desc: "Empty Path Part",
in: "gno.land/p/path//def",
expected: false, // fails
},
{
desc: "Trailing Slash",
in: "gno.land/p/path/abc/def/",
expected: false, // fails
},
{
desc: "Extra Slash(s)",
in: "gno.land/p/path///abc/def",
expected: false, // fails
},
{
desc: "Valid Long path",
in: "gno.land/r/very/very/very/long/path",
expected: true,
},
{
desc: "Long Path With Special Character 1",
in: "gno.land/r/very/very/very/long/p@th",
expected: false, // fails
},
{
desc: "Long Path With Special Character 2",
in: "gno.land/r/very/very/v%ry/long/path",
expected: false, // fails
},
{
desc: "Long Path With Trailing Slash",
in: "gno.land/r/very/very/very/long/path/",
expected: false, // fails
},
{
desc: "Long Path With Empty Path Part",
in: "gno.land/r/very/very/very//long/path/",
expected: false, // fails
},
} {
t.Run(tc.desc, func(t *testing.T) {
assert.Equal(t, tc.expected, rePkgOrRlmPath.MatchString(tc.in))
})
}
}

0 comments on commit f98e509

Please sign in to comment.