Esempio n. 1
0
func TestMakePathSanitizedDisablePathToLower(t *testing.T) {
	viper.Reset()
	defer viper.Reset()

	initCommonTestConfig()
	viper.Set("disablePathToLower", true)
	p := NewPathSpecFromConfig(viper.GetViper())

	tests := []struct {
		input    string
		expected string
	}{
		{"  FOO bar  ", "FOO-bar"},
		{"Foo.Bar/fOO_bAr-Foo", "Foo.Bar/fOO_bAr-Foo"},
		{"FOO,bar:FooBar", "FOObarFooBar"},
		{"foo/BAR.HTML", "foo/BAR.HTML"},
		{"трям/трям", "трям/трям"},
		{"은행", "은행"},
	}

	for _, test := range tests {
		output := p.MakePathSanitized(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Esempio n. 2
0
func TestMakePath(t *testing.T) {
	viper.Reset()
	defer viper.Reset()
	initCommonTestConfig()

	tests := []struct {
		input         string
		expected      string
		removeAccents bool
	}{
		{"  Foo bar  ", "Foo-bar", true},
		{"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo", true},
		{"fOO,bar:foobAR", "fOObarfoobAR", true},
		{"FOo/BaR.html", "FOo/BaR.html", true},
		{"трям/трям", "трям/трям", true},
		{"은행", "은행", true},
		{"Банковский кассир", "Банковскии-кассир", true},
		// Issue #1488
		{"संस्कृत", "संस्कृत", false},
		{"a%C3%B1ame", "a%C3%B1ame", false},         // Issue #1292
		{"this+is+a+test", "this+is+a+test", false}, // Issue #1290
	}

	for _, test := range tests {
		viper.Set("removePathAccents", test.removeAccents)
		p := NewPathSpecFromConfig(viper.GetViper())
		output := p.MakePath(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Esempio n. 3
0
func loadDefaultSettings() {
	viper.SetDefault("cleanDestinationDir", false)
	viper.SetDefault("watch", false)
	viper.SetDefault("metaDataFormat", "toml")
	viper.SetDefault("disable404", false)
	viper.SetDefault("disableRSS", false)
	viper.SetDefault("disableSitemap", false)
	viper.SetDefault("disableRobotsTXT", false)
	viper.SetDefault("contentDir", "content")
	viper.SetDefault("layoutDir", "layouts")
	viper.SetDefault("staticDir", "static")
	viper.SetDefault("archetypeDir", "archetypes")
	viper.SetDefault("publishDir", "public")
	viper.SetDefault("dataDir", "data")
	viper.SetDefault("i18nDir", "i18n")
	viper.SetDefault("themesDir", "themes")
	viper.SetDefault("defaultLayout", "post")
	viper.SetDefault("buildDrafts", false)
	viper.SetDefault("buildFuture", false)
	viper.SetDefault("buildExpired", false)
	viper.SetDefault("uglyURLs", false)
	viper.SetDefault("verbose", false)
	viper.SetDefault("ignoreCache", false)
	viper.SetDefault("canonifyURLs", false)
	viper.SetDefault("relativeURLs", false)
	viper.SetDefault("removePathAccents", false)
	viper.SetDefault("taxonomies", map[string]string{"tag": "tags", "category": "categories"})
	viper.SetDefault("permalinks", make(PermalinkOverrides, 0))
	viper.SetDefault("sitemap", Sitemap{Priority: -1, Filename: "sitemap.xml"})
	viper.SetDefault("defaultExtension", "html")
	viper.SetDefault("pygmentsStyle", "monokai")
	viper.SetDefault("pygmentsUseClasses", false)
	viper.SetDefault("pygmentsCodeFences", false)
	viper.SetDefault("pygmentsOptions", "")
	viper.SetDefault("disableLiveReload", false)
	viper.SetDefault("pluralizeListTitles", true)
	viper.SetDefault("preserveTaxonomyNames", false)
	viper.SetDefault("forceSyncStatic", false)
	viper.SetDefault("footnoteAnchorPrefix", "")
	viper.SetDefault("footnoteReturnLinkContents", "")
	viper.SetDefault("newContentEditor", "")
	viper.SetDefault("paginate", 10)
	viper.SetDefault("paginatePath", "page")
	viper.SetDefault("blackfriday", helpers.NewBlackfriday(viper.GetViper()))
	viper.SetDefault("rSSUri", "index.xml")
	viper.SetDefault("sectionPagesMenu", "")
	viper.SetDefault("disablePathToLower", false)
	viper.SetDefault("hasCJKLanguage", false)
	viper.SetDefault("enableEmoji", false)
	viper.SetDefault("pygmentsCodeFencesGuessSyntax", false)
	viper.SetDefault("useModTimeAsFallback", false)
	viper.SetDefault("currentContentLanguage", helpers.NewDefaultLanguage())
	viper.SetDefault("defaultContentLanguage", "en")
	viper.SetDefault("defaultContentLanguageInSubdir", false)
	viper.SetDefault("enableMissingTranslationPlaceholders", false)
	viper.SetDefault("enableGitInfo", false)
}
Esempio n. 4
0
func TestGetMarkdownRendererWithTOC(t *testing.T) {
	ctx := &RenderingContext{RenderTOC: true, ConfigProvider: viper.GetViper()}
	ctx.Content = []byte("testContent")
	ctx.Config = ctx.getConfig()
	actualRenderedMarkdown := markdownRender(ctx)
	expectedRenderedMarkdown := []byte("<nav>\n</nav>\n\n<p>testContent</p>\n")
	if !bytes.Equal(actualRenderedMarkdown, expectedRenderedMarkdown) {
		t.Errorf("Actual rendered Markdown (%s) did not match expected markdown (%s)", actualRenderedMarkdown, expectedRenderedMarkdown)
	}
}
Esempio n. 5
0
func doTestRelURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, lang string) {
	viper.Reset()
	viper.Set("multilingual", multilingual)
	viper.Set("currentContentLanguage", NewLanguage(lang))
	viper.Set("defaultContentLanguage", "en")
	viper.Set("defaultContentLanguageInSubdir", defaultInSubDir)

	tests := []struct {
		input    string
		baseURL  string
		canonify bool
		expected string
	}{
		{"/test/foo", "http://base/", false, "MULTI/test/foo"},
		{"/" + lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
		{lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
		{"test.css", "http://base/sub", false, "/subMULTI/test.css"},
		{"test.css", "http://base/sub", true, "MULTI/test.css"},
		{"/test/", "http://base/", false, "MULTI/test/"},
		{"/test/", "http://base/sub/", false, "/subMULTI/test/"},
		{"/test/", "http://base/sub/", true, "MULTI/test/"},
		{"", "http://base/ace/", false, "/aceMULTI/"},
		{"", "http://base/ace", false, "/aceMULTI"},
		{"http://abs", "http://base/", false, "http://abs"},
		{"//schemaless", "http://base/", false, "//schemaless"},
	}

	for i, test := range tests {
		viper.Set("baseURL", test.baseURL)
		viper.Set("canonifyURLs", test.canonify)
		p := NewPathSpecFromConfig(viper.GetViper())

		output := p.RelURL(test.input, addLanguage)

		expected := test.expected
		if multilingual && addLanguage {
			if !defaultInSubDir && lang == "en" {
				expected = strings.Replace(expected, "MULTI", "", 1)
			} else {
				expected = strings.Replace(expected, "MULTI", "/"+lang, 1)
			}
		} else {
			expected = strings.Replace(expected, "MULTI", "", 1)
		}

		if output != expected {
			t.Errorf("[%d][%t] Expected %#v, got %#v\n", i, test.canonify, expected, output)
		}
	}
}
Esempio n. 6
0
func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, lang string) {
	viper.Reset()
	viper.Set("multilingual", multilingual)
	viper.Set("currentContentLanguage", NewLanguage(lang))
	viper.Set("defaultContentLanguage", "en")
	viper.Set("defaultContentLanguageInSubdir", defaultInSubDir)

	tests := []struct {
		input    string
		baseURL  string
		expected string
	}{
		{"/test/foo", "http://base/", "http://base/MULTItest/foo"},
		{"/" + lang + "/test/foo", "http://base/", "http://base/" + lang + "/test/foo"},
		{"", "http://base/ace/", "http://base/ace/MULTI"},
		{"/test/2/foo/", "http://base", "http://base/MULTItest/2/foo/"},
		{"http://abs", "http://base/", "http://abs"},
		{"schema://abs", "http://base/", "schema://abs"},
		{"//schemaless", "http://base/", "//schemaless"},
		{"test/2/foo/", "http://base/path", "http://base/path/MULTItest/2/foo/"},
		{lang + "/test/2/foo/", "http://base/path", "http://base/path/" + lang + "/test/2/foo/"},
		{"/test/2/foo/", "http://base/path", "http://base/MULTItest/2/foo/"},
		{"http//foo", "http://base/path", "http://base/path/MULTIhttp/foo"},
	}

	for _, test := range tests {
		viper.Set("baseURL", test.baseURL)
		p := NewPathSpecFromConfig(viper.GetViper())
		output := p.AbsURL(test.input, addLanguage)
		expected := test.expected
		if multilingual && addLanguage {
			if !defaultInSubDir && lang == "en" {
				expected = strings.Replace(expected, "MULTI", "", 1)
			} else {
				expected = strings.Replace(expected, "MULTI", lang+"/", 1)
			}

		} else {
			expected = strings.Replace(expected, "MULTI", "", 1)
		}
		if output != expected {
			t.Fatalf("Expected %#v, got %#v\n", expected, output)
		}
	}
}
func TestBlackfridayTaskList(t *testing.T) {
	for i, this := range []struct {
		markdown        string
		taskListEnabled bool
		expect          string
	}{
		{`
TODO:

- [x] On1
- [X] On2
- [ ] Off

END
`, true, `<p>TODO:</p>

<ul class="task-list">
<li><input type="checkbox" checked disabled class="task-list-item"> On1</li>
<li><input type="checkbox" checked disabled class="task-list-item"> On2</li>
<li><input type="checkbox" disabled class="task-list-item"> Off</li>
</ul>

<p>END</p>
`},
		{`- [x] On1`, false, `<ul>
<li>[x] On1</li>
</ul>
`},
	} {
		blackFridayConfig := NewBlackfriday(viper.GetViper())
		blackFridayConfig.TaskLists = this.taskListEnabled
		ctx := &RenderingContext{Content: []byte(this.markdown), PageFmt: "markdown", Config: blackFridayConfig}

		result := string(RenderBytes(ctx))

		if result != this.expect {
			t.Errorf("[%d] got \n%v but expected \n%v", i, result, this.expect)
		}
	}
}
Esempio n. 8
0
func TestNewPathSpecFromConfig(t *testing.T) {
	viper.Set("disablePathToLower", true)
	viper.Set("removePathAccents", true)
	viper.Set("uglyURLs", true)
	viper.Set("multilingual", true)
	viper.Set("defaultContentLanguageInSubdir", true)
	viper.Set("defaultContentLanguage", "no")
	viper.Set("currentContentLanguage", NewLanguage("no"))
	viper.Set("canonifyURLs", true)
	viper.Set("paginatePath", "side")

	pathSpec := NewPathSpecFromConfig(viper.GetViper())

	require.True(t, pathSpec.canonifyURLs)
	require.True(t, pathSpec.defaultContentLanguageInSubdir)
	require.True(t, pathSpec.disablePathToLower)
	require.True(t, pathSpec.multilingual)
	require.True(t, pathSpec.removePathAccents)
	require.True(t, pathSpec.uglyURLs)
	require.Equal(t, "no", pathSpec.defaultContentLanguage)
	require.Equal(t, "no", pathSpec.currentContentLanguage.Lang)
	require.Equal(t, "side", pathSpec.paginatePath)
}
Esempio n. 9
0
func TestURLize(t *testing.T) {
	initCommonTestConfig()

	p := NewPathSpecFromConfig(viper.GetViper())

	tests := []struct {
		input    string
		expected string
	}{
		{"  foo bar  ", "foo-bar"},
		{"foo.bar/foo_bar-foo", "foo.bar/foo_bar-foo"},
		{"foo,bar:foobar", "foobarfoobar"},
		{"foo/bar.html", "foo/bar.html"},
		{"трям/трям", "%D1%82%D1%80%D1%8F%D0%BC/%D1%82%D1%80%D1%8F%D0%BC"},
		{"100%-google", "100-google"},
	}

	for _, test := range tests {
		output := p.URLize(test.input)
		if output != test.expected {
			t.Errorf("Expected %#v, got %#v\n", test.expected, output)
		}
	}
}
Esempio n. 10
0
func newViperProvidedRenderingContext() *RenderingContext {
	return &RenderingContext{ConfigProvider: viper.GetViper()}
}