diff --git a/x/logic/fs/filtered_fs.go b/x/logic/fs/filtered_fs.go index 1aac4e65..40b30ad3 100644 --- a/x/logic/fs/filtered_fs.go +++ b/x/logic/fs/filtered_fs.go @@ -37,7 +37,7 @@ func (f *FilteredFS) Open(name string) (fs.File, error) { return nil, err } - if !util.WhitelistBlacklistMatches(f.whitelist, f.blacklist, util.UrlMatches)(urlFile) { + if !util.WhitelistBlacklistMatches(f.whitelist, f.blacklist, util.URLMatches)(urlFile) { return nil, &fs.PathError{ Op: "open", Path: name, diff --git a/x/logic/keeper/interpreter.go b/x/logic/keeper/interpreter.go index 02e718da..fc8a1c81 100644 --- a/x/logic/keeper/interpreter.go +++ b/x/logic/keeper/interpreter.go @@ -134,10 +134,10 @@ func (k Keeper) newInterpreter(ctx goctx.Context) (*prolog.Interpreter, *util.Bo whitelistUrls := lo.Map( util.NonZeroOrDefault(interpreterParams.VirtualFilesFilter.Whitelist, []string{}), - util.Indexed(util.ParseUrlMust)) + util.Indexed(util.ParseURLMust)) blacklistUrls := lo.Map( util.NonZeroOrDefault(interpreterParams.VirtualFilesFilter.Whitelist, []string{}), - util.Indexed(util.ParseUrlMust)) + util.Indexed(util.ParseURLMust)) options := []interpreter.Option{ interpreter.WithPredicates(ctx, predicates, gasMeter), diff --git a/x/logic/util/func_test.go b/x/logic/util/func_test.go index 4326b384..21f2b293 100644 --- a/x/logic/util/func_test.go +++ b/x/logic/util/func_test.go @@ -12,13 +12,12 @@ var ( predicateMatches = PredicateMatches urlMatches = func(this string) func(string) bool { return func(that string) bool { - return UrlMatches(ParseUrlMust(this))(ParseUrlMust(that)) + return URLMatches(ParseURLMust(this))(ParseURLMust(that)) } } ) func TestWhitelistBlacklistMatches(t *testing.T) { - Convey("Given a test cases", t, func() { cases := []struct { values []string diff --git a/x/logic/util/pointer.go b/x/logic/util/pointer.go index f43bcbbb..f5e52682 100644 --- a/x/logic/util/pointer.go +++ b/x/logic/util/pointer.go @@ -2,7 +2,7 @@ package util import "reflect" -// DerefOrDefault returns the values of the pointer if it is not nil, otherwise returns the default values. +// DerefOrDefault returns the value of the pointer if it is not nil, otherwise returns the default value. func DerefOrDefault[T any](ptr *T, defaultValue T) T { if ptr != nil { return *ptr @@ -10,7 +10,7 @@ func DerefOrDefault[T any](ptr *T, defaultValue T) T { return defaultValue } -// NonZeroOrDefault returns the values of the argument if it is not nil and not zero, otherwise returns the default values. +// NonZeroOrDefault returns the value of the argument if it is not nil and not zero, otherwise returns the default value. func NonZeroOrDefault[T any](v, defaultValue T) T { v1 := reflect.ValueOf(v) if v1.IsValid() && !v1.IsZero() { diff --git a/x/logic/util/pointer_test.go b/x/logic/util/pointer_test.go index 09278e47..8ffb79ba 100644 --- a/x/logic/util/pointer_test.go +++ b/x/logic/util/pointer_test.go @@ -8,7 +8,7 @@ import ( ) func TestDerefOrDefault(t *testing.T) { - Convey("Given a pointer to an int and a default int values", t, func() { + Convey("Given a pointer to an int and a default int value", t, func() { x := 5 ptr := &x defaultValue := 10 @@ -16,7 +16,7 @@ func TestDerefOrDefault(t *testing.T) { Convey("When the pointer is not nil", func() { result := DerefOrDefault(ptr, defaultValue) - Convey("The result should be the values pointed to by the pointer", func() { + Convey("The result should be the value pointed to by the pointer", func() { So(result, ShouldEqual, x) }) }) @@ -24,7 +24,7 @@ func TestDerefOrDefault(t *testing.T) { Convey("When the pointer is nil", func() { result := DerefOrDefault(nil, defaultValue) - Convey("The result should be the default values", func() { + Convey("The result should be the default value", func() { So(result, ShouldEqual, defaultValue) }) }) @@ -32,7 +32,7 @@ func TestDerefOrDefault(t *testing.T) { } func TestNonZeroOrDefault(t *testing.T) { - Convey("Given a values", t, func() { + Convey("Given a value", t, func() { cases := []struct { v any defaultValue any @@ -45,8 +45,8 @@ func TestNonZeroOrDefault(t *testing.T) { {"hello", "default", "hello"}, } for _, tc := range cases { - Convey(fmt.Sprintf("When the values is %v", tc.v), func() { - Convey(fmt.Sprintf("Then the default values %v is returned", tc.defaultValue), func() { + Convey(fmt.Sprintf("When the value is %v", tc.v), func() { + Convey(fmt.Sprintf("Then the default value %v is returned", tc.defaultValue), func() { So(NonZeroOrDefault(tc.v, tc.defaultValue), ShouldEqual, tc.expected) }) }) diff --git a/x/logic/util/url.go b/x/logic/util/url.go index 56100e2c..57c297b0 100644 --- a/x/logic/util/url.go +++ b/x/logic/util/url.go @@ -4,17 +4,17 @@ import ( "net/url" ) -// UrlMatches is a function that returns a function that matches the given url against the given other item. +// URLMatches is a function that returns a function that matches the given url against the given other item. // // The function matches the components of the given url against the components of the given other url. If the component // of the given other url is empty, it is considered to match the component of the given url. // For example: -// - matchUrl("http://example.com/foo")("http://example.com/foo") -> true -// - matchUrl("http://example.com/foo")("http://example.com/foo?bar=baz") -> false -// - matchUrl("tel:123456789")("tel:") -> true +// - URLMatches("http://example.com/foo")("http://example.com/foo") -> true +// - URLMatches("http://example.com/foo")("http://example.com/foo?bar=baz") -> false +// - URLMatches("tel:123456789")("tel:") -> true // // The function is curried, and is a binary relation that is reflexive, associative (but not commutative). -func UrlMatches(this *url.URL) func(*url.URL) bool { +func URLMatches(this *url.URL) func(*url.URL) bool { return func(that *url.URL) bool { return (that.Scheme == "" || that.Scheme == this.Scheme) && (that.Opaque == "" || that.Opaque == this.Opaque) && @@ -26,9 +26,9 @@ func UrlMatches(this *url.URL) func(*url.URL) bool { } } -// ParseUrlMust parses the given url and panics if it fails. +// ParseURLMust parses the given url and panics if it fails. // You have been warned. -func ParseUrlMust(s string) *url.URL { +func ParseURLMust(s string) *url.URL { u, err := url.Parse(s) if err != nil { panic(err)