Skip to content

tada-team/swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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