File: main_test.go

package info (click to toggle)
golang-github-tdewolff-minify 2.20.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 39,388 kB
  • sloc: javascript: 394,644; xml: 25,649; ansic: 253; makefile: 108; python: 108; sh: 47
file content (58 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download
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
57
58
package main

import (
	"fmt"
	"testing"
	"testing/fstest"

	"github.com/tdewolff/test"
)

func TestCreateTasks(t *testing.T) {
	fsys := fstest.MapFS{
		"a.js":     {},
		"dir/b.js": {},
	}

	tests := []struct {
		input, output string
		tasks         map[string]string
	}{
		// root file
		{"a.js", "", map[string]string{"a.js": ""}},
		{"a.js", ".", map[string]string{"a.js": "a.js"}},
		{"a.js", "./", map[string]string{"a.js": "a.js"}},
		{"a.js", "out", map[string]string{"a.js": "out"}},
		{"a.js", "out/", map[string]string{"a.js": "out/a.js"}},

		// nested file
		{"dir/b.js", "", map[string]string{"dir/b.js": ""}},
		{"dir/b.js", ".", map[string]string{"dir/b.js": "b.js"}},
		{"dir/b.js", "./", map[string]string{"dir/b.js": "b.js"}},
		{"dir/b.js", "out", map[string]string{"dir/b.js": "out"}},
		{"dir/b.js", "out/", map[string]string{"dir/b.js": "out/b.js"}},

		// directory
		{"dir", "", map[string]string{"dir/b.js": ""}},
		{"dir", ".", map[string]string{"dir/b.js": "dir/b.js"}},
		{"dir", "./", map[string]string{"dir/b.js": "dir/b.js"}},
		{"dir", "out/", map[string]string{"dir/b.js": "out/dir/b.js"}},
		{"dir/", "out/", map[string]string{"dir/b.js": "out/b.js"}},
	}

	recursive = true
	for _, tt := range tests {
		t.Run(tt.input+" => "+tt.output, func(t *testing.T) {
			tasks, _, err := createTasks(fsys, []string{tt.input}, tt.output)
			test.Error(t, err)
			if len(tasks) != len(tt.tasks) {
				test.Fail(t, fmt.Sprintf("missing %v", tt.tasks))
			}
			for _, task := range tasks {
				if dst, ok := tt.tasks[task.srcs[0]]; !ok || dst != task.dst {
					test.Fail(t, fmt.Sprintf("unexpected %s => %s", task.srcs[0], task.dst))
				}
			}
		})
	}
}