-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
RpgDataConvertTest.java
322 lines (280 loc) · 13.9 KB
/
RpgDataConvertTest.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package dev.ebullient.convert;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import dev.ebullient.convert.io.Tui;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
import io.quarkus.test.junit.main.QuarkusMainLauncher;
import io.quarkus.test.junit.main.QuarkusMainTest;
import picocli.CommandLine;
@QuarkusMainTest
public class RpgDataConvertTest {
static Path outputPath_5e;
static Path outputPath_pf2;
static Tui tui;
@BeforeAll
public static void setupDir() {
setupDir("RpgDataConvertTest");
}
public static void setupDir(String root) {
tui = new Tui();
tui.init(null, false, false);
outputPath_5e = TestUtils.OUTPUT_ROOT_5E.resolve(root).resolve("test-cli");
outputPath_pf2 = TestUtils.OUTPUT_ROOT_PF2.resolve(root).resolve("test-cli");
outputPath_5e.toFile().mkdirs();
outputPath_pf2.toFile().mkdirs();
}
@Test
@Launch({ "--help" })
void testCommandHelp(LaunchResult result) {
result.echoSystemOut();
assertThat(result.getOutput())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.contains("Usage: ttrpg-convert");
}
@Test
@Launch({ "--version" })
void testCommandVersion(LaunchResult result) {
result.echoSystemOut();
assertThat(result.getOutput())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.contains("ttrpg-convert version");
}
@Test
void testCommandLiveData_5e(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
final Path target = outputPath_5e.resolve("srd-index");
TestUtils.deleteDir(target);
// SRD
LaunchResult result = launcher.launch("--index",
"-o", target.toString(), TestUtils.TOOLS_PATH_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
// Subset
result = launcher.launch("--index", "-s", "PHB,DMG,XGE,SCAG",
"-o", outputPath_5e.resolve("subset-index").toString(), TestUtils.TOOLS_PATH_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
}
}
@Test
void testCommandLiveData_5eAllSources(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
// All, I mean it. Really for real.. ALL.
final Path allIndex = outputPath_5e.resolve("all-index");
TestUtils.deleteDir(allIndex);
List<String> args = new ArrayList<>(List.of("--index", "-s", "ALL",
"--background", "examples/templates/tools5e/images-background2md.txt",
"--item", "examples/templates/tools5e/images-item2md.txt",
"--monster", "examples/templates/tools5e/images-monster2md.txt",
"--race", "examples/templates/tools5e/images-race2md.txt",
"--spell", "examples/templates/tools5e/images-spell2md.txt",
"-o", allIndex.toString(),
TestUtils.TOOLS_PATH_5E.toString()));
args.addAll(getFilesFrom(TestUtils.TOOLS_PATH_5E.resolve("adventure")));
args.addAll(getFilesFrom(TestUtils.TOOLS_PATH_5E.resolve("book")));
LaunchResult result = launcher.launch(args.toArray(new String[0]));
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
Tui tui = new Tui();
tui.init(null, false, false);
TestUtils.assertDirectoryContents(allIndex, tui, (p, content) -> {
List<String> errors = new ArrayList<>();
content.forEach(l -> TestUtils.checkMarkdownLinks(allIndex.toString(), p, l, errors));
return errors;
});
}
}
List<String> getFilesFrom(Path directory) {
try (Stream<Path> paths = Files.walk(directory)) {
return paths
.filter(p -> p.toFile().isFile())
.map(Path::toString)
.filter(s -> s.endsWith(".json"))
.collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Test
void testCommandLiveData_5eOneSource(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("erlw");
TestUtils.deleteDir(target);
// No basics
LaunchResult result = launcher.launch("-s", "ERLW",
"-o", target.toString(), TestUtils.TOOLS_PATH_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
}
}
@Test
void testCommandLiveData_5eHomebrew(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists() && TestUtils.HOMEBREW_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("homebrew");
TestUtils.deleteDir(target);
// No basics
LaunchResult result = launcher.launch("--debug", "--index",
"-s", "PHB", "-s", "MM", "-s", "DMG",
"-s", "dndwiki_bestbackgrounds",
"-s", "TDCSR",
"-s", "SC",
"-s", "arkadia",
"-s", "NerzugalsExtendedBestiary",
"-s", "TheLostLands",
"-o", target.toString(),
TestUtils.TOOLS_PATH_5E.toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("background/D&D Wiki; Featured Quality Backgrounds.json").toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("book/Darrington Press; Tal'Dorei Campaign Setting Reborn.json")
.toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("class/D&D Wiki; Swashbuckler.json").toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("collection/Arcana Games; Arkadia.json").toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("creature/Nerzugal Role-Playing; Nerzugal's Extended Bestiary.json")
.toString(),
TestUtils.HOMEBREW_PATH_5E.resolve("deity/Frog God Games; The Lost Lands.json").toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
}
}
@Test
void testCommandTemplates_5e(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("srd-templates");
TestUtils.deleteDir(target);
// SRD only, just templates
LaunchResult result = launcher.launch(
"--background", "src/test/resources/other/background.txt",
"--class", "src/test/resources/other/class.txt",
"--deity", "src/test/resources/other/deity.txt",
"--feat", "src/test/resources/other/feat.txt",
"--item", "src/test/resources/other/item.txt",
"--name", "src/test/resources/other/name.txt",
"--note", "src/test/resources/other/note.txt",
"--race", "src/test/resources/other/race.txt",
"--spell", "src/test/resources/other/spell.txt",
"--subclass", "src/test/resources/other/subclass.txt",
"-o", target.toString(), TestUtils.TOOLS_PATH_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
List.of(
// target.resolve("compendium/backgrounds")
target.resolve("compendium/classes"),
target.resolve("compendium/deities"),
target.resolve("compendium/feats"),
target.resolve("compendium/items"),
target.resolve("compendium/races"),
target.resolve("compendium/spells"))
.forEach(directory -> TestUtils.assertDirectoryContents(directory, tui, (p, content) -> {
if (content.stream().noneMatch(l -> l.equals("- test")) &&
content.stream().noneMatch(l -> l.startsWith("# Index"))) {
return List.of("Unable to find the - test tag in file " + p);
}
return List.of();
}));
}
}
@Test
void testCommandBadTemplates(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("bad-templates");
LaunchResult result = launcher.launch("--index",
"--background=garbage.txt",
"-o", target.toString(),
TestUtils.TOOLS_PATH_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command did not fail as expected. Output:%n%s", TestUtils.dump(result))
.isEqualTo(CommandLine.ExitCode.USAGE);
}
}
@Test
void testCommandBadTemplatesInJson(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("bad-templates-json");
LaunchResult result = launcher.launch("--index",
"-o", target.toString(),
TestUtils.TOOLS_PATH_5E.toString(),
TestUtils.TEST_SOURCES_BAD_TEMPL_JSON.toString());
assertThat(result.exitCode())
.withFailMessage("Command did not fail as expected. Output:%n%s", TestUtils.dump(result))
.isEqualTo(CommandLine.ExitCode.USAGE);
}
}
@Test
void testCommand_5eBookAdventureInJson(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_5E.toFile().exists()) {
Path target = outputPath_5e.resolve("json-book-adventure");
TestUtils.deleteDir(target);
LaunchResult result = launcher.launch("--index",
"-o", target.toString(),
TestUtils.TOOLS_PATH_5E.toString(),
TestUtils.TEST_SOURCES_BOOK_ADV_JSON_5E.toString());
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
Path wbtw = target.resolve("compend ium/adventures/the-wild-beyond-the-witchlight");
assertThat(wbtw).exists();
assertThat(wbtw).isDirectory();
Path phb = target.resolve("compend ium/books/players-handbook");
assertThat(phb).exists();
assertThat(phb).isDirectory();
List.of(
target.resolve("compend ium/adventures"),
target.resolve("compend ium/backgrounds"),
target.resolve("compend ium/books"),
target.resolve("compend ium/classes"),
target.resolve("compend ium/deities"),
target.resolve("compend ium/feats"),
target.resolve("compend ium/items"),
target.resolve("compend ium/races"),
target.resolve("compend ium/spells"))
.forEach(directory -> TestUtils.assertDirectoryContents(directory, tui, (p, content) -> {
List<String> errors = new ArrayList<>();
if (content.stream().anyMatch(l -> l.contains("/ru les/"))) {
errors.add("Found '/ru les/' " + p); // not escaped
}
if (content.stream().anyMatch(l -> l.contains("/compend ium/"))) {
errors.add("Found '/compend ium/' " + p); // not escaped
}
return errors;
}));
}
}
@Test
void testCommandLiveData_Pf2eAllSources(QuarkusMainLauncher launcher) {
if (TestUtils.TOOLS_PATH_PF2E.toFile().exists()) {
// All, I mean it. Really for real.. ALL.
final Path allIndex = outputPath_pf2.resolve("all-index");
TestUtils.deleteDir(allIndex);
List<String> args = new ArrayList<>(List.of("--index",
"-s", "ALL",
"-o", allIndex.toString(),
"-g", "pf2e",
TestUtils.TOOLS_PATH_PF2E.toString()));
LaunchResult result = launcher.launch(args.toArray(new String[0]));
assertThat(result.exitCode())
.withFailMessage("Command failed. Output:%n%s", TestUtils.dump(result))
.isEqualTo(0);
Tui tui = new Tui();
tui.init(null, false, false);
TestUtils.assertDirectoryContents(allIndex, tui, (p, content) -> {
List<String> errors = new ArrayList<>();
content.forEach(l -> TestUtils.checkMarkdownLinks(allIndex.toString(), p, l, errors));
return errors;
});
}
}
}