|
| 1 | +package com.feathersui.xml; |
| 2 | + |
| 3 | +import utest.Assert; |
| 4 | +import utest.Test; |
| 5 | + |
| 6 | +class TestXmlComponentDeclarationsCoreTypes extends Test { |
| 7 | + public function new() { |
| 8 | + super(); |
| 9 | + } |
| 10 | + |
| 11 | + public function testFloat():Void { |
| 12 | + var instance = XmlComponent.withMarkup( |
| 13 | + // @formatter:off |
| 14 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 15 | + <hx:Declarations> |
| 16 | + <hx:Float id="float">123.4</hx:Float> |
| 17 | + </hx:Declarations> |
| 18 | + </hx:Dynamic>'); |
| 19 | + // @formatter:on |
| 20 | + Assert.equals(123.4, instance.float); |
| 21 | + } |
| 22 | + |
| 23 | + public function testInt():Void { |
| 24 | + var instance = XmlComponent.withMarkup( |
| 25 | + // @formatter:off |
| 26 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 27 | + <hx:Declarations> |
| 28 | + <hx:Int id="int">-123</hx:Int> |
| 29 | + </hx:Declarations> |
| 30 | + </hx:Dynamic>'); |
| 31 | + // @formatter:on |
| 32 | + Assert.equals(-123, instance.int); |
| 33 | + } |
| 34 | + |
| 35 | + public function testUInt():Void { |
| 36 | + var instance = XmlComponent.withMarkup( |
| 37 | + // @formatter:off |
| 38 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 39 | + <hx:Declarations> |
| 40 | + <hx:UInt id="uint">123</hx:UInt> |
| 41 | + </hx:Declarations> |
| 42 | + </hx:Dynamic>'); |
| 43 | + // @formatter:on |
| 44 | + Assert.equals(123, instance.uint); |
| 45 | + } |
| 46 | + |
| 47 | + public function testBoolFalse():Void { |
| 48 | + var instance = XmlComponent.withMarkup( |
| 49 | + // @formatter:off |
| 50 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 51 | + <hx:Declarations> |
| 52 | + <hx:Bool id="bool">false</hx:Bool> |
| 53 | + </hx:Declarations> |
| 54 | + </hx:Dynamic>'); |
| 55 | + // @formatter:on |
| 56 | + Assert.isFalse(instance.bool); |
| 57 | + } |
| 58 | + |
| 59 | + public function testBoolTrue():Void { |
| 60 | + var instance = XmlComponent.withMarkup( |
| 61 | + // @formatter:off |
| 62 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 63 | + <hx:Declarations> |
| 64 | + <hx:Bool id="bool">true</hx:Bool> |
| 65 | + </hx:Declarations> |
| 66 | + </hx:Dynamic>'); |
| 67 | + // @formatter:on |
| 68 | + Assert.isTrue(instance.bool); |
| 69 | + } |
| 70 | + |
| 71 | + public function testString():Void { |
| 72 | + var instance = XmlComponent.withMarkup( |
| 73 | + // @formatter:off |
| 74 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 75 | + <hx:Declarations> |
| 76 | + <hx:String id="string">Hello XML</hx:String> |
| 77 | + </hx:Declarations> |
| 78 | + </hx:Dynamic>'); |
| 79 | + // @formatter:on |
| 80 | + Assert.equals("Hello XML", instance.string); |
| 81 | + } |
| 82 | + |
| 83 | + public function testArrayEmpty():Void { |
| 84 | + var instance = XmlComponent.withMarkup( |
| 85 | + // @formatter:off |
| 86 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 87 | + <hx:Declarations> |
| 88 | + <hx:Array id="array"></hx:Array> |
| 89 | + </hx:Declarations> |
| 90 | + </hx:Dynamic>'); |
| 91 | + // @formatter:on |
| 92 | + Assert.equals(0, instance.array.length); |
| 93 | + } |
| 94 | + |
| 95 | + public function testArrayWithItems():Void { |
| 96 | + var instance = XmlComponent.withMarkup( |
| 97 | + // @formatter:off |
| 98 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 99 | + <hx:Declarations> |
| 100 | + <hx:Array id="array"> |
| 101 | + <hx:String>a</hx:String> |
| 102 | + <hx:String>b</hx:String> |
| 103 | + <hx:String>c</hx:String> |
| 104 | + </hx:Array> |
| 105 | + </hx:Declarations> |
| 106 | + </hx:Dynamic>'); |
| 107 | + // @formatter:on |
| 108 | + Assert.equals(3, instance.array.length); |
| 109 | + Assert.equals("a", instance.array[0]); |
| 110 | + Assert.equals("b", instance.array[1]); |
| 111 | + Assert.equals("c", instance.array[2]); |
| 112 | + } |
| 113 | + |
| 114 | + public function testDynamicNoFields():Void { |
| 115 | + var instance = XmlComponent.withMarkup( |
| 116 | + // @formatter:off |
| 117 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 118 | + <hx:Declarations> |
| 119 | + <hx:Dynamic id="dyn"></hx:Dynamic> |
| 120 | + </hx:Declarations> |
| 121 | + </hx:Dynamic>'); |
| 122 | + // @formatter:on |
| 123 | + Assert.equals(0, Reflect.fields(instance.dyn).length); |
| 124 | + } |
| 125 | + |
| 126 | + public function testDynamicAttributeProperty():Void { |
| 127 | + var instance = XmlComponent.withMarkup( |
| 128 | + // @formatter:off |
| 129 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 130 | + <hx:Declarations> |
| 131 | + <hx:Dynamic id="dyn" value="123.4"></hx:Dynamic> |
| 132 | + </hx:Declarations> |
| 133 | + </hx:Dynamic>'); |
| 134 | + // @formatter:on |
| 135 | + Assert.equals(123.4, instance.dyn.value); |
| 136 | + } |
| 137 | + |
| 138 | + public function testDynamicElementProperty():Void { |
| 139 | + var instance = XmlComponent.withMarkup( |
| 140 | + // @formatter:off |
| 141 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 142 | + <hx:Declarations> |
| 143 | + <hx:Dynamic id="dyn"> |
| 144 | + <hx:value>123.4</hx:value> |
| 145 | + </hx:Dynamic> |
| 146 | + </hx:Declarations> |
| 147 | + </hx:Dynamic>'); |
| 148 | + // @formatter:on |
| 149 | + Assert.equals(123.4, instance.dyn.value); |
| 150 | + } |
| 151 | + |
| 152 | + public function testDynamicAttributeAndElementProperties():Void { |
| 153 | + var instance = XmlComponent.withMarkup( |
| 154 | + // @formatter:off |
| 155 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 156 | + <hx:Declarations> |
| 157 | + <hx:Dynamic id="dyn" value1="123.4"> |
| 158 | + <hx:value2>456.7</hx:value2> |
| 159 | + </hx:Dynamic> |
| 160 | + </hx:Declarations> |
| 161 | + </hx:Dynamic>'); |
| 162 | + // @formatter:on |
| 163 | + Assert.equals(123.4, Reflect.field(instance.dyn, "value1")); |
| 164 | + Assert.equals(456.7, Reflect.field(instance.dyn, "value2")); |
| 165 | + } |
| 166 | + |
| 167 | + public function testAnyNoFields():Void { |
| 168 | + var instance = XmlComponent.withMarkup( |
| 169 | + // @formatter:off |
| 170 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 171 | + <hx:Declarations> |
| 172 | + <hx:Any id="any"></hx:Any> |
| 173 | + </hx:Declarations> |
| 174 | + </hx:Dynamic>'); |
| 175 | + // @formatter:on |
| 176 | + Assert.equals(0, Reflect.fields(instance.any).length); |
| 177 | + } |
| 178 | + |
| 179 | + public function testAnyAttributeProperty():Void { |
| 180 | + var instance = XmlComponent.withMarkup( |
| 181 | + // @formatter:off |
| 182 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 183 | + <hx:Declarations> |
| 184 | + <hx:Any id="any" value="123.4"></hx:Any> |
| 185 | + </hx:Declarations> |
| 186 | + </hx:Dynamic>'); |
| 187 | + // @formatter:on |
| 188 | + Assert.equals(123.4, Reflect.field(instance.any, "value")); |
| 189 | + } |
| 190 | + |
| 191 | + public function testAnyElementProperty():Void { |
| 192 | + var instance = XmlComponent.withMarkup( |
| 193 | + // @formatter:off |
| 194 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 195 | + <hx:Declarations> |
| 196 | + <hx:Any id="any"> |
| 197 | + <hx:value>123.4</hx:value> |
| 198 | + </hx:Any> |
| 199 | + </hx:Declarations> |
| 200 | + </hx:Dynamic>'); |
| 201 | + // @formatter:on |
| 202 | + Assert.equals(123.4, Reflect.field(instance.any, "value")); |
| 203 | + } |
| 204 | + |
| 205 | + public function testAnyAttributeAndElementProperties():Void { |
| 206 | + var instance = XmlComponent.withMarkup( |
| 207 | + // @formatter:off |
| 208 | + '<hx:Dynamic xmlns:hx="http://ns.haxe.org/4/xml"> |
| 209 | + <hx:Declarations> |
| 210 | + <hx:Any id="any" value1="123.4"> |
| 211 | + <hx:value2>456.7</hx:value2> |
| 212 | + </hx:Any> |
| 213 | + </hx:Declarations> |
| 214 | + </hx:Dynamic>'); |
| 215 | + // @formatter:on |
| 216 | + Assert.equals(123.4, Reflect.field(instance.any, "value1")); |
| 217 | + Assert.equals(456.7, Reflect.field(instance.any, "value2")); |
| 218 | + } |
| 219 | +} |
0 commit comments