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/util/filelist/filelist_test.go
akuma06 c3211c6a14 Gofmt friendly (#752)
Keeping Go source code in line with what they preconize
2017-05-26 07:35:37 +10:00

48 lignes
898 o
Go

package filelist
import (
"github.com/NyaaPantsu/nyaa/model"
"html/template"
"testing"
)
func makeDummyFile(path ...string) (file model.File) {
file.SetPath(path)
return
}
func dashes(n uint) (out string) {
var i uint
for i = 0; i < n; i++ {
out += "-"
}
return
}
func TestFilelist(T *testing.T) {
files := []model.File{
makeDummyFile("A", "B", "C.txt"),
makeDummyFile("A", "C", "C.txt"),
makeDummyFile("B.txt"),
}
expected := "A\n" +
"-B\n" +
"--C.txt\n" +
"-C\n" +
"--C.txt\n" +
"B.txt\n"
filelist := FileListToFolder(files)
out, err := filelist.MakeFolderTreeView("{{dashes .NestLevel}}{{.FolderName}}\n", "{{dashes .NestLevel}}{{.Filename}}\n", map[string]interface{}{
"dashes": dashes,
}, nil)
if err != nil {
T.Fatalf("%v", err)
return
}
if out != template.HTML(expected) {
T.Fatalf("Error: expected %s, got %s", expected, out)
return
}
}