From b899fe041c48db3c3b36f5c799a0aea768ef83c4 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:33:32 +0200 Subject: [PATCH] chore: fix some typos and style --- README.md | 26 +++++++++++++------------- internal/assertions/assertions.go | 8 ++++---- must/must.go | 6 +++--- must/must_test.go | 2 +- skip/skip.go | 2 +- test.go | 6 +++--- test_test.go | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 6caf0f4..3ba4676 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ There are five key packages, :ballot_box_with_check: v0.6.0 adds support for custom `cmp.Option` values - - Adds ability to customize cmp.Equal behavior via cmp.Option arguments + - Adds ability to customize `cmp.Equal` behavior via `cmp.Option` arguments - Adds assertions for existence of single map key - Fixes some error outputs @@ -66,9 +66,9 @@ way - avoiding erroneous comparisons in the first place. Generally there are 4 ways of asserting equivalence between types. -#### the == operator +#### the `==` operator -Functions like `EqOp` and `ContainsOp` work on types that are `comparable`, i.e. are +Functions like `EqOp` and `ContainsOp` work on types that are `comparable`, i.e., are compatible with Go's built-in `==` and `!=` operators. #### a comparator function @@ -76,18 +76,18 @@ compatible with Go's built-in `==` and `!=` operators. Functions like `EqFunc` and `ContainsFunc` work on any type, as the caller passes in a function that takes two arguments of that type, returning a boolean indicating equivalence. -#### an .Equal method +#### an `.Equal` method Functions like `Equal` and `ContainsEqual` work on types implementing the `EqualFunc` generic interface (i.e. implement an `.Equal` method). The `.Equal` method is called to determine equivalence. -#### the cmp.Equal or reflect.DeepEqual functions +#### the `cmp.Equal` or `reflect.DeepEqual` functions Functions like `Eq` and `Contains` work on any type, using the `cmp.Equal` or `reflect.DeepEqual` functions to determine equivalence. Although this is the easiest / most compatible way -to "just compare stuff", it the least deterministic way of comparing instances of a type. -Changes to the underlying types may cause unexpected changes in their equivalence (e.g. +to "just compare stuff", it's the least deterministic way of comparing instances of a type. +Changes to the underlying types may cause unexpected changes in their equivalence (e.g., the addition of unexported fields, function field types, etc.). Assertions that make use of `cmp.Equal` configured with custom `cmp.Option` values. @@ -98,16 +98,16 @@ is done via the `cmp.Diff` function. For incompatible types, their `GoString` va printed instead. All output is directed through `t.Log` functions, and is visible only if test verbosity is -turned on (e.g. `go test -v`). +turned on (e.g., `go test -v`). #### fail fast vs. fail later The `test` and `must` packages are identical, except for how test cases behave when encountering a failure. Sometimes it is helpful for a test case to continue running even though a failure has -occurred (e.g. contains cleanup logic not captured via a `t.Cleanup` function). Other times it -make sense to fail immediately and stop the test case execution. +occurred (e.g., it contains cleanup logic not captured via a `t.Cleanup` function). Other times, it +makes sense to fail immediately and stop the test case execution. -### go-cmp Options +### `go-cmp` Options The test assertions that rely on `cmp.Equal` can be customized in how objects are compared by [specifying custom](https://github.com/google/go-cmp/blob/master/cmp/options.go#L16) @@ -243,7 +243,7 @@ err := c.Run() ```go import "github.com/shoenig/test/must" -// ... +// ... e1 := Employee{ID: 100, Name: "Alice"} e2 := Employee{ID: 101, Name: "Bob"} @@ -265,7 +265,7 @@ must.Equal(t, e1, e2) ### Output -The `test` and `must` package attempt to create useful, readable output when an assertions goes awry. Some random examples below. +The `test` and `must` package attempt to create useful, readable output when an assertion goes awry. Some random examples below. ```text test_test.go:779: expected different file permissions diff --git a/internal/assertions/assertions.go b/internal/assertions/assertions.go index 60f01e6..a959434 100644 --- a/internal/assertions/assertions.go +++ b/internal/assertions/assertions.go @@ -233,19 +233,19 @@ func EqJSON(exp, val string) (s string) { var expA, expB any if err := json.Unmarshal([]byte(exp), &expA); err != nil { - s = fmt.Sprintf("failed to unmarshal first argument as json: %v\n", err) + s = fmt.Sprintf("failed to unmarshal first argument as JSON: %v\n", err) return } if err := json.Unmarshal([]byte(val), &expB); err != nil { - s = fmt.Sprintf("failed to unmarshal second argument as json: %v\n", err) + s = fmt.Sprintf("failed to unmarshal second argument as JSON: %v\n", err) return } if !reflect.DeepEqual(expA, expB) { jsonA, _ := json.Marshal(expA) jsonB, _ := json.Marshal(expB) - s = "expected equality via json marshalling\n" + s = "expected equality via JSON marshalling\n" s += diff(string(jsonA), string(jsonB), nil) return } @@ -263,7 +263,7 @@ func ValidJSONBytes(input []byte) (s string) { func validJSON(input []byte) (s string) { if !json.Valid([]byte(input)) { - return "expected input to be valid json\n" + return "expected input to be valid JSON\n" } return } diff --git a/must/must.go b/must/must.go index 4232d46..619ba81 100644 --- a/must/must.go +++ b/must/must.go @@ -21,7 +21,7 @@ import ( "github.com/shoenig/test/wait" ) -// ErrorAssertionFunc allows to pass Error and NoError in table driven tests +// ErrorAssertionFunc allows passing Error and NoError in table driven tests type ErrorAssertionFunc func(t T, err error, settings ...Setting) // Nil asserts a is nil. @@ -226,7 +226,7 @@ func SliceNotContains[A any](t T, slice []A, item A, settings ...Setting) { invoke(t, assertions.SliceNotContains(slice, item), settings...) } -// SliceNotContainsFunc asserts item does not exist inslice, using eq to compare +// SliceNotContainsFunc asserts item does not exist in slice, using eq to compare // elements. func SliceNotContainsFunc[A, B any](t T, slice []A, item B, eq func(a A, b B) bool, settings ...Setting) { t.Helper() @@ -417,7 +417,7 @@ func MapEqFunc[M1, M2 interfaces.Map[K, V], K comparable, V any](t T, exp M1, va } // MapEqual asserts maps exp and val contain the same key/val pairs, using Equal -// method to compare vals +// method to compare val func MapEqual[M interfaces.MapEqualFunc[K, V], K comparable, V interfaces.EqualFunc[V]](t T, exp, val M, settings ...Setting) { t.Helper() invoke(t, assertions.MapEqual(exp, val), settings...) diff --git a/must/must_test.go b/must/must_test.go index 399bd79..b589927 100644 --- a/must/must_test.go +++ b/must/must_test.go @@ -336,7 +336,7 @@ func TestNotEqFunc_PS(t *testing.T) { } func TestEqJSON(t *testing.T) { - tc := newCase(t, `expected equality via json marshalling`) + tc := newCase(t, `expected equality via JSON marshalling`) t.Cleanup(tc.assert) EqJSON(tc, `{"a":1, "b":2}`, `{"b":2, "a":9}`) diff --git a/skip/skip.go b/skip/skip.go index 071f082..1fee66a 100644 --- a/skip/skip.go +++ b/skip/skip.go @@ -127,7 +127,7 @@ func MinimumCores(t T, num int) { } // MaximumCores will skip the test if the number of cores on the system -// exceeeds the given maximum. +// exceeds the given maximum. func MaximumCores(t T, num int) { cpus := runtime.NumCPU() if cpus > num { diff --git a/test.go b/test.go index 936eb4f..73ef6ae 100644 --- a/test.go +++ b/test.go @@ -19,7 +19,7 @@ import ( "github.com/shoenig/test/wait" ) -// ErrorAssertionFunc allows to pass Error and NoError in table driven tests +// ErrorAssertionFunc allows passing Error and NoError in table driven tests type ErrorAssertionFunc func(t T, err error, settings ...Setting) // Nil asserts a is nil. @@ -224,7 +224,7 @@ func SliceNotContains[A any](t T, slice []A, item A, settings ...Setting) { invoke(t, assertions.SliceNotContains(slice, item), settings...) } -// SliceNotContainsFunc asserts item does not exist inslice, using eq to compare +// SliceNotContainsFunc asserts item does not exist in slice, using eq to compare // elements. func SliceNotContainsFunc[A, B any](t T, slice []A, item B, eq func(a A, b B) bool, settings ...Setting) { t.Helper() @@ -415,7 +415,7 @@ func MapEqFunc[M1, M2 interfaces.Map[K, V], K comparable, V any](t T, exp M1, va } // MapEqual asserts maps exp and val contain the same key/val pairs, using Equal -// method to compare vals +// method to compare val func MapEqual[M interfaces.MapEqualFunc[K, V], K comparable, V interfaces.EqualFunc[V]](t T, exp, val M, settings ...Setting) { t.Helper() invoke(t, assertions.MapEqual(exp, val), settings...) diff --git a/test_test.go b/test_test.go index cf448db..6f84294 100644 --- a/test_test.go +++ b/test_test.go @@ -334,7 +334,7 @@ func TestNotEqFunc_PS(t *testing.T) { } func TestEqJSON(t *testing.T) { - tc := newCase(t, `expected equality via json marshalling`) + tc := newCase(t, `expected equality via JSON marshalling`) t.Cleanup(tc.assert) EqJSON(tc, `{"a":1, "b":2}`, `{"b":2, "a":9}`)