From f98e509e6e833c33cac01b2216c52137b301df5c Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 10 Apr 2024 01:31:19 +0530 Subject: [PATCH] Test rePkgOrRlmPath --- tm2/pkg/std/memfile_test.go | 142 ++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/tm2/pkg/std/memfile_test.go b/tm2/pkg/std/memfile_test.go index 44031cd1b8b..4e441bef0e7 100644 --- a/tm2/pkg/std/memfile_test.go +++ b/tm2/pkg/std/memfile_test.go @@ -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)) + }) + } +}