-
Notifications
You must be signed in to change notification settings - Fork 219
/
image-data.js
114 lines (85 loc) · 4.67 KB
/
image-data.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
const ImageData = require("../lib/ImageData");
const test = require("ava");
let image;
test.before(t => {
image = new ImageData("a/b/c/key.png", "bucket", "data", {});
});
test("Build output path when directory is undefined", t => {
t.is(image.combineWithDirectory({}), "a/b/c/key.png");
});
test("Build output path when directory is empty", t => {
t.is(image.combineWithDirectory({directory: ""}), "key.png");
});
test("Build output path when directory is relative deeper", t => {
t.is(image.combineWithDirectory({directory: "./d"}), "a/b/c/d/key.png");
});
test("Build output path when directory is relative deeper - 2nd level", t => {
t.is(image.combineWithDirectory({directory: "./d/e"}), "a/b/c/d/e/key.png");
});
test("Build output path when directory is relative backward", t => {
t.is(image.combineWithDirectory({directory: ".."}), "a/b/key.png");
});
test("Build output path when directory is relative backward with new subdirectory branch", t => {
t.is(image.combineWithDirectory({directory: "../d"}), "a/b/d/key.png");
});
test("Build output path when directory is absolute", t => {
t.is(image.combineWithDirectory({directory: "d"}), "d/key.png");
});
test("Build output path when directory is absolute - 2nd level", t => {
t.is(image.combineWithDirectory({directory: "d/e"}), "d/e/key.png");
});
test("Build output path with prefix", t => {
t.is(image.combineWithDirectory({directory: "d/e", prefix: "prefix-"}), "d/e/prefix-key.png");
});
test("Build output path with suffix", t => {
t.is(image.combineWithDirectory({directory: "d/e", suffix: "-suffix"}), "d/e/key-suffix.png");
});
test("Build output path with prefix and suffix", t => {
t.is(image.combineWithDirectory({directory: "d/e", prefix: "prefix-", suffix: "_suffix"}), "d/e/prefix-key_suffix.png");
});
test("Build output path with keep orignal extension", t => {
t.is(image.combineWithDirectory({directory: "d/e", keepExtension: true}), "d/e/key.png");
});
test("[path-template] Build output path when template is an empty object", t => {
t.is(image.combineWithDirectory({}), "a/b/c/key.png");
});
test("[path-template] Build output path when template is an empty map", t => {
t.is(image.combineWithDirectory({template: {}}), "a/b/c/key.png");
});
test("[path-template] Build output path when template is an map with pattern and output keys empty", t => {
t.is(image.combineWithDirectory({template: {pattern: "", output: ""}}), "a/b/c/key.png");
});
test("[path-template] Build output path when template replace whole directory", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: ""}}), "key.png");
});
test("[path-template] Build output path when template adds subdirectory", t => {
t.is(image.combineWithDirectory({template: {pattern: "*path", output: "*path/d"}}), "a/b/c/d/key.png");
});
test("[path-template] Build output path when template adds subdirectory - 2nd level", t => {
t.is(image.combineWithDirectory({template: {pattern: "*path", output: "*path/d/e"}}), "a/b/c/d/e/key.png");
});
test("[path-template] Build output path when template removes top subdirectory", t => {
t.is(image.combineWithDirectory({template: {pattern: "*path/c", output: "*path"}}), "a/b/key.png");
});
test("[path-template] Build output path when template replaces top subdirectory with new one", t => {
t.is(image.combineWithDirectory({template: {pattern: "*path/c", output: "*path/d"}}), "a/b/d/key.png");
});
test("[path-template] Build output path when template replaces old path with new absolute one", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: "d"}}), "d/key.png");
});
test("[path-template] Build output path when template replaces old path with new absolute one - 2nd level", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: "d/e"}}), "d/e/key.png");
});
test("[path-template] Build output path when template didn't match base directory", t => {
t.is(image.combineWithDirectory({template: {pattern: "x/:something", output: "d/e"}}), "a/b/c/key.png");
});
test("[path-template] Build output path with template and prefix", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: "d/e"}, prefix: "prefix-"}), "d/e/prefix-key.png");
});
test("[path-template] Build output path with template and suffix", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: "d/e"}, suffix: "-suffix"}), "d/e/key-suffix.png");
});
test("[path-template] Build output path with template, prefix and suffix", t => {
t.is(image.combineWithDirectory({template: {pattern: "*", output: "d/e"}, prefix: "prefix-", suffix: "_suffix"}), "d/e/prefix-key_suffix.png");
});