|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using iText.StyledXmlParser.Css; |
| 4 | +using iText.StyledXmlParser.Css.Resolve.Shorthand.Impl; |
| 5 | +using iText.Test; |
| 6 | + |
| 7 | +namespace iText.StyledXmlParser.Css.Resolve.Shorthand { |
| 8 | + public class TextDecorationUnitTest : ExtendedITextTest { |
| 9 | + [NUnit.Framework.Test] |
| 10 | + public virtual void ResolveShorthandLineEmptyTest() { |
| 11 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 12 | + IList<CssDeclaration> result = resolver.ResolveShorthand(""); |
| 13 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 14 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 15 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-line")); |
| 16 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 17 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 18 | + } |
| 19 | + |
| 20 | + [NUnit.Framework.Test] |
| 21 | + public virtual void ResolveShorthandLineNoneTest() { |
| 22 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 23 | + IList<CssDeclaration> result = resolver.ResolveShorthand("none"); |
| 24 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 25 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 26 | + NUnit.Framework.Assert.AreEqual("none", resultMap.Get("text-decoration-line")); |
| 27 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 28 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 29 | + } |
| 30 | + |
| 31 | + [NUnit.Framework.Test] |
| 32 | + public virtual void ResolveShorthandLineNoneAndUnderlineTogetherTest() { |
| 33 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 34 | + IList<CssDeclaration> result = resolver.ResolveShorthand("none underline"); |
| 35 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 36 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 37 | + String line = resultMap.Get("text-decoration-line"); |
| 38 | + NUnit.Framework.Assert.IsTrue(line != null && line.Contains("underline") && line.Contains("none")); |
| 39 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 40 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 41 | + } |
| 42 | + |
| 43 | + [NUnit.Framework.Test] |
| 44 | + public virtual void ResolveShorthandLineOnePropertyTest() { |
| 45 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 46 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline"); |
| 47 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 48 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 49 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 50 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 51 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 52 | + } |
| 53 | + |
| 54 | + [NUnit.Framework.Test] |
| 55 | + public virtual void ResolveShorthandLineTwoPropertiesTest() { |
| 56 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 57 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline overline"); |
| 58 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 59 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 60 | + String line = resultMap.Get("text-decoration-line"); |
| 61 | + NUnit.Framework.Assert.IsTrue(line != null && line.Contains("underline") && line.Contains("overline")); |
| 62 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 63 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 64 | + } |
| 65 | + |
| 66 | + [NUnit.Framework.Test] |
| 67 | + public virtual void ResolveShorthandColorNamedTest() { |
| 68 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 69 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline red"); |
| 70 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 71 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 72 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 73 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 74 | + NUnit.Framework.Assert.AreEqual("red", resultMap.Get("text-decoration-color")); |
| 75 | + } |
| 76 | + |
| 77 | + [NUnit.Framework.Test] |
| 78 | + public virtual void ResolveShorthandColorRgbTest() { |
| 79 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 80 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline rgb(255, 255, 0)"); |
| 81 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 82 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 83 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 84 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 85 | + NUnit.Framework.Assert.AreEqual("rgb(255,255,0)", resultMap.Get("text-decoration-color")); |
| 86 | + } |
| 87 | + |
| 88 | + [NUnit.Framework.Test] |
| 89 | + public virtual void ResolveShorthandColorRgbWithOpacityTest() { |
| 90 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 91 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline rgb(255, 255, 0, 0.5)"); |
| 92 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 93 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 94 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 95 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 96 | + NUnit.Framework.Assert.AreEqual("rgb(255,255,0,0.5)", resultMap.Get("text-decoration-color")); |
| 97 | + } |
| 98 | + |
| 99 | + [NUnit.Framework.Test] |
| 100 | + public virtual void ResolveShorthandColorHslTest() { |
| 101 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 102 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline hsl(300, 76%, 72%)"); |
| 103 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 104 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 105 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 106 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 107 | + NUnit.Framework.Assert.AreEqual("hsl(300,76%,72%)", resultMap.Get("text-decoration-color")); |
| 108 | + } |
| 109 | + |
| 110 | + [NUnit.Framework.Test] |
| 111 | + public virtual void ResolveShorthandColorHexTest() { |
| 112 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 113 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline #DDAA55"); |
| 114 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 115 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 116 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 117 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-style")); |
| 118 | + NUnit.Framework.Assert.AreEqual("#ddaa55", resultMap.Get("text-decoration-color")); |
| 119 | + } |
| 120 | + |
| 121 | + [NUnit.Framework.Test] |
| 122 | + public virtual void ResolveShorthandStyleOnePropertyTest() { |
| 123 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 124 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline wavy"); |
| 125 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 126 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 127 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 128 | + NUnit.Framework.Assert.AreEqual("wavy", resultMap.Get("text-decoration-style")); |
| 129 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 130 | + } |
| 131 | + |
| 132 | + [NUnit.Framework.Test] |
| 133 | + public virtual void ResolveShorthandStyleTwoPropertiesTest() { |
| 134 | + TextDecorationShorthandResolver resolver = new TextDecorationShorthandResolver(); |
| 135 | + IList<CssDeclaration> result = resolver.ResolveShorthand("underline wavy dotted"); |
| 136 | + IDictionary<String, String> resultMap = ConvertCssDeclarationsToMap(result); |
| 137 | + NUnit.Framework.Assert.AreEqual(3, resultMap.Count); |
| 138 | + NUnit.Framework.Assert.AreEqual("underline", resultMap.Get("text-decoration-line")); |
| 139 | + NUnit.Framework.Assert.AreEqual("dotted", resultMap.Get("text-decoration-style")); |
| 140 | + NUnit.Framework.Assert.AreEqual("initial", resultMap.Get("text-decoration-color")); |
| 141 | + } |
| 142 | + |
| 143 | + private IDictionary<String, String> ConvertCssDeclarationsToMap(IList<CssDeclaration> declarations) { |
| 144 | + IDictionary<String, String> result = new Dictionary<String, String>(); |
| 145 | + foreach (CssDeclaration decl in declarations) { |
| 146 | + result.Put(decl.GetProperty(), decl.GetExpression()); |
| 147 | + } |
| 148 | + return result; |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments