update: move structs with test data into tests
This commit is contained in:
parent
dc03addc2c
commit
778301ed3c
42
slug_test.go
42
slug_test.go
@ -11,7 +11,8 @@ import (
|
||||
|
||||
//=============================================================================
|
||||
|
||||
var SlugMakeTests = []struct {
|
||||
func TestSlugMake(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
@ -48,8 +49,7 @@ var SlugMakeTests = []struct {
|
||||
{"影師", "ying-shi"},
|
||||
}
|
||||
|
||||
func TestSlugMake(t *testing.T) {
|
||||
for index, st := range SlugMakeTests {
|
||||
for index, st := range testCases {
|
||||
got := Make(st.in)
|
||||
if got != st.want {
|
||||
t.Errorf(
|
||||
@ -59,7 +59,8 @@ func TestSlugMake(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var SlugMakeLangTests = []struct {
|
||||
func TestSlugMakeLang(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
lang string
|
||||
in string
|
||||
want string
|
||||
@ -71,8 +72,7 @@ var SlugMakeLangTests = []struct {
|
||||
{"test", "This & that", "this-and-that"}, // unknown lang, fallback to "en"
|
||||
}
|
||||
|
||||
func TestSlugMakeLang(t *testing.T) {
|
||||
for index, smlt := range SlugMakeLangTests {
|
||||
for index, smlt := range testCases {
|
||||
got := MakeLang(smlt.in, smlt.lang)
|
||||
if got != smlt.want {
|
||||
t.Errorf(
|
||||
@ -82,7 +82,8 @@ func TestSlugMakeLang(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var SlugMakeUserSubstituteTests = []struct {
|
||||
func TestSlugMakeUserSubstituteLang(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
cSub map[string]string
|
||||
lang string
|
||||
in string
|
||||
@ -93,8 +94,7 @@ var SlugMakeUserSubstituteTests = []struct {
|
||||
{map[string]string{"&": "or"}, "de", "This & that", "this-or-that"}, // by default "&" => "und"
|
||||
}
|
||||
|
||||
func TestSlugMakeUserSubstituteLang(t *testing.T) {
|
||||
for index, smust := range SlugMakeUserSubstituteTests {
|
||||
for index, smust := range testCases {
|
||||
CustomSub = smust.cSub
|
||||
got := MakeLang(smust.in, smust.lang)
|
||||
if got != smust.want {
|
||||
@ -107,8 +107,9 @@ func TestSlugMakeUserSubstituteLang(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlugMakeSubstituteOrderLang(t *testing.T) {
|
||||
// Always substitute runes first
|
||||
var SlugMakeSubstituteOrderTests = []struct {
|
||||
var testCases = []struct {
|
||||
rSub map[rune]string
|
||||
sSub map[string]string
|
||||
in string
|
||||
@ -118,8 +119,7 @@ var SlugMakeSubstituteOrderTests = []struct {
|
||||
{map[rune]string{'&': "down"}, map[string]string{"&": "up"}, "&", "down"},
|
||||
}
|
||||
|
||||
func TestSlugMakeSubstituteOrderLang(t *testing.T) {
|
||||
for index, smsot := range SlugMakeSubstituteOrderTests {
|
||||
for index, smsot := range testCases {
|
||||
CustomRuneSub = smsot.rSub
|
||||
CustomSub = smsot.sSub
|
||||
got := Make(smsot.in)
|
||||
@ -133,7 +133,8 @@ func TestSlugMakeSubstituteOrderLang(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var SlugSubstituteTests = []struct {
|
||||
func TestSubstituteLang(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
cSub map[string]string
|
||||
in string
|
||||
want string
|
||||
@ -142,8 +143,7 @@ var SlugSubstituteTests = []struct {
|
||||
{map[string]string{"'": " "}, "That's great", "That s great"},
|
||||
}
|
||||
|
||||
func TestSubstituteLang(t *testing.T) {
|
||||
for index, sst := range SlugSubstituteTests {
|
||||
for index, sst := range testCases {
|
||||
got := Substitute(sst.in, sst.cSub)
|
||||
if got != sst.want {
|
||||
t.Errorf(
|
||||
@ -153,7 +153,8 @@ func TestSubstituteLang(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var SlugSubstituteRuneTests = []struct {
|
||||
func TestSubstituteRuneLang(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
cSub map[rune]string
|
||||
in string
|
||||
want string
|
||||
@ -162,8 +163,7 @@ var SlugSubstituteRuneTests = []struct {
|
||||
{map[rune]string{'\'': " "}, "That's great", "That s great"},
|
||||
}
|
||||
|
||||
func TestSubstituteRuneLang(t *testing.T) {
|
||||
for index, ssrt := range SlugSubstituteRuneTests {
|
||||
for index, ssrt := range testCases {
|
||||
got := SubstituteRune(ssrt.in, ssrt.cSub)
|
||||
if got != ssrt.want {
|
||||
t.Errorf(
|
||||
@ -173,7 +173,8 @@ func TestSubstituteRuneLang(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var SlugMakeSmartTruncateTests = []struct {
|
||||
func TestSlugMakeSmartTruncate(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
in string
|
||||
maxLength int
|
||||
want string
|
||||
@ -186,8 +187,7 @@ var SlugMakeSmartTruncateTests = []struct {
|
||||
{"Dobrosław Żybort", 5, "dobro"},
|
||||
}
|
||||
|
||||
func TestSlugMakeSmartTruncate(t *testing.T) {
|
||||
for index, smstt := range SlugMakeSmartTruncateTests {
|
||||
for index, smstt := range testCases {
|
||||
MaxLength = smstt.maxLength
|
||||
got := Make(smstt.in)
|
||||
if got != smstt.want {
|
||||
|
Loading…
Reference in New Issue
Block a user