[Debtags-commits] [svn] r2074 - in tagcoll/2.0: . tagcoll tagcoll/stream

Enrico Zini enrico at alioth.debian.org
Fri Nov 17 15:42:23 CET 2006


Author: enrico
Date: Fri Nov 17 15:42:23 2006
New Revision: 2074

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/TextFormat.cc
   tagcoll/2.0/tagcoll/TextFormat.h
   tagcoll/2.0/tagcoll/patch-tut.cc
   tagcoll/2.0/tagcoll/stream/patcher-tut.cc
Log:
 r3644 at viaza:  enrico | 2006-11-17 15:34:47 +0100
 Added test cases to catch a couple of problems I just spotted in tagcoll diff


Modified: tagcoll/2.0/tagcoll/TextFormat.cc
==============================================================================
--- tagcoll/2.0/tagcoll/TextFormat.cc	(original)
+++ tagcoll/2.0/tagcoll/TextFormat.cc	Fri Nov 17 15:42:23 2006
@@ -38,7 +38,7 @@
 // element: \s*[^ \t,:]\s*([.:])\s*
 // or
 // element: \s*[^ \t,:].*?[^ \t,:]\s*([.:])\s+
-int parseElement(input::Input& in, string& item) throw (tagcoll::exception::Parser)
+int parseElement(input::Input& in, string& item)
 {
 	item = string();
 	string sep;

Modified: tagcoll/2.0/tagcoll/TextFormat.h
==============================================================================
--- tagcoll/2.0/tagcoll/TextFormat.h	(original)
+++ tagcoll/2.0/tagcoll/TextFormat.h	Fri Nov 17 15:42:23 2006
@@ -91,7 +91,7 @@
  *   \li ':'
  *   \li ','
  */
-int parseElement(input::Input& in, std::string& item) throw (tagcoll::exception::Parser);
+int parseElement(input::Input& in, std::string& item);
 
 
 /**

Modified: tagcoll/2.0/tagcoll/patch-tut.cc
==============================================================================
--- tagcoll/2.0/tagcoll/patch-tut.cc	(original)
+++ tagcoll/2.0/tagcoll/patch-tut.cc	Fri Nov 17 15:42:23 2006
@@ -234,6 +234,56 @@
 	ensure_equals(*i->second.added.begin(), "pizza");
 }
 
+// Test diffing collections
+template<> template<>
+void to::test<6>()
+{
+	string in_coll1(
+			"a: b, c\n"
+			"b: a\n"
+			);
+	string in_coll2(
+			"a: d, c\n"
+			"c: a\n"
+			);
+	coll::Simple<string, string> coll1;
+	coll::Simple<string, string> coll2;
+	parseCollection(in_coll1, inserter(coll1));
+	parseCollection(in_coll2, inserter(coll2));
+
+	PatchList<string, string> patches;
+	patches.addPatch(coll1, coll2);
+
+	// Replacing items should work
+	PatchList<string, string>::const_iterator i = patches.begin();
+	ensure(i != patches.end());
+	ensure_equals(i->first, string("a"));
+	ensure_equals(i->second.added.size(), 1u);
+	ensure_equals(*i->second.added.begin(), string("d"));
+	ensure_equals(i->second.removed.size(), 1u);
+	ensure_equals(*i->second.removed.begin(), string("b"));
+
+	// Removing items should work
+	++i;
+	ensure(i != patches.end());
+	ensure_equals(i->first, string("b"));
+	ensure(i->second.added.empty());
+	ensure_equals(i->second.removed.size(), 1u);
+	ensure_equals(*i->second.removed.begin(), string("a"));
+
+	// Adding items should work
+	++i;
+	ensure(i != patches.end());
+	ensure_equals(i->first, string("c"));
+	ensure(i->second.removed.empty());
+	ensure_equals(i->second.added.size(), 1u);
+	ensure_equals(*i->second.added.begin(), string("a"));
+
+	++i;
+	ensure(i == patches.end());
+}
+
+
 }
 
 #include <tagcoll/TextFormat.tcc>

Modified: tagcoll/2.0/tagcoll/stream/patcher-tut.cc
==============================================================================
--- tagcoll/2.0/tagcoll/stream/patcher-tut.cc	(original)
+++ tagcoll/2.0/tagcoll/stream/patcher-tut.cc	Fri Nov 17 15:42:23 2006
@@ -32,9 +32,39 @@
 };
 TESTGRP(tagcoll_stream_patcher);
 
+// Test simple collection patching
 template<> template<>
 void to::test<1>()
 {
+	string input_coll("a: b\n");
+	string output_coll("a: c\n");
+	input::String patch("a: +c, -b");
+	PatchList<string, string> patches = textformat::parsePatch(patch);
+	coll::Simple<string, string> result;
+	parseCollection(input_coll, stream::patcher(patches, inserter(result)));
+	coll::Simple<string, string> reference;
+	parseCollection(output_coll, inserter(reference));
+	ensure_coll_equals(reference, result);
+}
+
+// Test adding new items through patching
+template<> template<>
+void to::test<2>()
+{
+	string input_coll("a: b\n");
+	string output_coll("a: b\nb: c\n");
+	input::String patch("b: +c, -b");
+	PatchList<string, string> patches = textformat::parsePatch(patch);
+	coll::Simple<string, string> result;
+	parseCollection(input_coll, stream::patcher(patches, inserter(result)));
+	coll::Simple<string, string> reference;
+	parseCollection(output_coll, inserter(reference));
+	ensure_coll_equals(reference, result);
+}
+
+template<> template<>
+void to::test<3>()
+{
 	string input_coll(
 			"a: b, c\n"
 			"b:\n"



More information about the Debtags-commits mailing list