Skip to content

Commit

Permalink
style(logic): fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Apr 13, 2023
1 parent 5f9c8a1 commit dad6f70
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion x/logic/fs/filtered_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions x/logic/util/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/logic/util/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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
}
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() {
Expand Down
12 changes: 6 additions & 6 deletions x/logic/util/pointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ 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

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)
})
})

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)
})
})
})
}

func TestNonZeroOrDefault(t *testing.T) {
Convey("Given a values", t, func() {
Convey("Given a value", t, func() {
cases := []struct {
v any
defaultValue any
Expand All @@ -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)
})
})
Expand Down
14 changes: 7 additions & 7 deletions x/logic/util/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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)
Expand Down

0 comments on commit dad6f70

Please sign in to comment.