mirror of
https://github.com/jezhiggins/arabica
synced 2024-12-25 21:58:21 +01:00
Properly parameterise PYXWriter and SAX tests on string type
This commit is contained in:
parent
cd99dba691
commit
c37d974e47
2 changed files with 64 additions and 58 deletions
|
@ -18,9 +18,8 @@ class PYXWriter : public XMLFilterImpl<string_type, string_adaptor>
|
||||||
typedef XMLReaderInterface<string_type, string_adaptor> XMLReaderT;
|
typedef XMLReaderInterface<string_type, string_adaptor> XMLReaderT;
|
||||||
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
|
typedef XMLFilterImpl<string_type, string_adaptor> XMLFilterT;
|
||||||
typedef typename XMLFilterT::AttributesT AttributesT;
|
typedef typename XMLFilterT::AttributesT AttributesT;
|
||||||
typedef typename string_type::value_type charT;
|
typedef typename string_adaptor::value_type charT;
|
||||||
typedef typename string_type::traits_type traitsT;
|
typedef std::basic_ostream<charT> ostreamT;
|
||||||
typedef std::basic_ostream<charT, traitsT> ostreamT;
|
|
||||||
typedef Arabica::text::Unicode<charT> UnicodeT;
|
typedef Arabica::text::Unicode<charT> UnicodeT;
|
||||||
private:
|
private:
|
||||||
using XMLFilterT::getParent;
|
using XMLFilterT::getParent;
|
||||||
|
@ -103,7 +102,7 @@ void PYXWriter<string_type, string_adaptor>::processingInstruction(const string_
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
void PYXWriter<string_type, string_adaptor>::escape(const string_type& ch)
|
void PYXWriter<string_type, string_adaptor>::escape(const string_type& ch)
|
||||||
{
|
{
|
||||||
for(typename string_type::const_iterator s = ch.begin(), se = ch.end(); s != se; ++s)
|
for(typename string_adaptor::const_iterator s = string_adaptor::begin(ch), se = string_adaptor::end(ch); s != se; ++s)
|
||||||
if(*s == UnicodeT::LINE_FEED)
|
if(*s == UnicodeT::LINE_FEED)
|
||||||
*stream_ << UnicodeT::BACK_SLASH << UnicodeT::LOWERCASE_N;
|
*stream_ << UnicodeT::BACK_SLASH << UnicodeT::LOWERCASE_N;
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,107 +29,114 @@ class WhitespaceStripperTest : public TestCase
|
||||||
{
|
{
|
||||||
} // setUp
|
} // setUp
|
||||||
|
|
||||||
|
void expect(char const* expected, std::basic_ostringstream<typename string_adaptor::value_type>& result) {
|
||||||
|
assertEquals(
|
||||||
|
expected,
|
||||||
|
string_adaptor::asStdString(string_adaptor::construct(result.str().c_str()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void testNoStrip()
|
void testNoStrip()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, parser);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, parser);
|
||||||
writer.parse(*source("<test><p> Woo baby hooray </p></test>"));
|
writer.parse(*source("<test><p> Woo baby hooray </p></test>"));
|
||||||
assertEquals("(test\n(p\n- Woo baby hooray \n)p\n)test\n", o.str());
|
expect("(test\n(p\n- Woo baby hooray \n)p\n)test\n", o);
|
||||||
} // testNoStrip
|
} // testNoStrip
|
||||||
|
|
||||||
void testStripLeading()
|
void testStripLeading()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::WhitespaceStripper<std::string> stripper(parser);
|
Arabica::SAX::WhitespaceStripper<string_type, string_adaptor> stripper(parser);
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, stripper);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, stripper);
|
||||||
writer.parse(*source("<test><p>Woo</p></test>"));
|
writer.parse(*source("<test><p>Woo</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p> Woo</p></test>"));
|
writer.parse(*source("<test><p> Woo</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p> Woo</p></test>"));
|
writer.parse(*source("<test><p> Woo</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
} // testStripLeading
|
} // testStripLeading
|
||||||
|
|
||||||
void testStripTrailing()
|
void testStripTrailing()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::WhitespaceStripper<std::string> stripper(parser);
|
Arabica::SAX::WhitespaceStripper<string_type, string_adaptor> stripper(parser);
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, stripper);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, stripper);
|
||||||
writer.parse(*source("<test><p>Woo</p></test>"));
|
writer.parse(*source("<test><p>Woo</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo </p></test>"));
|
writer.parse(*source("<test><p>Woo </p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo </p></test>"));
|
writer.parse(*source("<test><p>Woo </p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo\n)p\n)test\n", o);
|
||||||
} // testStripTrailing
|
} // testStripTrailing
|
||||||
|
|
||||||
void testStripMid()
|
void testStripMid()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::WhitespaceStripper<std::string> stripper(parser);
|
Arabica::SAX::WhitespaceStripper<string_type, string_adaptor> stripper(parser);
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, stripper);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, stripper);
|
||||||
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
writer.parse(*source("<test><p>Woo yea</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea\n)p\n)test\n", o);
|
||||||
} // testStripMid
|
} // testStripMid
|
||||||
|
|
||||||
void testStripMid2()
|
void testStripMid2()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::WhitespaceStripper<std::string> stripper(parser);
|
Arabica::SAX::WhitespaceStripper<string_type, string_adaptor> stripper(parser);
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, stripper);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, stripper);
|
||||||
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o);
|
||||||
|
|
||||||
o.str("");
|
o.str(string_adaptor::empty_string());
|
||||||
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
writer.parse(*source("<test><p>Woo yea man</p></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo yea man\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo yea man\n)p\n)test\n", o);
|
||||||
} // testStripMid2
|
} // testStripMid2
|
||||||
|
|
||||||
void testStrip()
|
void testStrip()
|
||||||
{
|
{
|
||||||
std::ostringstream o;
|
std::basic_ostringstream<typename string_adaptor::value_type> o;
|
||||||
Arabica::SAX::XMLReader<std::string> parser;
|
Arabica::SAX::XMLReader<string_type, string_adaptor> parser;
|
||||||
Arabica::SAX::WhitespaceStripper<std::string> stripper(parser);
|
Arabica::SAX::WhitespaceStripper<string_type, string_adaptor> stripper(parser);
|
||||||
Arabica::SAX::PYXWriter<std::string> writer(o, stripper);
|
Arabica::SAX::PYXWriter<string_type, string_adaptor> writer(o, stripper);
|
||||||
writer.parse(*source("<test><p> Woo baby hooray </p><!-- yo mama --></test>"));
|
writer.parse(*source("<test><p> Woo baby hooray </p><!-- yo mama --></test>"));
|
||||||
assertEquals("(test\n(p\n-Woo baby hooray\n)p\n)test\n", o.str());
|
expect("(test\n(p\n-Woo baby hooray\n)p\n)test\n", o);
|
||||||
} // testStrip
|
} // testStrip
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Arabica::SAX::InputSource<std::string> > source(const std::string& str)
|
std::unique_ptr<Arabica::SAX::InputSource<string_type, string_adaptor> > source(const std::string& str)
|
||||||
{
|
{
|
||||||
std::unique_ptr<std::iostream> ss(new std::stringstream());
|
std::unique_ptr<std::iostream> ss(new std::stringstream());
|
||||||
(*ss) << str;
|
(*ss) << str;
|
||||||
return std::make_unique<Arabica::SAX::InputSource<std::string>>(std::move(ss));
|
return std::make_unique<Arabica::SAX::InputSource<string_type, string_adaptor>>(std::move(ss));
|
||||||
} // source
|
} // source
|
||||||
}; // WhitespaceStripperTest
|
}; // WhitespaceStripperTest
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue