2
* Serialize a tagged collection to a text file
4
* Copyright (C) 2003,2004,2005 Enrico Zini <enrico@debian.org>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <tests/test-utils.h>
22
#include <tagcoll/TextFormat.h>
23
#include <tagcoll/input/string.h>
24
#include <tagcoll/stream/sink.h>
25
#include <tagcoll/patch.h>
29
using namespace tagcoll;
30
using namespace tagcoll::tests;
32
struct tagcoll_textformat_shar {
34
TESTGRP(tagcoll_textformat);
43
"d: c::D, e::F, f::g\n"
46
int countItems = 0, countTags = 0;
47
textformat::parse(coll, stream::countingSink(countItems, countTags));
49
ensure_equals(countItems, 4);
50
ensure_equals(countTags, 5);
60
"d: +c::D, -e::F, -f::g\n"
63
PatchList<string, string> plist = textformat::parsePatch(coll);
66
cerr << "Patchlist[" << plist.size() << "]:" << endl;
67
for (PatchList<string, string>::const_iterator i = plist.begin();
68
i != plist.end(); i++)
69
cerr << " " << i->first << ": " <<
70
i->second.added.size() << "x" <<
71
i->second.removed.size() << endl;
74
ensure_equals(plist.size(), 2u);
75
ensure(plist.find("a") != plist.end());
76
ensure(plist.find("b") == plist.end());
77
ensure(plist.find("c") == plist.end());
78
ensure(plist.find("d") != plist.end());
80
PatchList<string, string>::const_iterator i = plist.find("a");
81
ensure_equals(i->second.added.size(), 2u);
82
ensure_equals(i->second.removed.size(), 0u);
85
ensure_equals(i->second.added.size(), 1u);
86
ensure_equals(i->second.removed.size(), 2u);
95
"foo: antani, blinda\n"
96
"bar, foo: antani, blinda\n";
98
FILE* out = fmemopen(buf, 1000, "w");
101
textformat::StdioWriter writer(out);
105
*writer = make_pair(s1, wibble::Empty<string>());
110
*writer = make_pair(s1, s2);
114
*writer = make_pair(s1, s2);
118
s1.insert("foo"); s1.insert("bar");
119
*writer = make_pair(s1, s2);
125
ensure_equals(reference, outstr);
128
template<> template<>
134
"foo: antani, blinda\n"
135
"bar, foo: antani, blinda\n";
138
textformat::OstreamWriter writer(out);
142
*writer = make_pair(s1, wibble::Empty<string>());
147
*writer = make_pair(s1, s2);
151
*writer = make_pair(s1, s2);
155
s1.insert("foo"); s1.insert("bar");
156
*writer = make_pair(s1, s2);
159
ensure_equals(out.str(), reference);
162
template<> template<>
167
PatchList<string, string> patchlist;
168
std::set<string> added; added.insert("add");
169
std::set<string> removed; removed.insert("rm");
170
patchlist.addPatch(Patch<string, string>("test", added, removed));
172
FILE* out = fmemopen(buf, 999, "w");
175
textformat::outputPatch(patchlist, out);
178
ensure(strcmp(buf, "test: +add, -rm\n") == 0);
181
std::string operator()(const std::string& str) { return str + "o"; }
184
out = fmemopen(buf, 999, "w");
188
#warning Enable this test please
189
textformat::outputPatch(oer, oer, patchlist, out);
192
ensure(strcmp(buf, "test: +addo, -rmo\n") == 0);
198
#include <tagcoll/TextFormat.tcc>
199
#include <tagcoll/stream/filters.tcc>
201
// vim:set ts=4 sw=4: