public void Porownanie() { Diff diff = new Diff("<xml><a>test</a></xml>", "<xml><a>test2</a></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.ROZNE_WARTOSCI_WEZLA); diff = new Diff("<xml><a b=\"1\"/></xml>","<xml><a b=\"1\" c=\"1\"/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.ZBEDNY_ATRYBUT); diff = new Diff("<xml><a b=\"1\" c=\"1\"/></xml>", "<xml><a b=\"1\"/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.BRAKUJACY_ATRYBUT); diff = new Diff("<xml><a b=\"1\"/></xml>", "<xml><a b=\"2\"/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.ROZNE_WARTOSCI_ATRYBUTU); diff = new Diff("<xml></xml>", "<xml><a b=\"1\"/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.ZBEDNY_WEZEL); diff = new Diff("<xml><a b=\"1\"/></xml>", "<xml></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.BRAKUJACY_WEZEL); diff = new Diff("<xml><element><a b=\"1\"/></element></xml>", "<xml><a b=\"1\"/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 2); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.PRZENIESIONY_WEZEL); diff = new Diff("<lower:aaa xmlns:lower=\"http://zvon.org/lowercase\" />", "<lower:aaa xmlns:lower=\"http://zvon.org/lowercase2\" />", 0, true, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 3); Assert.AreEqual(diff.Roznice()[1].TypProblemu, TYP_ROZNICY.ROZNE_PRZESTRZENIE_NAZW); diff = new Diff("<xml><a></xml>", "<xml><a/></xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); Assert.AreEqual(diff.Roznice()[0].TypProblemu, TYP_ROZNICY.BLEDNY_XML); }
public void Informacje() { Diff diff = new Diff("<xml>\n<a>test</a>\n</xml>", "<xml>\n\n<a>test2</a>\n</xml>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice()[0].ZrodPozycja.LineNumber, 2); Assert.AreEqual(diff.Roznice()[0].DocPozycja.LineNumber, 3); Assert.IsTrue(diff.Roznice()[0].ZrodPozycja.HasLineInfo()); Assert.AreEqual(diff.Roznice()[0].DocPozycja.LineNumber, 3); Assert.AreEqual(diff.Roznice()[0].PozycjaZrod, "2"); Assert.AreEqual(diff.Roznice()[0].PozycjaDoc, "3"); Assert.AreEqual(diff.Roznice()[0].OpisProblemu, "Rożne wartości tekstowe węzłów"); Assert.IsTrue(diff.Roznice()[0].Glowna); }
public void PorownanieTest() { Diff diff = new Diff("<a/>", "<a/>", 33, false, true); XElement element1 = new XElement("Root"); XElement element2 = new XElement("Root"); Assert.AreEqual(Compare.Porownanie(element1, element2), 150); element1 = new XElement("Root"); element2 = new XElement("Root1"); Assert.AreEqual(Compare.Porownanie(element1, element2), 120); element1 = new XElement("Root", new XAttribute("Att1", "Some text"), new XAttribute("Att2", "Some text") ); element2 = new XElement("Root", new XAttribute("Att1", "Some text"), new XAttribute("Att2", "Some text") ); Assert.AreEqual(Compare.Porownanie(element1, element2), 190); element1 = new XElement("Root"); element2 = new XElement("Root", new XAttribute("Att2", "Some text") ); Assert.AreEqual(Compare.Porownanie(element1, element2), 150); element1 = new XElement("Root", new XAttribute("Att1", "Some text") ); element2 = new XElement("Root", new XAttribute("Ysaz", "Some text") ); Assert.AreEqual(Compare.Porownanie(element1, element2), 150); element1 = new XElement("Root", new XAttribute("Att1", "Some") ); element2 = new XElement("Root", new XAttribute("Att1", "text") ); Assert.AreEqual(Compare.Porownanie(element1, element2), 160); }
public void Roznice() { Diff diff = new Diff("<a/>", "<a/>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 0); diff = new Diff("<a><b></a>", "<a><c/></a>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); diff = new Diff("<a><b/></a>", "<a><c/></a>", 0, false, true); diff.Porownuj(); Assert.AreEqual(diff.Roznice().Count, 1); }
public void NazwaElementuTest() { Diff diff = new Diff("<a/>", "<a/>", 33, false, true); XElement root = new XElement("Root"); XAttribute atrybut = new XAttribute("a", "wartosc"); Assert.AreEqual(Compare.NazwaElementu(root), "Root"); Assert.AreEqual(Compare.NazwaElementu(atrybut), "a"); XNamespace aw = "http://www.test.com"; root = new XElement(aw + "Root"); atrybut = new XAttribute(aw + "a", "wartosc"); Assert.AreEqual(Compare.NazwaElementu(root), "Root"); Assert.AreEqual(Compare.NazwaElementu(atrybut), "a"); diff=new Diff("<a/>", "<a/>", 33, true, true); root = new XElement(aw + "Root"); atrybut = new XAttribute(aw + "a", "wartosc"); Assert.AreEqual(Compare.NazwaElementu(root), "{http://www.test.com}Root"); Assert.AreEqual(Compare.NazwaElementu(atrybut), "{http://www.test.com}a"); }
/// <summary> /// Wyczyszczenie zawartości edytorów /// </summary> private void Wyczysc() { porownanie = null; ProblemyGrid.ItemsSource = null; foreach(IVisualLineTransformer transformer in colorizer) { LewyKod.TextArea.TextView.LineTransformers.Remove(transformer); PrawyKod.TextArea.TextView.LineTransformers.Remove(transformer); } colorizer.Clear(); }
/// <summary> /// Zdarzenie porównujące zawartości 2 edytorów /// </summary> private void Porownaj_Click(object sender, RoutedEventArgs e) { if (LewyKod.Text == "" || PrawyKod.Text == "") { MessageBox.Show("Nie ma co porównywać", "Brak zawartości", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (Przestrzenie.IsChecked.HasValue) { Wyczysc(); int podobiesntwo = (int)PodobSlider.Value; porownanie = new Diff(LewyKod.Text, PrawyKod.Text,podobiesntwo, Przestrzenie.IsChecked.Value, IgnorujNazwy.IsChecked.Value); porownanie.Porownuj(); PrezentujDane(); Powiadomienie(); index = -1; } }