|
| 1 | +package com.itextpdf.styledxmlparser.css.resolve.shorthand; |
| 2 | + |
| 3 | +import com.itextpdf.styledxmlparser.css.CommonCssConstants; |
| 4 | +import com.itextpdf.styledxmlparser.css.CssDeclaration; |
| 5 | +import com.itextpdf.styledxmlparser.css.resolve.shorthand.impl.ColumnsShorthandResolver; |
| 6 | +import com.itextpdf.styledxmlparser.logs.StyledXmlParserLogMessageConstant; |
| 7 | +import com.itextpdf.test.ExtendedITextTest; |
| 8 | +import com.itextpdf.test.annotations.LogMessage; |
| 9 | +import com.itextpdf.test.annotations.LogMessages; |
| 10 | +import com.itextpdf.test.annotations.type.UnitTest; |
| 11 | + |
| 12 | +import java.util.Collections; |
| 13 | +import java.util.List; |
| 14 | +import org.junit.Assert; |
| 15 | +import org.junit.Test; |
| 16 | +import org.junit.experimental.categories.Category; |
| 17 | + |
| 18 | +@Category(UnitTest.class) |
| 19 | +public class ColumnsShorthandResolverTest extends ExtendedITextTest { |
| 20 | + @Test |
| 21 | + public void initialOrInheritOrUnsetValuesTest() { |
| 22 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 23 | + |
| 24 | + String initialShorthand = CommonCssConstants.INITIAL; |
| 25 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(initialShorthand); |
| 26 | + Assert.assertEquals(2, resolvedShorthand.size()); |
| 27 | + Assert.assertEquals(CommonCssConstants.COLUMN_COUNT, resolvedShorthand.get(0).getProperty()); |
| 28 | + Assert.assertEquals(CommonCssConstants.INITIAL, resolvedShorthand.get(0).getExpression()); |
| 29 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(1).getProperty()); |
| 30 | + Assert.assertEquals(CommonCssConstants.INITIAL, resolvedShorthand.get(1).getExpression()); |
| 31 | + |
| 32 | + String inheritShorthand = CommonCssConstants.INHERIT; |
| 33 | + resolvedShorthand = resolver.resolveShorthand(inheritShorthand); |
| 34 | + Assert.assertEquals(2, resolvedShorthand.size()); |
| 35 | + Assert.assertEquals(CommonCssConstants.COLUMN_COUNT, resolvedShorthand.get(0).getProperty()); |
| 36 | + Assert.assertEquals(CommonCssConstants.INHERIT, resolvedShorthand.get(0).getExpression()); |
| 37 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(1).getProperty()); |
| 38 | + Assert.assertEquals(CommonCssConstants.INHERIT, resolvedShorthand.get(1).getExpression()); |
| 39 | + |
| 40 | + String unsetShorthand = CommonCssConstants.UNSET; |
| 41 | + resolvedShorthand = resolver.resolveShorthand(unsetShorthand); |
| 42 | + Assert.assertEquals(2, resolvedShorthand.size()); |
| 43 | + Assert.assertEquals(CommonCssConstants.COLUMN_COUNT, resolvedShorthand.get(0).getProperty()); |
| 44 | + Assert.assertEquals(CommonCssConstants.UNSET, resolvedShorthand.get(0).getExpression()); |
| 45 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(1).getProperty()); |
| 46 | + Assert.assertEquals(CommonCssConstants.UNSET, resolvedShorthand.get(1).getExpression()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + @LogMessages(messages = @LogMessage(messageTemplate = StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY, count = 2)) |
| 51 | + public void emptyShorthandTest() { |
| 52 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 53 | + String emptyShorthand = ""; |
| 54 | + Assert.assertEquals(Collections.<CssDeclaration>emptyList(), resolver.resolveShorthand(emptyShorthand)); |
| 55 | + |
| 56 | + String shorthandWithSpaces = " "; |
| 57 | + Assert.assertEquals(Collections.<CssDeclaration>emptyList(), resolver.resolveShorthand(shorthandWithSpaces)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void columnsWithOneAbsoluteValueTest() { |
| 62 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 63 | + |
| 64 | + String shorthand = "10px"; |
| 65 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 66 | + |
| 67 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 68 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(0).getProperty()); |
| 69 | + Assert.assertEquals("10px", resolvedShorthand.get(0).getExpression()); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void columnWithOneMetricValueTest() { |
| 74 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 75 | + |
| 76 | + String shorthand = "10px"; |
| 77 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 78 | + |
| 79 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 80 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(0).getProperty()); |
| 81 | + Assert.assertEquals("10px", resolvedShorthand.get(0).getExpression()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void columnWithOneRelativeValueTest() { |
| 86 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 87 | + |
| 88 | + String shorthand = "10em"; |
| 89 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 90 | + |
| 91 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 92 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(0).getProperty()); |
| 93 | + Assert.assertEquals("10em", resolvedShorthand.get(0).getExpression()); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void columnWithColumnCountTest() { |
| 98 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 99 | + |
| 100 | + String shorthand = "3"; |
| 101 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 102 | + |
| 103 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 104 | + Assert.assertEquals(CommonCssConstants.COLUMN_COUNT, resolvedShorthand.get(0).getProperty()); |
| 105 | + Assert.assertEquals("3", resolvedShorthand.get(0).getExpression()); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void columnWithAutoValuesTest() { |
| 110 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 111 | + |
| 112 | + String shorthand = "auto auto"; |
| 113 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 114 | + |
| 115 | + Assert.assertTrue(resolvedShorthand.isEmpty()); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void columnWithAutoAndRelativeValueTest() { |
| 120 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 121 | + |
| 122 | + String shorthand = "3em auto"; |
| 123 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 124 | + |
| 125 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 126 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(0).getProperty()); |
| 127 | + Assert.assertEquals("3em", resolvedShorthand.get(0).getExpression()); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + public void columnWithRelativeAndAutoValueTest() { |
| 132 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 133 | + |
| 134 | + String shorthand = "auto 3em"; |
| 135 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 136 | + |
| 137 | + Assert.assertEquals(1, resolvedShorthand.size()); |
| 138 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(0).getProperty()); |
| 139 | + Assert.assertEquals("3em", resolvedShorthand.get(0).getExpression()); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + public void columnWithRelativeAndCountValueTest() { |
| 144 | + IShorthandResolver resolver = new ColumnsShorthandResolver(); |
| 145 | + |
| 146 | + String shorthand = "12 3em"; |
| 147 | + List<CssDeclaration> resolvedShorthand = resolver.resolveShorthand(shorthand); |
| 148 | + |
| 149 | + Assert.assertEquals(2, resolvedShorthand.size()); |
| 150 | + Assert.assertEquals(CommonCssConstants.COLUMN_COUNT, resolvedShorthand.get(0).getProperty()); |
| 151 | + Assert.assertEquals("12", resolvedShorthand.get(0).getExpression()); |
| 152 | + Assert.assertEquals(CommonCssConstants.COLUMN_WIDTH, resolvedShorthand.get(1).getProperty()); |
| 153 | + Assert.assertEquals("3em", resolvedShorthand.get(1).getExpression()); |
| 154 | + } |
| 155 | + |
| 156 | +} |
0 commit comments