Code Monkey home page Code Monkey logo

Comments (1)

dolmen avatar dolmen commented on May 29, 2024

Like #1486 this use case can be rewritten using slices.ContainsFunc, but this time by using it at 2 depth levels.

See https://go.dev/play/p/Y6d7YuRjRu1

	expectedValues := []fooBar{ // the expected list that contains only fields that we wanna check, can be a struct type generated just for a specific test
		{foo: "Three", bar: 3},
		{foo: "One", bar: 1},
	}

	assert.True(t,
		slices.ContainsFunc(
			[]fooBarBuzz{ // it's suppose to be generated and have lots of fields
				{foo: "One", bar: 1, buzz: time.Now()},
				{foo: "Two", bar: 2, buzz: time.Now().Add(1 * time.Second)},
				{foo: "Three", bar: 3, buzz: time.Now().Add(10 * time.Second)},
				{foo: "Four", bar: 4, buzz: time.Now().Add(1 * time.Minute)},
			},
			func(actual fooBarBuzz) bool {
				return slices.ContainsFunc(expectedValues, func(expected fooBar) bool {
					return actual.foo == expected.foo && actual.bar == expected.bar
				})
			},
		),
		"should contain subset {foo: \"One\", bar: 1} and {foo: \"Three\", bar: 3}",
	)

Like #1486 I think that this is more readable than introducing a new method in Testify. So I'm rejecting this feature request.

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.