public void Empty_Extension_With_Space_Should_Be_Parsed() { var ni = new NullLineInfo(); var parsed = XamlMarkupExtensionParser.Parse(ni, "{Binding }", n => new XamlIlAstXmlTypeReference(ni, "", n)); Helpers.StructDiff(parsed, new XamlIlAstObjectNode(new NullLineInfo(), new XamlIlAstXmlTypeReference(ni, "", "Binding"))); }
public void Parser_Should_Handle_Ignorable_Content(bool map) { var root = XDocumentXamlParser.Parse(@" <Root xmlns='rootns' xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' mc:Ignorable='d d2' xmlns:d='test' xmlns:d2='test2' d:DataContext='123' d2:Lalala='321'> <d:DesignWidth>test</d:DesignWidth> </Root> ", map ? new Dictionary <string, string>() { ["test"] = "mapped" } : null); var ni = new NullLineInfo(); var rootType = new XamlAstXmlTypeReference(ni, "rootns", "Root"); if (map) { Helpers.StructDiff(root.Root, new XamlAstObjectNode(ni, rootType) { Children = { new XamlAstXmlDirective(ni, "mapped", "DataContext", new[] { new XamlAstTextNode(ni, "123", true), }), new XamlAstTextNode(ni, "\n "), new XamlAstObjectNode(ni, new XamlAstXmlTypeReference(ni, "mapped", "DesignWidth")) { Children = { new XamlAstTextNode(ni, "test") } }, new XamlAstTextNode(ni, "\n") } }); } else { Helpers.StructDiff(root.Root, new XamlAstObjectNode(ni, rootType) { Children = { new XamlAstTextNode(ni, "\n ") } }); } }
public void Parser_Should_Be_Able_To_Parse_A_Simple_Tree() { var root = XDocumentXamlIlParser.Parse( @" <Root xmlns='rootns' xmlns:t='testns' xmlns:d='directive' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Child Ext='{Extension 123, 321, Prop=test, Prop2=test2, Prop3={Extension}, Prop4=test3}' Other.Prop='{}Not extension' Prop1='123' Root.AttachedProp='AttachedValue' t:Namespaced.AttachedProp='AttachedValue' d:Directive='DirectiveValue' d:DirectiveExt='{Extension 123}'> <t:SubChild Prop='321' Root.AttachedProp='AttachedValue'/> <Child.DottedProp>DottedValue</Child.DottedProp> <Root.AttachedDottedProp>AttachedValue</Root.AttachedDottedProp> <Child.NodeListProp> <SubChild/> <SubChild/> </Child.NodeListProp> </Child> <GenericType x:TypeArguments='Child,t:NamespacedGeneric(Child,GenericType ( Child, t:Namespaced) )'/> </Root>"); var ni = new NullLineInfo(); var rootType = new XamlIlAstXmlTypeReference(ni, "rootns", "Root"); var childType = new XamlIlAstXmlTypeReference(ni, "rootns", "Child"); var subChildType = new XamlIlAstXmlTypeReference(ni, "rootns", "SubChild"); var nsSubChildType = new XamlIlAstXmlTypeReference(ni, "testns", "SubChild"); var namespacedType = new XamlIlAstXmlTypeReference(ni, "testns", "Namespaced"); var extensionType = new XamlIlAstXmlTypeReference(ni, "rootns", "Extension") { IsMarkupExtension = true }; var other = new XamlIlDocument { NamespaceAliases = new Dictionary <string, string> { [""] = "rootns", ["t"] = "testns", ["d"] = "directive", ["x"] = "http://schemas.microsoft.com/winfx/2006/xaml" }, Root = new XamlIlAstObjectNode(ni, rootType) { Children = { // <Child new XamlIlAstObjectNode(ni, childType) { Children = { // Ext='{Extension 123, 321, Prop=test, Prop2=test2}' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, childType, "Ext", childType), new XamlIlAstObjectNode(ni, extensionType) { Arguments = { new XamlIlAstTextNode(ni, "123"), new XamlIlAstTextNode(ni, "321"), }, Children = { new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, extensionType, "Prop", extensionType), new XamlIlAstTextNode(ni, "test")), new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, extensionType, "Prop2", extensionType), new XamlIlAstTextNode(ni, "test2")), new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, extensionType, "Prop3", extensionType), new XamlIlAstObjectNode(ni, extensionType)), new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, extensionType, "Prop4", extensionType), new XamlIlAstTextNode(ni, "test3")), } }), //Other.Prop='{}Not extension' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, new XamlIlAstXmlTypeReference(ni, "rootns", "Other"), "Prop", childType), new XamlIlAstTextNode(ni, "Not extension")), // Prop1='123' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, childType, "Prop1", childType), new XamlIlAstTextNode(ni, "123")), // Root.AttachedProp='AttachedValue' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, rootType, "AttachedProp", childType), new XamlIlAstTextNode(ni, "AttachedValue")), //t:Namespaced.AttachedProp='AttachedValue' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, namespacedType, "AttachedProp", childType), new XamlIlAstTextNode(ni, "AttachedValue")), //d:Directive='DirectiveValue'> new XamlIlAstXmlDirective(ni, "directive", "Directive", new[] { new XamlIlAstTextNode(ni, "DirectiveValue") }), //d:DirectiveExt='{Extension 123}'> new XamlIlAstXmlDirective(ni, "directive", "DirectiveExt", new[] { new XamlIlAstObjectNode(ni, extensionType) { Arguments = { new XamlIlAstTextNode(ni, "123"), } } }), // <t:SubChild Prop='321' Root.AttachedProp='AttachedValue'/> new XamlIlAstObjectNode(ni, nsSubChildType) { Children = { new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, nsSubChildType, "Prop", nsSubChildType), new XamlIlAstTextNode(ni, "321")), // Root.AttachedProp='AttachedValue' new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, rootType, "AttachedProp", nsSubChildType), new XamlIlAstTextNode(ni, "AttachedValue")), } }, //<Child.DottedProp>DottedValue</Child.DottedProp> new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, childType, "DottedProp", childType), new[] { new XamlIlAstTextNode(ni, "DottedValue") }), // <Root.AttachedDottedProp>AttachedValue</Root.AttachedDottedProp> new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, rootType, "AttachedDottedProp", childType), new[] { new XamlIlAstTextNode(ni, "AttachedValue") }), //<Child.NodeListProp> new XamlIlAstXamlPropertyValueNode(ni, new XamlIlAstNamePropertyReference(ni, childType, "NodeListProp", childType), new[] { // <SubChild/> new XamlIlAstObjectNode(ni, subChildType), // <SubChild/> new XamlIlAstObjectNode(ni, subChildType), }) } }, //<GenericType x:TypeArguments='Child,t:NamespacedGeneric(Child,GenericType(Child, t:Namespaced))'/> new XamlIlAstObjectNode(ni, new XamlIlAstXmlTypeReference(ni, "rootns", "GenericType", new[] { childType, new XamlIlAstXmlTypeReference(ni, "testns", "NamespacedGeneric", new[] { childType, new XamlIlAstXmlTypeReference(ni, "rootns", "GenericType", new[] { childType, namespacedType }), }), })) } } }; Helpers.StructDiff(root, other); }