Skip to content

Instantly share code, notes, and snippets.

@mikeumus
Last active February 13, 2018 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeumus/a97da2d65bfa4f5b92e13177f6a88922 to your computer and use it in GitHub Desktop.
Save mikeumus/a97da2d65bfa4f5b92e13177f6a88922 to your computer and use it in GitHub Desktop.
An attempt at a helper function for table driven tests in go.
package gopol
import (
// "fmt"
// "io"
// "log"
// "bytes"
// "fmt"
// "log"
// "bufio"
// "os"
// "os/exec"
// "strings"
"testing"
)
type testCasesStruct []struct {
n string
expected bool
}
type valUserInType func(string) bool
var curPairInputTestCases = []struct {
n string
expected bool
}{
{"1/d", false},
{"a/d", false},
{"a", false},
{"", false},
{"_", false},
{"/", false},
{"ETF_#@$", false},
{"ETF_BTC", false},
{"asd/sad", true},
{"123/321", false},
{"3ta/321", false},
{"123/y43", false},
{"abc/abcd", false},
{"abcd/abc", false},
{"123/321", false},
}
func TestGoPolSuite(t *testing.T) {
methodTester(t, validateCurPairInput, curPairInputTestCases)
}
// https://routley.io/tech/2017/11/05/intermediate-go-testing.html
func methodTester(t *testing.T, testingMethod valUserInType, testCases testCasesStruct) {
t.Helper()
for _, tt := range testCases {
actual := testingMethod(tt.n)
if actual != tt.expected {
t.Errorf("\n%v(%v)\n expected: %v\n actual: %v\n", testingMethod, tt.n, tt.expected, actual)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment