https://github.com/tada-team/swap
Shortcuts for swapping variable values
https://github.com/tada-team/swap
go golang testing
Last synced: about 1 year ago
JSON representation
Shortcuts for swapping variable values
- Host: GitHub
- URL: https://github.com/tada-team/swap
- Owner: tada-team
- License: unlicense
- Created: 2020-11-22T02:23:33.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-02-20T16:06:22.000Z (over 4 years ago)
- Last Synced: 2025-03-24T22:42:01.165Z (over 1 year ago)
- Topics: go, golang, testing
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swap variables
```go
// myconfig.go
var myConfig struct {
Foo string
Bar int
}
func init() {
readConfig(&myConfig)
}
```
```go
// 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...
}
```