|
1 | 1 | package org.asciidoctor.cli;
|
2 | 2 |
|
3 | 3 | import com.beust.jcommander.JCommander;
|
4 |
| -import org.asciidoctor.Attributes; |
5 |
| -import org.asciidoctor.Options; |
6 |
| -import org.asciidoctor.OptionsBuilder; |
7 | 4 | import org.asciidoctor.SafeMode;
|
8 |
| -import org.asciidoctor.jruby.internal.AsciidoctorUtils; |
9 | 5 | import org.junit.Test;
|
10 | 6 |
|
11 | 7 | import java.io.File;
|
12 |
| -import java.util.List; |
| 8 | +import java.nio.file.Path; |
13 | 9 |
|
14 |
| -import static org.hamcrest.CoreMatchers.is; |
15 |
| -import static org.hamcrest.MatcherAssert.assertThat; |
16 |
| -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; |
17 |
| -import static org.hamcrest.collection.IsMapContaining.hasEntry; |
18 |
| -import static org.hamcrest.collection.IsMapContaining.hasKey; |
| 10 | +import static org.assertj.core.api.Assertions.assertThat; |
19 | 11 |
|
20 | 12 | public class WhenAsciidoctorAPICallIsCalled {
|
21 | 13 |
|
22 | 14 | @Test
|
23 | 15 | public void api_parameters_should_be_transformed_to_cli_command() {
|
24 |
| - |
25 |
| - Attributes attributes = Attributes.builder() |
26 |
| - .attribute("myAtribute", "myValue") |
27 |
| - .sectionNumbers(true) |
28 |
| - .copyCss(false) |
29 |
| - .build(); |
30 |
| - |
31 |
| - OptionsBuilder optionsBuilder = Options.builder() |
32 |
| - .backend("docbook") |
33 |
| - .templateDirs(new File("a"), new File("b")) |
34 |
| - .safe(SafeMode.UNSAFE) |
35 |
| - .attributes(attributes); |
36 |
| - |
37 |
| - List<String> command = AsciidoctorUtils.toAsciidoctorCommand( |
38 |
| - optionsBuilder.asMap(), "file.adoc"); |
39 |
| - |
40 |
| - String currentDirectory = new File("").getAbsolutePath() + File.separator; |
41 |
| - |
42 |
| - String[] parameters = command.subList(1, command.size()).toArray(new String[0]); |
| 16 | + final String currentDirectory = new File("").getAbsolutePath() + File.separator; |
| 17 | + var parameters = new String[]{ |
| 18 | + "-T", Path.of(currentDirectory, "a").toAbsolutePath().toString(), |
| 19 | + "-T", Path.of(currentDirectory, "b").toAbsolutePath().toString(), |
| 20 | + "-S", "UNSAFE", |
| 21 | + "-b", "docbook", |
| 22 | + "-a", "myAttribute=myValue", |
| 23 | + "-a", "sectnums", |
| 24 | + "-a", "copycss!", |
| 25 | + "file.adoc" |
| 26 | + }; |
43 | 27 |
|
44 | 28 | final AsciidoctorCliOptions asciidoctorCliOptions = new AsciidoctorCliOptions();
|
45 | 29 | final JCommander jCommander = new JCommander(asciidoctorCliOptions);
|
46 | 30 | jCommander.parse(parameters);
|
47 | 31 |
|
48 |
| - assertThat(asciidoctorCliOptions.getTemplateDir(), containsInAnyOrder(currentDirectory + "a", currentDirectory + "b")); |
49 |
| - assertThat(asciidoctorCliOptions.getSafeMode(), is(SafeMode.UNSAFE)); |
50 |
| - assertThat(asciidoctorCliOptions.getBackend(), is("docbook")); |
51 |
| - assertThat(asciidoctorCliOptions.getParameters(), containsInAnyOrder("file.adoc")); |
52 |
| - |
53 |
| - assertThat(asciidoctorCliOptions.getAttributes(), hasEntry("myAtribute", "myValue")); |
54 |
| - assertThat(asciidoctorCliOptions.getAttributes(), hasKey("sectnums")); |
55 |
| - assertThat(asciidoctorCliOptions.getAttributes(), hasKey("copycss!")); |
| 32 | + assertThat(asciidoctorCliOptions.getTemplateDir()).containsExactlyInAnyOrder(currentDirectory + "a", currentDirectory + "b"); |
| 33 | + assertThat(asciidoctorCliOptions.getSafeMode()).isEqualTo(SafeMode.UNSAFE); |
| 34 | + assertThat(asciidoctorCliOptions.getBackend()).isEqualTo("docbook"); |
| 35 | + assertThat(asciidoctorCliOptions.getParameters()).containsExactly("file.adoc"); |
| 36 | + assertThat(asciidoctorCliOptions.getAttributes()) |
| 37 | + .containsEntry("myAttribute", "myValue") |
| 38 | + .containsEntry("sectnums", "") |
| 39 | + .containsEntry("copycss!", ""); |
56 | 40 | }
|
57 |
| - |
58 | 41 | }
|
0 commit comments