package hugolib import ( "strings" "testing" ) func pageFromString(in, filename string) (*Page, error) { return NewPageFrom(strings.NewReader(in), filename) } func CheckShortCodeMatch(t *testing.T, input, expected string, template Template) { p, _ := pageFromString(SIMPLE_PAGE, "simple.md") output := ShortcodesHandle(input, p, template) if output != expected { t.Fatalf("Shortcode render didn't match. Expected: %q, Got: %q", expected, output) } } func TestNonSC(t *testing.T) { tem := NewTemplate() CheckShortCodeMatch(t, "{{% movie 47238zzb %}}", "{{% movie 47238zzb %}}", tem) } func TestPositionalParamSC(t *testing.T) { tem := NewTemplate() tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`) CheckShortCodeMatch(t, "{{% video 47238zzb %}}", "Playing Video 47238zzb", tem) CheckShortCodeMatch(t, "{{% video 47238zzb 132 %}}", "Playing Video 47238zzb", tem) CheckShortCodeMatch(t, "{{%video 47238zzb%}}", "Playing Video 47238zzb", tem) CheckShortCodeMatch(t, "{{%video 47238zzb %}}", "Playing Video 47238zzb", tem) CheckShortCodeMatch(t, "{{% video 47238zzb %}}", "Playing Video 47238zzb", tem) } func TestNamedParamSC(t *testing.T) { tem := NewTemplate() tem.AddInternalShortcode("img.html", ``) CheckShortCodeMatch(t, `{{% img src="one" %}}`, ``, tem) CheckShortCodeMatch(t, `{{% img class="aspen" %}}`, ``, tem) CheckShortCodeMatch(t, `{{% img src= "one" %}}`, ``, tem) CheckShortCodeMatch(t, `{{% img src ="one" %}}`, ``, tem) CheckShortCodeMatch(t, `{{% img src = "one" %}}`, ``, tem) CheckShortCodeMatch(t, `{{% img src = "one" class = "aspen grove" %}}`, ``, tem) } func TestInnerSC(t *testing.T) { tem := NewTemplate() tem.AddInternalShortcode("inside.html", `
More Here
\nMore Here
\nlink and text
\n