|
| 1 | +package xlog |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "github.com/yuin/goldmark/text" |
| 9 | +) |
| 10 | + |
| 11 | +func TestBanner(t *testing.T) { |
| 12 | + tcs := []struct { |
| 13 | + name string |
| 14 | + path string |
| 15 | + content string |
| 16 | + expected string |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "page in root and image is relative implicitly", |
| 20 | + path: "home", |
| 21 | + content: "", |
| 22 | + expected: "/image.jpg", |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "page in root and image is relative explicitly", |
| 26 | + path: "home", |
| 27 | + content: "", |
| 28 | + expected: "/image.jpg", |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "page in root and image is relative explicitly in subdir", |
| 32 | + path: "home", |
| 33 | + content: "", |
| 34 | + expected: "/images/image.jpg", |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "page in subdir and image is relative implicitly", |
| 38 | + path: "posts/home", |
| 39 | + content: "", |
| 40 | + expected: "/posts/image.jpg", |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "page in subdir and image is relative explicitly", |
| 44 | + path: "posts/home", |
| 45 | + content: "", |
| 46 | + expected: "/posts/image.jpg", |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "page in subdir and image is relative explicitly in subdir", |
| 50 | + path: "posts/home", |
| 51 | + content: "", |
| 52 | + expected: "/posts/images/image.jpg", |
| 53 | + }, |
| 54 | + { |
| 55 | + name: "page in subdir and image is relative explicitly in parent", |
| 56 | + path: "posts/home", |
| 57 | + content: "", |
| 58 | + expected: "/images/image.jpg", |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + for _, tc := range tcs { |
| 63 | + t.Run(tc.name, func(t *testing.T) { |
| 64 | + reader := text.NewReader([]byte(tc.content)) |
| 65 | + p := page{ |
| 66 | + name: tc.path, |
| 67 | + lastUpdate: time.Time{}, |
| 68 | + ast: MarkdownConverter().Parser().Parse(reader), |
| 69 | + content: (*Markdown)(&tc.content), |
| 70 | + } |
| 71 | + |
| 72 | + require.Equal(t, tc.expected, Banner(&p)) |
| 73 | + }) |
| 74 | + } |
| 75 | +} |
0 commit comments