-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathbuild_test.go
56 lines (45 loc) · 1.63 KB
/
build_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"slices"
"strings"
"testing"
"github.com/joeshaw/envdecode"
"github.com/stretchr/testify/require"
)
func init() {
if err := envdecode.Decode(&conf); err != nil {
fmt.Fprintf(os.Stderr, "Error decoding conf from env: %v", err)
os.Exit(1)
}
}
func TestExtCanonical(t *testing.T) {
require.Equal(t, ".jpg", extCanonical("https://example.com/image.jpg"))
require.Equal(t, ".jpg", extCanonical("https://example.com/image.JPG"))
require.Equal(t, ".jpg", extCanonical("https://example.com/image.jpg?query"))
}
func TestExtImageTarget(t *testing.T) {
require.Equal(t, ".jpg", extImageTarget(".jpg"))
require.Equal(t, ".webp", extImageTarget(".heic"))
}
func TestLexicographicBase32(t *testing.T) {
// Should only incorporate lower case characters.
require.True(t, lexicographicBase32 == strings.ToLower(lexicographicBase32))
// All characters in the encoding set should be lexicographically ordered.
{
// This can be replaced with `strings.Clone` come Go 1.20.
b := make([]byte, len(lexicographicBase32))
copy(b, lexicographicBase32)
slices.Sort(b)
require.Equal(t, lexicographicBase32, string(b))
}
}
func TestPagePathKey(t *testing.T) {
require.Equal(t, "about", pagePathKey("./pages/about.ace"))
require.Equal(t, "about", pagePathKey("./pages-drafts/about.ace"))
require.Equal(t, "deep/about", pagePathKey("./pages/deep/about.ace"))
require.Equal(t, "deep/about", pagePathKey("./pages-drafts/deep/about.ace"))
require.Equal(t, "really/deep/about", pagePathKey("./pages/really/deep/about.ace"))
require.Equal(t, "really/deep/about", pagePathKey("./pages-drafts/really/deep/about.ace"))
}