Skip to content

Commit ef6714d

Browse files
committed
Merge branch 'master' of github.com:yegor256/xembly
2 parents 1af0c66 + a52ba1f commit ef6714d

4 files changed

Lines changed: 101 additions & 8 deletions

File tree

.github/workflows/mvn.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ jobs:
2424
with:
2525
distribution: 'temurin'
2626
java-version: ${{ matrix.java }}
27-
- uses: actions/cache@v5
28-
with:
29-
path: ~/.m2/repository
30-
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
31-
restore-keys: |
32-
${{ runner.os }}-jdk-${{ matrix.java }}-maven-
3327
- run: java -version
3428
- run: mvn -version
35-
- run: mvn --errors --batch-mode clean install -Pqulice
29+
- run: mvn --errors --batch-mode clean install -Pqulice -Dhone.skip=true

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
<plugin>
218218
<groupId>org.eolang</groupId>
219219
<artifactId>hone-maven-plugin</artifactId>
220-
<version>0.23.2</version>
220+
<version>0.23.3</version>
221221
<executions>
222222
<execution>
223223
<goals>

src/main/java/org/xembly/Transformers.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,37 @@ public Transformer create() {
5353
}
5454
}
5555

56+
/**
57+
* Transformer factory that produces compact (non-indented) XML.
58+
* All transformers produced by this factory will be configured to produce
59+
* XML documents with XML declaration but without pretty-printing
60+
* (no indentation, no extra line breaks).
61+
* @since 0.32.3
62+
*/
63+
final class Compact implements Transformers {
64+
65+
/**
66+
* Original transformer factory.
67+
*/
68+
private final Transformers original;
69+
70+
/**
71+
* Default ctor.
72+
* @since 0.32.3
73+
*/
74+
public Compact() {
75+
this.original = new Transformers.Formatted(
76+
new Transformers.Default(),
77+
Collections.singletonMap(OutputKeys.ENCODING, "UTF-8")
78+
);
79+
}
80+
81+
@Override
82+
public Transformer create() {
83+
return this.original.create();
84+
}
85+
}
86+
5687
/**
5788
* Transformer factory that produces document transformers.
5889
* All transformers produced by this factory will be configured to produce
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2013-2026 Yegor Bugayenko
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.xembly;
6+
7+
import org.hamcrest.MatcherAssert;
8+
import org.hamcrest.Matchers;
9+
import org.junit.jupiter.api.Test;
10+
11+
/**
12+
* Test case for {@link Transformers}.
13+
*
14+
* @since 0.32.3
15+
*/
16+
final class TransformersTest {
17+
18+
@Test
19+
void prettyPrintsByDefault() throws Exception {
20+
MatcherAssert.assertThat(
21+
"Default Xembler must produce indented XML",
22+
new Xembler(
23+
new Directives().add("a").add("b").set("hello")
24+
).xml(),
25+
Matchers.containsString("<a>\n")
26+
);
27+
}
28+
29+
@Test
30+
void disablesPrettyPrintWithCompact() throws Exception {
31+
MatcherAssert.assertThat(
32+
"Compact transformer must produce non-indented XML",
33+
new Xembler(
34+
new Directives().add("a").add("b").set("hello"),
35+
new Transformers.Compact()
36+
).xml(),
37+
Matchers.allOf(
38+
Matchers.containsString("<a><b>hello</b></a>"),
39+
Matchers.not(Matchers.containsString("\n ")),
40+
Matchers.not(Matchers.containsString("\n "))
41+
)
42+
);
43+
}
44+
45+
@Test
46+
void rendersDeclarationInCompactMode() throws Exception {
47+
MatcherAssert.assertThat(
48+
"Compact transformer must keep XML declaration",
49+
new Xembler(
50+
new Directives().add("root"),
51+
new Transformers.Compact()
52+
).xml(),
53+
Matchers.startsWith("<?xml version=\"1.0\"")
54+
);
55+
}
56+
57+
@Test
58+
void omitsDeclarationWithNode() throws Exception {
59+
MatcherAssert.assertThat(
60+
"Node transformer must omit XML declaration",
61+
new Xembler(
62+
new Directives().add("root"),
63+
new Transformers.Node()
64+
).xml(),
65+
Matchers.not(Matchers.containsString("<?xml"))
66+
);
67+
}
68+
}

0 commit comments

Comments
 (0)