This repository has no description
1package markup
2
3import "testing"
4
5func TestFileTypePatterns(t *testing.T) {
6 cases := []struct {
7 format Format
8 filename string
9 want bool
10 }{
11 {FormatMarkdown, "x.md", true},
12 {FormatMarkdown, "x.MARKDOWN", true},
13 {FormatMarkdown, "x.mkdn", true},
14 {FormatMarkdown, "x.mkd", true},
15 {FormatMarkdown, "x.mdown", true},
16 {FormatMarkdown, "x.txt", false},
17 {FormatMarkdown, "x.rst", false},
18 }
19
20 for _, c := range cases {
21 t.Run(string(c.format)+"/"+c.filename, func(t *testing.T) {
22 p, ok := FileTypePatterns[c.format]
23 if !ok {
24 t.Fatalf("FileTypePatterns[%q] missing", c.format)
25 }
26 if got := p.MatchString(c.filename); got != c.want {
27 t.Errorf("FileTypePatterns[%q].MatchString(%q) = %v, want %v", c.format, c.filename, got, c.want)
28 }
29 })
30 }
31}
32
33func TestGetFormat(t *testing.T) {
34 cases := []struct {
35 filename string
36 want Format
37 }{
38 {"x.md", FormatMarkdown},
39 {"x.MARKDOWN", FormatMarkdown},
40 {"x.txt", FormatText},
41 {"x.rs", FormatText}, // unknown -> default
42 {"noext", FormatText},
43 }
44
45 for _, c := range cases {
46 t.Run(c.filename, func(t *testing.T) {
47 if got := GetFormat(c.filename); got != c.want {
48 t.Errorf("GetFormat(%q) = %q, want %q", c.filename, got, c.want)
49 }
50 })
51 }
52}