Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics #8

Merged
merged 9 commits into from
Apr 1, 2023
Merged

Generics #8

merged 9 commits into from
Apr 1, 2023

Conversation

corbym
Copy link
Owner

@corbym corbym commented Apr 1, 2023

v.1.1.0 - generics

Changes all the matchers to use generics instead of reflection. Some still use a bit of reflection, e.g. TypeName etc.

Other major changes:

  • ValueContaining has been split into StringContaining, MapContaining, MapContainingValues, MapMatchingValues, ArrayContaining and ArrayMatching.
  • No longer panics with unknown types, as types will fail at compile time.

Some idiosyncrasies with the generic types do exist, but this is language specific;

  • map matchers generally need to know the type of the map key values explicitly or the compiler will complain, e.g.
    then.AssertThat(testing, map[string]bool{"hi": true, "bye": true}, has.AllKeys[string, bool]("hi", "bye"))
  • has.Length() is likewise pernickety about types being explicit, mainly because it works on both strings and arrays. It needs to know both the type of the array and the array/string type. Confused? me too.
  • is.LessThan and is.GreaterThan no longer work on complex types. This is because the complex types do not support the comparison operators (yet, somehow, they could be compared by reflection 🤷 )

See the matcher_test.go file for full usage.

@corbym corbym added this to the v1.1.0 milestone Apr 1, 2023
@coveralls
Copy link

coveralls commented Apr 1, 2023

Coverage Status

Coverage: 100.0%. Remained the same when pulling 4ea9cb6 on generics into 38dfeaf on master.

@corbym corbym merged commit c340bb4 into master Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants