protected override bool OnTryApply(UxDocument document) { if (!NodePath.TryFind(document, out UxElement node)) { return(false); } node.IsEmpty = IsEmpty; return(true); }
static UxDocument ParseAndExpandUxDocument(string uxText) { var doc = UxDocument.Parse(uxText); // ReSharper disable once UnusedVariable foreach (var node in doc.Root.DescendantNodesAndSelf()) { // Do nothing here } return(doc); }
public void SourceOffset_is_correct_for_all_nodes_in_example(string uxContent) { var doc = UxDocument.Parse(uxContent); foreach (var node in doc.DescendantNodes()) { var expected = node.Syntax.ToString(); var actual = uxContent.Substring(node.SourceOffset, node.Syntax.FullSpan); Assert.That(node.FullSpan, Is.EqualTo(expected.Length)); Assert.That(actual, Is.EqualTo(expected)); } }
public void Merge_then_verify_equality_and_events(string before, string after) { var source = ParseXml(after); var destination = ParseXml(before); var patchDestination = ParseXml(before); var sourceBefore = source.ToString(); var invertedChanges = new Stack <UxChange>(); destination.Changed += change => { Console.WriteLine( "Got change: {0}", JsonConvert.SerializeObject( change, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, Converters = { new SyntaxConverter() } })); Assert.That(change.TryApply(patchDestination), Is.True, "Could not apply change to patch destination"); Assert.That(patchDestination.Syntax, Is.EqualTo(destination.Syntax)); invertedChanges.Push(change.Invert()); }; Console.WriteLine("Destination:\r\n{0}\r\nSource:\r\n{1}", destination, source); destination.Merge(source); Console.WriteLine("Destination:\r\n{0}\r\nSource:\r\n{1}", destination, source); Assert.That(source.ToString(), Is.EqualTo(sourceBefore)); Assert.That(destination.ToString(), Is.EqualTo(source.ToString())); Assert.That(source.DeepEquals(destination), Is.True); Assert.That( patchDestination.Syntax, Is.EqualTo(destination.Syntax), "Change stream did not recreate \"after\" syntax"); var reversed = UxDocument.FromSyntax(patchDestination.Syntax); while (invertedChanges.Count > 0) { invertedChanges.Pop().TryApply(reversed); } Assert.That( reversed.Syntax, Is.EqualTo(ParseXml(before).Syntax), "Inverted change stream did not recreate \"before\" syntax"); //Assert.That(actualEventCount, Is.EqualTo(expectedEvents.Count), // "Fewer events than expected emitted by Changed event:\r\n" + // string.Concat(expectedEvents.Select(x => string.Format(" {0}\r\n", x)))); }
public void Mutate(UxDocument doc) { var element = doc.Root; var descendants = element.Descendants().ToList(); if ((descendants.Count < _maUxElements / 2 || _rng.NextDouble() > descendants.Count / (double)_maUxElements) && descendants.Count < _maUxElements) { AddRandomItem(element, descendants); } else { RandomItem(descendants).Remove(); } }
public void Qualified_names_are_correct() { var doc = UxDocument.Parse( "<Panel ux:Class=\"CustomPanel\" Color=\"Black\" xmlns:foo=\"foo://\"><ux:Poo /><foo:Bar /></Panel>"); var el = doc.Root; Assert.That(el.Attributes[0].QualifiedName, Is.EqualTo("{http://schemas.fusetools.com/ux}Class")); Assert.That(el.Attributes[1].QualifiedName, Is.EqualTo("Color")); Assert.That( el.QualifiedName, Is.EqualTo( "{Fuse, Fuse.Reactive, Fuse.Selection, Fuse.Animations, Fuse.Drawing, Fuse.Entities, Fuse.Controls, Fuse.Layouts, Fuse.Elements, Fuse.Effects, Fuse.Triggers, Fuse.Navigation, Fuse.Triggers.Actions, Fuse.Gestures, Fuse.Resources, Fuse.Native, Fuse.Physics, Fuse.Vibration, Fuse.Motion, Fuse.Testing, Uno.UX}Panel")); Assert.That(el.Elements.ElementAt(0).QualifiedName, Is.EqualTo("{http://schemas.fusetools.com/ux}Poo")); Assert.That(el.Elements.ElementAt(1).QualifiedName, Is.EqualTo("{foo://}Bar")); }
static UxDocument ParseDoc(string ux) { var doc = UxDocument.Parse(ux); return(doc); }
static UxDocument ParseXml(string xml) { return(UxDocument.Parse(xml)); }