Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/templates/template_functions_test.go

903 lignes
20 KiB
Go
Brut Lien permanent Vue normale Historique

package templates
import (
"fmt"
"html/template"
"net/url"
"path"
"testing"
"time"
"reflect"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/categories"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
)
// run before router/init.go:init()
var _ = func() (_ struct{}) {
categories.InitCategories()
return
}()
func TestGetRawQuery(t *testing.T) {
var tests = []map[string]string{
{
"test": "",
"expected": "",
},
{
"test": "http://lol.co/",
"expected": "",
},
{
"test": "lol.co",
"expected": "",
},
{
"test": "lol.co?",
"expected": "",
},
{
"test": "lol.co?why",
"expected": "why",
},
{
"test": "https://lol.co?why",
"expected": "why",
},
}
for _, test := range tests {
url, _ := url.Parse(test["test"])
value := getRawQuery(url)
if value != test["expected"] {
t.Errorf("Unexpected value from the function getRawQuery, got '%s', wanted '%s' for '%s'", value, test["expected"], test["test"])
}
}
}
func TestGenSearchWithOrdering(t *testing.T) {
var tests = []map[string]string{
{
"test": "",
"mode": "2",
"expected": "/search?order=true&sort=2",
},
{
"test": "http://lol.co/?s=why&sort=1",
"mode": "2",
"expected": "/search?order=false&s=why&sort=2",
},
{
"test": "http://lol.co/?s=why&sort=1",
"mode": "1",
"expected": "/search?order=true&s=why&sort=1",
},
{
"test": "http://lol.co/?s=why&sort=1&order=true",
"mode": "1",
"expected": "/search?order=false&s=why&sort=1",
},
{
"test": "http://lol.co/?s=why&sort=1&order=false",
"mode": "1",
"expected": "/search?order=true&s=why&sort=1",
},
{
"test": "http://lol.co/?s=why&sort=1&order=false",
"mode": "2",
"expected": "/search?order=false&s=why&sort=2",
},
{
"test": "http://lol.co/?s=why&sort=1&order=true",
"mode": "2",
"expected": "/search?order=false&s=why&sort=2",
},
}
for _, test := range tests {
url, _ := url.Parse(test["test"])
value := genSearchWithOrdering(url, test["mode"], "/search")
if value != test["expected"] {
t.Errorf("Unexpected value from the function genSearchWithOrdering, got '%s', wanted '%s' for '%s' and '%s'", value, test["expected"], test["test"], test["mode"])
}
}
}
func TestgenSearchWithCategory(t *testing.T) {
var tests = []map[string]string{
{
"test": "",
"mode": "1_",
"expected": "/search?c=1_",
},
}
for _, test := range tests {
url, _ := url.Parse(test["test"])
value := genSearchWithCategory(url, test["mode"], "/search")
if value != test["expected"] {
t.Errorf("Unexpected value from the function genSearchWithCategory, got '%s', wanted '%s' for '%s' and '%s'", value, test["expected"], test["test"], test["mode"])
}
}
}
func TestFlagCode(t *testing.T) {
var tests = []map[string]string{
{
"test": "",
"expected": "und",
},
{
"test": "es",
"expected": "es",
},
{
"test": "lol",
"expected": "lol",
},
{
"test": "fr-fr",
"expected": "fr",
},
{
"test": "fr-lol",
"expected": "lol",
},
{
"test": "ca-es",
"expected": "ca",
},
{
"test": "es-mx",
"expected": "es",
},
}
for _, test := range tests {
value := flagCode(test["test"])
if value != test["expected"] {
t.Errorf("Unexpected value from the function flagCode, got '%s', wanted '%s' for '%s'", value, test["expected"], test["test"])
}
}
}
func TestGetAvatar(t *testing.T) {
var tests = []struct {
Test string
Size int
Expected string
}{
{
Test: "",
Size: 0,
2017-11-01 01:44:16 +01:00
Expected: "/img/avatar_0.jpg",
},
{
Test: "",
Size: 100,
2017-11-01 01:44:16 +01:00
Expected: "/img/avatar_100.jpg",
},
{
Test: "test",
Size: 100,
Expected: "https://www.gravatar.com/avatar/test?s=100",
},
{
Test: "test",
Size: 0,
Expected: "https://www.gravatar.com/avatar/test?s=0",
},
}
for _, test := range tests {
value := getAvatar(test.Test, test.Size)
if value != test.Expected {
t.Errorf("Unexpected value from the function getAvatar, got '%s', wanted '%s' for '%s' and '%d'", value, test.Expected, test.Test, test.Size)
}
}
2017-11-01 08:38:48 +01:00
}
func TestGetCategory(t *testing.T) {
var tests = []struct {
TestCat string
TestParent bool
Expected categories.Categories
}{
{
TestCat: "",
TestParent: false,
Expected: categories.Categories{},
},
{
TestCat: "",
TestParent: true,
Expected: categories.Categories{},
},
{
TestCat: "3_12",
TestParent: false,
Expected: categories.Categories{},
},
{
TestCat: "3",
TestParent: false,
Expected: categories.Categories{
{"3_12", "anime_amv"},
{"3_5", "anime_english_translated"},
{"3_13", "anime_non_english_translated"},
{"3_6", "anime_raw"},
},
},
{
TestCat: "3",
TestParent: true,
Expected: categories.Categories{
{"3_", "anime"},
{"3_12", "anime_amv"},
{"3_5", "anime_english_translated"},
{"3_13", "anime_non_english_translated"},
{"3_6", "anime_raw"},
},
},
}
for _, test := range tests {
value := getCategory(test.TestCat, test.TestParent)
if !reflect.DeepEqual(value, test.Expected) {
t.Errorf("Unexpected value from the function getCategory, got '%v', wanted '%v' for '%s' and '%t'", value, test.Expected, test.TestCat, test.TestParent)
}
}
}
func TestCategoryName(t *testing.T) {
var tests = []struct {
TestCat string
TestSubCat string
Expected string
}{
{
TestCat: "",
TestSubCat: "",
Expected: "",
},
{
TestCat: "d",
TestSubCat: "s",
Expected: "",
},
{
TestCat: "3",
TestSubCat: "",
Expected: "anime",
},
{
TestCat: "3",
TestSubCat: "6",
Expected: "anime_raw",
},
}
for _, test := range tests {
value := categoryName(test.TestCat, test.TestSubCat)
if value != test.Expected {
t.Errorf("Unexpected value from the function categoryName, got '%s', wanted '%s' for '%s' and '%s'", value, test.Expected, test.TestCat, test.TestSubCat)
}
}
}
Janitor (#1728) * Fix "torrent is being generated" message showing up even when the torrent couldn't be generated * Add janitor user status * Remove usage of deprecated HasAdmin() function * Give Janitors access to mod panel * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Update edit.go * Update profile.go * Rollback bad changes, remove redundant email check and stop using deprecated function * Show every userstatus (member, janitor, banned, mod) in comments * Return empty status if anonymous * Show no userstatus for anonymous profile * Show moderation link to janitors too * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Add Janitor to userstatus select in user edit * "Janitor" translation string * didnt mean to commit this change * rollback wrongfully comitted changes * rollback commit * Update CHANGELOG.md * Fix wrong id for translation * remove deprecated HasAdmin() function again * change name of variable used in comment loop for clarity purposes * visual cue for locked torrents in torrent listing for admins * add visual cues for hidden torrents in admin torrent listing * Dont show delete buttons for janitors * janitor cannot delete torrents * show block/unblock button in torrent list for janitors instead of delete button * fix function that didnt get executed * add ban buttons on userlist & visual cue for banned users * Fix "user successfully deleted" message showing even if user wasnt deleted * Add "ban" button, no "delete" button for jantiors * add "unban" and "ban" translation strings * add "unban" and "ban" translation strings * different <form> for ban button * Update index.jet.html * add userprofile ban route * add toggleBan() function, janitors dont need captcha either * fix panic error when deleting an anonymous comment * add user_banned_by and user_unbanned_by * add user_banned_by and user_unbanned_by * Make ToggleBan() return whether or not the user is now banned * Add handler for /ban route * change log filter * hide locked torrents from regular users * hide locked torrents from regular users * hide locked torrent from api search for regular users * change function to CurrentOrJanitor * change function to currentorjanitor * change function to currentorjanitor * add CurrentOrJanitor function * fix extra ( * fix extra ) and wrong variable name * Fix wrong value for janitor user status * Fix user edit that did not work because of "unique constraint user.emails" error * only immediately visually update user if user has been updated successfully * use FindAllForAdminsOrderBy in order to preload users * create FindAllForAdminsOrderBy that preloads users * Show username instead of ID in Uploader column in admin panel * Fix userprofile buttons overflowing at some specific resolutions * Mods can set users as janitors * Show ban/unban buttons on userprofile for janitors * Identical styling for usermenu links and buttons * dont show ban buttons on other staff * add ban message through get parameter * make toggleBan() trigger user update * Add "user_banned" and "user_unbanned" * add "user_banned" and "user_unbanned" * Visual cue for banned user * banned users can still log in * visual cue for banned user in badgemenu * locked status if banned user on upload * banned users cannot comment * Put "banned" text between () * add GetCategoryName() to template_test * add GetCategoryName() that returns full category name from full category string * Show search content in page title if it exists, or search category if it exists, otherwise shows "Home" * error message when user uploads an torrent & is banned * add torrent_uploaded_locked * add torrent_uploaded_locked * fix delete definitely button that never appeared * Show delete definitely button on admin panel index * admins can undelete a torrent by editing it's status * Trigger ViewHandler() directly instead of redirecting * Render the template directly instead of triggering torrent view handler * bigger usermenu buttons once responsive design kicks in * make btn-* class non-bold * Responsive notification page * visual cue for locked torrents in torrent listing * Update search.go * Update search.go * Update api.go * Update helpers.go * Update template.go * Update torrentParam.go * remove "hidden" class * Update search.go * fix an html error * Add files via upload * Update admin.jet.html * Update index.go * Update index.go * Update router.go * Update torrentParam_test.go * Update torrentParam_test.go * fix extra " * fix bad copypaste * Update CHANGELOG.md * Update guidelines.jet.html * Update CHANGELOG.md * add Guidelines and Moderation Guidelines * fix missing commas * Update torrentlist.jet.html * Update find.go * Update stats.go * Update view.jet.html * Update index.jet.html
2017-11-14 09:39:39 +01:00
func TestCategoryName2(t *testing.T) {
var tests = []struct {
TestCat string
Expected string
}{
{
TestCat: "_",
Expected: "",
},
{
TestCat: "d",
Expected: "",
},
{
TestCat: "3_",
Expected: "anime",
},
{
TestCat: "3_6",
Expected: "anime_raw",
},
}
for _, test := range tests {
value := GetCategoryName(test.TestCat)
if value != test.Expected {
t.Errorf("Unexpected value from the function categoryName, got '%s', wanted '%s' for '%s'", value, test.Expected, test.TestCat)
}
}
}
func TestLanguageName(t *testing.T) {
var tests = []struct {
TestLang publicSettings.Language
Expected string
}{
{
TestLang: publicSettings.Language{"", "", ""},
Expected: "",
},
{
TestLang: publicSettings.Language{"", "fr", "fr-fr"},
Expected: "French (France)",
},
{
TestLang: publicSettings.Language{"", "fr", "fr"},
Expected: "French",
},
{
TestLang: publicSettings.Language{"something, something", "es", "es, es-mx"},
Expected: "Spanish, Mexican Spanish",
},
}
T := mockupTemplateT(t)
for _, test := range tests {
value := languageName(test.TestLang, T)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%s', wanted '%s' for '%v'", value, test.Expected, test.TestLang)
}
}
}
func TestLanguageNameFromCode(t *testing.T) {
var tests = []struct {
TestLang string
Expected string
}{
{
TestLang: "",
Expected: "",
},
{
TestLang: "fr-fr",
Expected: "French (France)",
},
{
TestLang: "ofjd",
Expected: "",
},
{
TestLang: "fr",
Expected: "French",
},
{
TestLang: "es, es-mx",
Expected: "Spanish, Mexican Spanish",
},
}
T := mockupTemplateT(t)
for _, test := range tests {
value := languageNameFromCode(test.TestLang, T)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%s', wanted '%s' for '%s'", value, test.Expected, test.TestLang)
}
}
}
func TestFileSize(t *testing.T) {
var tests = []struct {
TestSize int64
2017-11-01 01:44:16 +01:00
TestShowUnknown bool
Expected template.HTML
}{
{
TestSize: 0,
2017-11-01 01:44:16 +01:00
TestShowUnknown: true,
Expected: template.HTML("Unknown"),
},
2017-11-01 01:44:16 +01:00
{
TestSize: 0,
TestShowUnknown: false,
Expected: template.HTML("0.0 B"),
},
{
TestSize: 10,
2017-11-01 01:59:48 +01:00
TestShowUnknown: false,
Expected: template.HTML("10.0 B"),
},
{
TestSize: 10,
TestShowUnknown: true,
Expected: template.HTML("10.0 B"),
},
}
T := mockupTemplateT(t)
for _, test := range tests {
2017-11-01 02:38:06 +01:00
value := fileSize(test.TestSize, T, test.TestShowUnknown)
if value != test.Expected {
t.Errorf("Unexpected value from the function fileSize, got '%s', wanted '%s' for '%d' with '%t'", value, test.Expected, test.TestSize, test.TestShowUnknown)
}
}
}
func TestLastID(t *testing.T) {
var tests = []struct {
TestTorrents []models.TorrentJSON
TestURL string
Expected int
}{
{
TestTorrents: []models.TorrentJSON{{ID: 3}, {ID: 1}},
TestURL: "?sort=&order=",
Expected: 3,
},
{
TestTorrents: []models.TorrentJSON{{ID: 3}, {ID: 1}},
TestURL: "?sort=2&order=",
Expected: 3,
},
{
TestTorrents: []models.TorrentJSON{{ID: 1}, {ID: 3}},
TestURL: "?sort=2&order=true",
Expected: 3,
},
{
TestTorrents: []models.TorrentJSON{{ID: 1}, {ID: 3}},
TestURL: "?sort=3&order=true",
Expected: 0,
},
{
TestTorrents: []models.TorrentJSON{},
TestURL: "?sort=2&order=true",
Expected: 0,
},
{
TestTorrents: []models.TorrentJSON{},
TestURL: "?sort=2&order=false",
Expected: 0,
},
}
for _, test := range tests {
url, _ := url.Parse(test.TestURL)
value := lastID(url, test.TestTorrents)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%d', wanted '%d' for '%s' and '%v'", value, test.Expected, test.TestURL, test.TestTorrents)
}
}
}
func TestGetReportDescription(t *testing.T) {
var tests = []struct {
TestDesc string
Expected string
}{
{
TestDesc: "",
Expected: "",
},
{
TestDesc: "illegal",
Expected: "Illegal content",
},
{
TestDesc: "spam",
Expected: "Spam / Garbage",
},
{
TestDesc: "wrongcat",
Expected: "Wrong category",
},
{
TestDesc: "dup",
Expected: "Duplicate / Deprecated",
},
{
TestDesc: "illegal_content",
Expected: "Illegal content",
},
{
TestDesc: "spam_garbage",
Expected: "Spam / Garbage",
},
{
TestDesc: "wrong_category",
Expected: "Wrong category",
},
{
TestDesc: "duplicate_deprecated",
Expected: "Duplicate / Deprecated",
},
}
T := mockupTemplateT(t)
for _, test := range tests {
value := getReportDescription(test.TestDesc, T)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%s', wanted '%s' for '%s'", value, test.Expected, test.TestDesc)
}
}
}
func TestGenUploaderLink(t *testing.T) {
var tests = []struct {
TestID uint
TestName template.HTML
TestHidden bool
Expected template.HTML
}{
{
TestID: 0,
TestName: template.HTML(""),
TestHidden: false,
Expected: template.HTML("れんちょん"),
},
{
TestID: 10,
TestName: template.HTML("dd"),
TestHidden: true,
Expected: template.HTML("れんちょん"),
},
{
TestID: 10,
TestName: template.HTML("dd"),
TestHidden: false,
Expected: template.HTML("<a href=\"/user/10/dd\">dd</a>"),
},
{
TestID: 0, // Old Uploader
TestName: template.HTML("dd"),
TestHidden: false,
Expected: template.HTML("dd"),
},
{
TestID: 10,
TestName: template.HTML(""),
TestHidden: false,
Expected: template.HTML("れんちょん"),
},
{
TestID: 10,
TestName: template.HTML(""),
TestHidden: true,
Expected: template.HTML("れんちょん"),
},
}
for _, test := range tests {
value := genUploaderLink(test.TestID, test.TestName, test.TestHidden)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%s', wanted '%s' for '%d' and '%s' and '%t'", string(value), string(test.Expected), test.TestID, string(test.TestName), test.TestHidden)
}
}
}
func TestContains(t *testing.T) {
var tests = []struct {
TestArr interface{}
TestComp string
Expected bool
}{
{
TestArr: "kilo",
TestComp: "kilo",
Expected: true,
},
{
TestArr: "kilo",
TestComp: "loki", // Clearly not the same level
Expected: false,
},
{
TestArr: "kilo",
TestComp: "kiloo",
Expected: false,
},
{
TestArr: publicSettings.Language{Code: "kilo"},
TestComp: "kilo",
Expected: true,
},
{
TestArr: publicSettings.Language{Code: "kilo"},
TestComp: "loki", // Clearly not the same level
Expected: false,
},
{
TestArr: publicSettings.Language{Code: "kilo"},
TestComp: "kiloo",
Expected: false,
},
{
TestArr: "kilo",
TestComp: "",
Expected: false,
},
{
TestArr: publicSettings.Language{Code: "kilo"},
TestComp: "",
Expected: false,
},
}
for _, test := range tests {
value := contains(test.TestArr, test.TestComp)
if value != test.Expected {
t.Errorf("Unexpected value from the function languageName, got '%t', wanted '%t' for '%v' and '%s'", value, test.Expected, test.TestArr, test.TestComp)
}
}
}
func testTorrentFileExists(t *testing.T) {
var tests = []struct {
hash string
Expected bool
}{
{
hash: "",
Expected: false,
},
}
for _, test := range tests {
value := torrentFileExists(test.hash, "")
if value != test.Expected {
t.Errorf("Unexpected value from the function TorrentFileExists, got '%t', wanted '%t' for '%s'", value, test.Expected, test.hash)
}
}
}
2017-11-01 08:52:47 +01:00
func Teststrcmp(t *testing.T) {
var tests = []struct {
TestString string
TestString2 string
2017-11-01 08:52:47 +01:00
TestEnd int
TestStart int
Expected bool
}{
{
TestString: "kilo",
TestString2: "kilo",
2017-11-01 08:52:47 +01:00
TestEnd: -1,
TestStart: 0,
Expected: true,
},
{
2017-11-01 08:52:47 +01:00
TestString: "kilo",
TestString2: "loki",
TestEnd: -1,
TestStart: 0,
Expected: false,
},
"No comments" message, avatar in comments, classic theme improvements, some other changes, Old Navigation (#1545) * Update view.jet.html * Update en-us.all.json * Update view.jet.html * Update CHANGELOG.md * fix travis * Update classic.css * Update view.jet.html * Update main.css * Update classic.css * Update classic.css * Update classic.css * add link to user page & avatar in comment * stylisation for avatar in main.css * Update classic.css * Fix wrongly placed ::before * Add rule list to terms of service * import rules on register * fix refine-container-2's inputs * Update base.jet.html * Update en-us.all.json * Update CHANGELOG.md * GenNav changes to constantly put HTML for nav arrows regardless of page * css changes for website nav etc etc * add OldNav global variable * Add OldNav to test.go * Update publicSettings.go * change OldNav's value type * Old navigation in settings * add OldNav in user variables * add oldNav input handler in settings.go * Change OldNav's default value into false * Create OldNav.jet.html * Update search.jet.html * remove character that had nothing to do here * fix wrong variable name * fix worng variable name and travis * Update classic.css * Add sort order & type to old nav * add toString() function in test * add toString() function * translation string for oldnav setting * Use translation string in settings.jet.html * fix few html errors * ditto * travis fix test * remove useless charset * remove useless things * add spaces before attributes * attempt at fixing travis 2 * fix wrong variable name * Update classic.css * fix travis plsss
2017-09-11 19:45:39 +02:00
{
2017-11-01 08:52:47 +01:00
TestString: "superkilo", //compare "superkilo" to "kilo"
TestString2: "kilo",
TestEnd: -1,
TestStart: 0,
Expected: false,
},
{
TestString: "superkilo", //compare "kilo" to "kilo"
TestString2: "kilo",
TestEnd: -1,
TestStart: 6,
Expected: true,
2017-11-01 09:05:38 +01:00
},
2017-11-01 08:52:47 +01:00
{
TestString: "superkill", //compare "kil" to "kil"
TestString2: "kilo",
TestEnd: 8,
TestStart: 6,
Expected: true,
"No comments" message, avatar in comments, classic theme improvements, some other changes, Old Navigation (#1545) * Update view.jet.html * Update en-us.all.json * Update view.jet.html * Update CHANGELOG.md * fix travis * Update classic.css * Update view.jet.html * Update main.css * Update classic.css * Update classic.css * Update classic.css * add link to user page & avatar in comment * stylisation for avatar in main.css * Update classic.css * Fix wrongly placed ::before * Add rule list to terms of service * import rules on register * fix refine-container-2's inputs * Update base.jet.html * Update en-us.all.json * Update CHANGELOG.md * GenNav changes to constantly put HTML for nav arrows regardless of page * css changes for website nav etc etc * add OldNav global variable * Add OldNav to test.go * Update publicSettings.go * change OldNav's value type * Old navigation in settings * add OldNav in user variables * add oldNav input handler in settings.go * Change OldNav's default value into false * Create OldNav.jet.html * Update search.jet.html * remove character that had nothing to do here * fix wrong variable name * fix worng variable name and travis * Update classic.css * Add sort order & type to old nav * add toString() function in test * add toString() function * translation string for oldnav setting * Use translation string in settings.jet.html * fix few html errors * ditto * travis fix test * remove useless charset * remove useless things * add spaces before attributes * attempt at fixing travis 2 * fix wrong variable name * Update classic.css * fix travis plsss
2017-09-11 19:45:39 +02:00
},
}
for _, test := range tests {
2017-11-01 08:52:47 +01:00
value := strcmp(test.TestString, test.TestString2, -1, 0)
"No comments" message, avatar in comments, classic theme improvements, some other changes, Old Navigation (#1545) * Update view.jet.html * Update en-us.all.json * Update view.jet.html * Update CHANGELOG.md * fix travis * Update classic.css * Update view.jet.html * Update main.css * Update classic.css * Update classic.css * Update classic.css * add link to user page & avatar in comment * stylisation for avatar in main.css * Update classic.css * Fix wrongly placed ::before * Add rule list to terms of service * import rules on register * fix refine-container-2's inputs * Update base.jet.html * Update en-us.all.json * Update CHANGELOG.md * GenNav changes to constantly put HTML for nav arrows regardless of page * css changes for website nav etc etc * add OldNav global variable * Add OldNav to test.go * Update publicSettings.go * change OldNav's value type * Old navigation in settings * add OldNav in user variables * add oldNav input handler in settings.go * Change OldNav's default value into false * Create OldNav.jet.html * Update search.jet.html * remove character that had nothing to do here * fix wrong variable name * fix worng variable name and travis * Update classic.css * Add sort order & type to old nav * add toString() function in test * add toString() function * translation string for oldnav setting * Use translation string in settings.jet.html * fix few html errors * ditto * travis fix test * remove useless charset * remove useless things * add spaces before attributes * attempt at fixing travis 2 * fix wrong variable name * Update classic.css * fix travis plsss
2017-09-11 19:45:39 +02:00
if value != test.Expected {
t.Errorf("Unexpected value from the function strcmp, got '%t' by comparing '%s' to '%s' starting at '%d' and ending after '%d', wanted '%t'", value, test.TestString, test.TestString2, test.TestStart, test.TestEnd, test.Expected)
"No comments" message, avatar in comments, classic theme improvements, some other changes, Old Navigation (#1545) * Update view.jet.html * Update en-us.all.json * Update view.jet.html * Update CHANGELOG.md * fix travis * Update classic.css * Update view.jet.html * Update main.css * Update classic.css * Update classic.css * Update classic.css * add link to user page & avatar in comment * stylisation for avatar in main.css * Update classic.css * Fix wrongly placed ::before * Add rule list to terms of service * import rules on register * fix refine-container-2's inputs * Update base.jet.html * Update en-us.all.json * Update CHANGELOG.md * GenNav changes to constantly put HTML for nav arrows regardless of page * css changes for website nav etc etc * add OldNav global variable * Add OldNav to test.go * Update publicSettings.go * change OldNav's value type * Old navigation in settings * add OldNav in user variables * add oldNav input handler in settings.go * Change OldNav's default value into false * Create OldNav.jet.html * Update search.jet.html * remove character that had nothing to do here * fix wrong variable name * fix worng variable name and travis * Update classic.css * Add sort order & type to old nav * add toString() function in test * add toString() function * translation string for oldnav setting * Use translation string in settings.jet.html * fix few html errors * ditto * travis fix test * remove useless charset * remove useless things * add spaces before attributes * attempt at fixing travis 2 * fix wrong variable name * Update classic.css * fix travis plsss
2017-09-11 19:45:39 +02:00
}
}
}
2017-11-01 08:52:47 +01:00
func Teststrfind(t *testing.T) {
var tests = []struct {
TestString string
TestString2 string
2017-11-01 09:40:41 +01:00
TestStart int
2017-11-01 08:52:47 +01:00
Match bool
}{
{
TestString: "kilo",
TestString2: "kilo",
2017-11-01 09:40:41 +01:00
TestStart: 0,
2017-11-01 08:52:47 +01:00
Match: true,
},
{
TestString: "kilo",
2017-11-01 08:52:47 +01:00
TestString2: "loki",
2017-11-01 09:40:41 +01:00
TestStart: 0,
2017-11-01 08:52:47 +01:00
Match: false,
},
{
2017-11-01 09:40:41 +01:00
TestString: "akumeme",
TestString2: "meme",
TestStart: 0,
Match: true,
},
{
TestString: "memeaku",
TestString2: "meme",
TestStart: 4, //Search "meme" in "aku", obviously not there
Match: false,
},
}
for _, test := range tests {
2017-11-01 09:40:41 +01:00
value := strfind(test.TestString, test.TestString2, test.TestStart)
if value != test.Match {
t.Errorf("Unexpected value from the function strfind, got '%t' by comparing '%s' to '%s' starting from %d, wanted '%t'", value, test.TestString, test.TestString2, test.TestStart, test.Match)
}
}
}
func TestGetDomain(t *testing.T) {
var tests = []struct {
domainName string
}{
{
domainName: "wubwub",
},
}
for _, test := range tests {
value := getDomainName()
if value != test.domainName {
//t.Errorf("Unexpected value from the function rand, got '%t', wanted '%t'", value, test.domainName)
}
}
}
2017-11-01 09:58:17 +01:00
2017-11-01 10:55:48 +01:00
func TestGetTheme(t *testing.T) {
2017-11-01 10:46:10 +01:00
var tests = []struct {
domainName []string
}{
{
2017-11-01 10:55:48 +01:00
domainName: []string{"test", "test", "test"},
2017-11-01 10:46:10 +01:00
},
}
for _, test := range tests {
2017-11-01 10:55:48 +01:00
test.domainName = getThemeList()
}
}
2017-11-01 10:21:06 +01:00
func testformatThemeName(t *testing.T) {
var tests = []struct {
2017-11-01 08:22:43 +01:00
TestPath string
Expected string
}{
{
2017-11-01 08:22:43 +01:00
TestPath: "g",
2017-11-01 08:30:09 +01:00
Expected: "/g/",
2017-11-01 08:22:43 +01:00
},
{
TestPath: "v",
2017-11-01 08:30:09 +01:00
Expected: "/v/",
2017-11-01 08:22:43 +01:00
},
{
TestPath: "my_theme",
2017-11-01 08:30:09 +01:00
Expected: "My Theme",
2017-11-01 08:22:43 +01:00
},
{
TestPath: "tomorrow",
2017-11-01 08:30:09 +01:00
Expected: "Tomorrow",
},
}
for _, test := range tests {
Ts, _, err := publicSettings.TfuncAndLanguageWithFallback("en-us")
if err != nil {
t.Error("Couldn't load language files!")
}
var T publicSettings.TemplateTfunc
T = func(id string, args ...interface{}) template.HTML {
return template.HTML(fmt.Sprintf(Ts(id), args...))
}
2017-11-01 08:22:43 +01:00
value := formatThemeName(test.TestPath, T)
if value != test.Expected {
t.Errorf("Unexpected value from the function formatThemeName, got '%s' from '%s', wanted '%s'", value, test.TestPath, test.Expected)
}
}
}
func testFormatDate(t *testing.T) {
2017-11-01 08:22:43 +01:00
UTC, _ := time.LoadLocation("")
var tests = []struct {
2017-11-01 08:22:43 +01:00
TestDate time.Time
TestFullDate bool
Expected string
}{
{
2017-11-01 08:22:43 +01:00
TestDate: time.Date(2017, 11, 1, 0, 0, 0, 0, UTC),
TestFullDate: false,
2017-11-01 08:30:09 +01:00
Expected: "Nov 1, 2017",
2017-11-01 08:22:43 +01:00
},
{
TestDate: time.Date(2017, 11, 1, 0, 0, 0, 0, UTC),
TestFullDate: true,
2017-11-01 08:30:09 +01:00
Expected: "11/1/2017, 0:00:00 AM UTC+0",
},
}
for _, test := range tests {
2017-11-01 08:37:05 +01:00
value := formatDate(test.TestDate, test.TestFullDate)
2017-11-01 08:22:43 +01:00
if value != test.Expected {
t.Errorf("Unexpected value from the function formatDate, got '%s' from '%s' and '%t', wanted '%s'", value, test.TestDate, test.TestFullDate, test.Expected)
}
}
}
func testGenSearchName(t *testing.T) {
var tests = []struct {
Search SearchForm
currentURL string
Expected string
}{
{
Search: SearchForm{},
currentURL: "/",
Expected: "home",
},
{
Search: SearchForm{},
currentURL: "/search",
Expected: "search",
},
{
Search: SearchForm{UserName: "yiiT"},
currentURL: "/username/yiiT/search",
Expected: "yiiT",
},
{
Search: SearchForm{Category: "3_"},
currentURL: "/search?c=3_",
Expected: "anime",
},
{
Search: SearchForm{Category: "3_12"},
currentURL: "/search?c=3_12",
Expected: "anime_amv",
},
}
for _, test := range tests {
Ts, _, err := publicSettings.TfuncAndLanguageWithFallback("en-us")
if err != nil {
t.Error("Couldn't load language files!")
}
var T publicSettings.TemplateTfunc
T = func(id string, args ...interface{}) template.HTML {
return template.HTML(fmt.Sprintf(Ts(id), args...))
}
value := GenSearchName(test.Search, test.currentURL, T)
if value != test.Expected {
t.Errorf("Unexpected value from the function GenSearchName, got '%s' wanted '%s'", value, test.Expected)
}
}
}
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
conf := config.Get().I18n
conf.Directory = path.Join("..", conf.Directory)
var retriever publicSettings.UserRetriever // not required during initialization
err := publicSettings.InitI18n(conf, retriever)
if err != nil {
t.Errorf("failed to initialize language translations: %v", err)
}
Ts, _, err := publicSettings.TfuncAndLanguageWithFallback("en-us")
if err != nil {
t.Error("Couldn't load language files!")
}
var T publicSettings.TemplateTfunc
T = func(id string, args ...interface{}) template.HTML {
return template.HTML(fmt.Sprintf(Ts(id), args...))
}
return T
}