|
| 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