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