Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 510 Bytes

README.md

File metadata and controls

33 lines (28 loc) · 510 Bytes

swap variables

// myconfig.go
var myConfig struct {
	Foo string
	Bar int
}

func init() {
	readConfig(&myConfig)
}
// test.go
import "github.com/tada-team/swap"

func TestWithSwap(t *testing.T) {
	defer swap.Value(&myConfig.Foo, "test value")()
	defer swap.Value(&myConfig.Bar, 42)()
	// ...test cases...
}

// more sugar
func TestWithSwapChain(t *testing.T) {
	defer swap.Chain(
		swap.Value(&myConfig.Foo, "test value"),
		swap.Value(&myConfig.Bar, 42),
	)()  
	// ...test cases...
}