public void OnEnable(MemberItem member) { if (m_IsDummy) { Member = member; DummyModel = member.LoadDoc(TextOrig, Language, false, false); if (Language == LanguageUtil.ELanguage.English) { DummyModel.EnforcePunctuation(); } DummyModel.SanitizeForEditing(); } else { Member = member; member.LoadDoc(Language); member.LoadDoc(TextCurrent, Language, false); if (Language == LanguageUtil.ELanguage.English) { Model.EnforcePunctuation(); } Model.SanitizeForEditing(); if (Diff == null) { Diff = new StringDiff(); } Diff.Compare(TextOrig, TextCurrent); } }
private static string RenderRows(Template rowTemplate, List <Line> lines, string indentBegin, string indentEnd) { string output = ""; foreach (var line in lines) { string left = XmlEscape(line.Left); string right = XmlEscape(line.Right); if (line.EntryType == EntryType.Changed) { List <StringDiff> streaks = StringDiff.FindDifferences(left, right); left = RenderStreaks(streaks, StreakType.Unchanged, StreakType.Removed); right = RenderStreaks(streaks, StreakType.Unchanged, StreakType.Added); } output += rowTemplate.Render(new { LineType = line.EntryType.ToString(), LineTypeLc = line.EntryType.ToString().ToLower(), IndentBegin = indentBegin, IndentEnd = indentEnd, Left = left, Right = right, }); } return(output); }
public void Load() { if (m_IsDummy) { return; } if (Member == null) { Debug.LogError("Cannot load member since it is null."); return; } Member.LoadDoc(Language); if (Language == LanguageUtil.ELanguage.English) { Model.EnforcePunctuation(); } Model.SanitizeForEditing(); TextOrig = Model.ToString(); TextCurrent = TextOrig; if (Diff == null) { Diff = new StringDiff(); } Diff.Compare(TextOrig, TextCurrent); Dirty = false; DirtyAutoChanges = false; }
public void Format_SingleLineTextWithInlineAtributeAndCommentNested_FormatsWell() { // Arrange var source = @"<Element1> <Element2 Attr=""Foo""> Some text<!-- Wierd Comment --> </Element2> </Element1>"; var expected = @"<Element1> <Element2 Attr=""Foo""> Some text <!-- Wierd Comment --> </Element2> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_SingleLineTextWithNonInlineAtributeNested_TextPreserved() { // Arrange var source = @"<Element1> <Element2 Attr1=""Foo1"" Attr2=""Foo1""> Some text </Element2> </Element1>"; var expected = @"<Element1> <Element2 Attr1=""Foo1"" Attr2=""Foo1""> Some text </Element2> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_MultilineCommentBetweenElements_CommentPreserved() { // Arrange var source = @"<Element1> <!-- A multiline comment A multiline comment A multiline comment --> </Element1>"; var expected = @"<Element1> <!-- A multiline comment A multiline comment A multiline comment --> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_MultiLineCommentAtStart_Written() { // Arrange var source = @" <!--Start Comment Start Comment1 Start Comment Start Comment--> <Element1 />"; var expected = @"<!-- Start Comment Start Comment1 Start Comment Start Comment --> <Element1 />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_WhiteSpaceBetweenElements_OneBlankPreserved() { // Arrange var source = @"<Element1> <Element2 /> </Element1>"; var expected = @"<Element1> <Element2 /> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void EditDistance() { var diff = new StringDiff("intention", "execution"); int dist = diff.EditDistance(); Assert.AreEqual(5, dist); }
public void Format_AttributesWithOrderInstructionIncludingPredefined_OrdersAsPerInstruction() { // Arrange var source = @"<!-- xamlr:order Z2, X1, Grid.Row, x:Name, Y3 --> <Element1 xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" x:Name=""n"" Grid.Row=""g"" A1=""a"" Z2=""z"" Y3=""y"" X1=""x"" />"; var expected = @"<!-- xamlr:order Z2, X1, Grid.Row, x:Name, Y3 --> <Element1 Z2=""z"" X1=""x"" Grid.Row=""g"" x:Name=""n"" Y3=""y"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" A1=""a"" />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void FirstElement() { var diff = new StringDiff("qabc", "xabc"); var result = diff.Compute(); result.Print(); }
public void Format_MultilineText_TextPreserved() { // Arrange var source = @"<Element1> Some text Some text Some text </Element1>"; var expected = @"<Element1> Some text Some text Some text </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_Text_SpacePreserved() { // Arrange var source = @"<Element1 xml:space=""preserve""> Moo foo Mba SDFSD slb sdlf </Element1>"; var expected = @"<Element1 xml:space=""preserve""> Moo foo Mba SDFSD slb sdlf </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_NestedDefault_NormalFormattingResumed() { // Arrange var source = @"<Element1 xml:space=""preserve""> <Element2 xml:space=""default""> Foo bar </Element2> Moo X BAR </Element1>"; var expected = @"<Element1 xml:space=""preserve""> <Element2 xml:space=""default"">Foo bar</Element2> Moo X BAR </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_SignificantWhiteSpaceContainsSingleLineComment_SpacePreserved() { // Arrange var source = @"<Element1 xml:space=""preserve""> <!-- I'm a lovely comment --> </Element1>"; var expected = @"<Element1 xml:space=""preserve""> <!-- I'm a lovely comment --> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_ComplexMarkupExtension1_Formats() { // Arrange var source = @"<Element1 Markup=""{Binding Path=Foo, ElementName={Binding Path=DataContext.Girrafe, Converter={StaticResource GirrafeConverter}}, Source={StaticResource Items}}"" />"; var expected = @"<Element1 Markup=""{Binding Path=Foo, ElementName={Binding Path=DataContext.Girrafe, Converter={StaticResource GirrafeConverter}}, Source={StaticResource Items}}"" />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_SimpleNested_SpacePreserved() { // Arrange var source = @"<Element1 xml:space=""preserve""> <Element2 A1=""Value1"" A2=""Value2"" /> </Element1>"; var expected = @"<Element1 xml:space=""preserve""> <Element2 A1=""Value1"" A2=""Value2"" /> </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void NoChanges() { var diff = new StringDiff("foo", "foo"); var result = diff.Compute(); Assert.AreEqual(3, result.Changes.Count()); Assert.AreEqual(0, result.Additions); Assert.AreEqual(0, result.Deletions); }
public void DiffCommonPrefix() { var diff = new StringDiff("abcdfghjqz", "abcdefgijkrxyz"); var result = diff.Compute(); result.Print(); Assert.AreEqual(6, result.Additions); Assert.AreEqual(2, result.Deletions); Assert.AreEqual(16, result.Changes.Count()); }
public void DiffBanana() { var diff = new StringDiff("banana", "atana"); // var diff = new StringDiff("atana", "banana"); var result = diff.Compute(); result.Print(); Assert.AreEqual(1, result.Additions); Assert.AreEqual(2, result.Deletions); Assert.AreEqual(7, result.Changes.Count()); }
public void LcsTest() { var diff = new StringDiff("banana", "atana"); string result = diff.LCS(); Assert.AreEqual("aana", result); diff = new StringDiff("abcdfghjqz", "abcdefgijkrxyz"); result = diff.LCS(); Assert.AreEqual("abcdfgjz", result); }
public void Format_OneEmptyElement_Formats() { // Arrange var source = @"<Element1 />"; var expected = @"<Element1 />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_SingleAttribute_SpacesInAttributesAreNotTrimmed() { // Arrange var source = @"<Element1 Attribute="" abc "" />"; var expected = @"<Element1 Attribute="" abc "" />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_IntegrationTest1_FormatsAsExpected() { // Arrange var source = "IntegrationTest1.xaml".GetSource(); var expected = "IntegrationTest1_Formatted.xaml".GetSource(); // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_SingleUnnestedNonEmptyMarkupExtension_FormatsOnOneLine() { // Arrange var source = @"<Element1 Markup=""{Binding Path='Foo'}"" />"; var expected = @"<Element1 Markup=""{Binding Path='Foo'}"" />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_HasXmlPreamble_PreservesPreamble() { // Arrange var source = @"<?xml version=""1.0"" encoding=""utf-8""?><Element1 />"; var expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <Element1 />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_ProcessingInstructionAtStart_Formats() { // Arrange var source = @"<?Mapping ClrNamespace=""Xamlr.Core"" XmlNamespace=""Xamlr""?><Element1 />"; var expected = @"<?Mapping ClrNamespace=""Xamlr.Core"" XmlNamespace=""Xamlr""?> <Element1 />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_WhiteSpaceAtEnd_Trimmed() { // Arrange var source = @"<Element1 /> "; var expected = @"<Element1 />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_TwoAttributes_FormatsOnTwoLines() { // Arrange var source = @"<Element1 Attribute1=""abc"" Attribute2=""def"" />"; var expected = @"<Element1 Attribute1=""abc"" Attribute2=""def"" />"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }
public void Format_DeepNestedDefault_NormalFormattingResumed() { // Arrange var source = @"<Element1 xml:space=""preserve"" Attribute1=""Moo"" Attribute2=""Foo""> <Element2 xml:space=""default"" Attribute1=""Zoo"" Attribute2=""{Binding Path=Height, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=views:MainView}}""> <Element3><Element4> Foo bar </Element4></Element3> </Element2> Moo X BAR </Element1>"; var expected = @"<Element1 xml:space=""preserve"" Attribute1=""Moo"" Attribute2=""Foo""> <Element2 xml:space=""default"" Attribute1=""Zoo"" Attribute2=""{Binding Path=Height, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=views:MainView}}""> <Element3> <Element4>Foo bar</Element4> </Element3> </Element2> Moo X BAR </Element1>"; // Act var actual = source.Format(); // Assert var result = StringDiff.Compare(expected, actual); Assert.IsTrue(result.AreEqual, result.Details); }