|
| 1 | +/* |
| 2 | + * See the NOTICE file distributed with this work for additional |
| 3 | + * information regarding copyright ownership. |
| 4 | + * |
| 5 | + * This is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU Lesser General Public License as |
| 7 | + * published by the Free Software Foundation; either version 2.1 of |
| 8 | + * the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This software is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this software; if not, write to the Free |
| 17 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. |
| 19 | + */ |
| 20 | + |
| 21 | +package org.xwiki.rendering.listener; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.xwiki.rendering.block.Block; |
| 27 | +import org.xwiki.rendering.block.MacroBlock; |
| 28 | +import org.xwiki.rendering.block.SpaceBlock; |
| 29 | +import org.xwiki.rendering.block.WordBlock; |
| 30 | +import org.xwiki.rendering.internal.parser.XDOMGeneratorListener; |
| 31 | + |
| 32 | +import static org.junit.jupiter.api.Assertions.*; |
| 33 | + |
| 34 | +/** |
| 35 | + * Unit tests for {@link InlineFilterListener}. |
| 36 | + * |
| 37 | + * @version $Id$ |
| 38 | + */ |
| 39 | +class InlineFilterListenerTest |
| 40 | +{ |
| 41 | + @Test |
| 42 | + void beginParagraph() |
| 43 | + { |
| 44 | + InlineFilterListener listener = new InlineFilterListener(); |
| 45 | + XDOMGeneratorListener xdomGeneratorListener = new XDOMGeneratorListener(); |
| 46 | + listener.setWrappedListener(xdomGeneratorListener); |
| 47 | + |
| 48 | + listener.beginDocument(new MetaData()); |
| 49 | + listener.beginParagraph(Listener.EMPTY_PARAMETERS); |
| 50 | + listener.onWord("This"); |
| 51 | + listener.onSpace(); |
| 52 | + listener.onWord("is"); |
| 53 | + listener.onSpace(); |
| 54 | + listener.onWord("inline"); |
| 55 | + listener.endParagraph(Listener.EMPTY_PARAMETERS); |
| 56 | + listener.endDocument(new MetaData()); |
| 57 | + |
| 58 | + List<Block> children = xdomGeneratorListener.getXDOM().getChildren(); |
| 59 | + List<Block> expectedChildren = List.of(new WordBlock("This"), new SpaceBlock(), new WordBlock("is"), |
| 60 | + new SpaceBlock(), new WordBlock("inline")); |
| 61 | + assertEquals(expectedChildren, children); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void onMacro() |
| 66 | + { |
| 67 | + InlineFilterListener listener = new InlineFilterListener(); |
| 68 | + XDOMGeneratorListener xdomGeneratorListener = new XDOMGeneratorListener(); |
| 69 | + listener.setWrappedListener(xdomGeneratorListener); |
| 70 | + |
| 71 | + listener.beginDocument(new MetaData()); |
| 72 | + listener.onMacro("testMacro", Listener.EMPTY_PARAMETERS, null, false); |
| 73 | + listener.endDocument(new MetaData()); |
| 74 | + |
| 75 | + List<Block> children = xdomGeneratorListener.getXDOM().getChildren(); |
| 76 | + List<Block> expectedChildren = List.of(new MacroBlock("testMacro", Listener.EMPTY_PARAMETERS, null, true)); |
| 77 | + assertEquals(expectedChildren, children); |
| 78 | + } |
| 79 | +} |
0 commit comments