1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// tests for class TextStyle
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include "asserttestexit.h"
#include "srchilite/textstyleformatter.h"
#include "srchilite/bufferedoutput.h"
#include <sstream>
#include "srchilite/srcuntabifier.h"
#include "srchilite/ctagsformatter.h"
#include "srchilite/ctagscollector.h"
#include "srchilite/textstyles.h"
#include "srchilite/formatterparams.h"
using namespace srchilite;
class MyPreFormatter : public PreFormatter {
public:
virtual ~MyPreFormatter() {
}
protected:
/**
* test performatting
*/
virtual const std::string doPreformat(const std::string &text) {
return "{" + text + "}";
}
};
using namespace std;
int main() {
CTagsCollector collectorInline("mytags", INLINE);
CTagsFormatterResults results;
string sourceFile = string( BASEDIR) + "readtags.h";
TextStyles textStyles;
const char *vars[] = { "linenum", "infilename", "infile", "outfile", 0 };
textStyles.refstyle.anchor = TextStyle(
"<A>$text - $infilename):$linenum<A>", vars);
textStyles.refstyle.inline_reference = TextStyle(
"<IN>$text - $infilename):$linenum<IN>", vars);
textStyles.refstyle.postline_reference = TextStyle(
"<PL>$text - $infilename):$linenum<PL>", vars);
textStyles.refstyle.postdoc_reference = TextStyle(
"<PD>$text - $infilename):$linenum<PD>", vars);
// pretend the output is readtags.html
MyPreFormatter preformatter;
CTagsFormatter ctagsformatter(&preformatter, textStyles.refstyle,
&collectorInline);
ctagsformatter.setFileInfo(sourceFile, "readtags.html");
ostringstream os;
BufferedOutput bufferedOutput(os);
// just a foo tag
string orig = "<F>$text</F>";
TextStyle textStyle1(orig);
TextStyleFormatter formatter(textStyle1);
formatter.setBufferedOutput(&bufferedOutput);
formatter.setPreFormatter(&preformatter);
formatter.setCTagsFormatter(&ctagsformatter);
FormatterParams params(sourceFile);
params.line = 1;
formatter.format("there are no references", ¶ms);
cout << "formatted: " << os.str() << endl;
assertEquals("<F>{there are no references}</F>", os.str());
os.str("");
formatter.format("just one READTAGS_H reference", ¶ms);
cout << "formatted: " << os.str() << endl;
assertEquals(
"<F>{just one }</F><F><IN>{READTAGS_H} - readtags.h):22<IN></F><F>{ reference}</F>",
os.str());
// check that there's not post line and post doc references
os.str("");
bufferedOutput.writePostLine();
assertEquals("", os.str());
os.str("");
bufferedOutput.writePostDoc();
assertEquals("", os.str());
// test anchor
os.str("");
params.line = 22;
formatter.format("just one READTAGS_H anchor", ¶ms);
cout << "formatted: " << os.str() << endl;
assertEquals(
"<F>{just one }</F><F><A>{READTAGS_H} - readtags.h):22<A></F><F>{ anchor}</F>",
os.str());
// check that there's not post line and post doc references
os.str("");
bufferedOutput.writePostLine();
assertEquals("", os.str());
os.str("");
bufferedOutput.writePostDoc();
assertEquals("", os.str());
// test automatic postline
os.str("");
params.line = 1;
formatter.format("this file is a file reference", ¶ms);
cout << "formatted: " << os.str() << endl;
// the references do not appear in the paragraph, but in post line
assertEquals(
"<F>{this }</F><F>{file}</F><F>{ is a }</F><F>{file}</F><F>{ reference}</F>",
os.str());
// check that there's a post line and no post doc references
os.str("");
bufferedOutput.writePostLine();
cout << "postline: " << os.str() << endl;
assertEquals(
"<PL>{file} - readtags.h):112<PL>{\n}<PL>{file} - readtags.h):72<PL>{\n}",
os.str());
os.str("");
bufferedOutput.writePostDoc();
assertEquals("", os.str());
// test post doc
collectorInline.setRefPosition(POSTDOC);
os.str("");
params.line = 1;
formatter.format("this file is a file reference", ¶ms);
cout << "formatted: " << os.str() << endl;
// the references do not appear in the paragraph, but in post line
assertEquals(
"<F>{this }</F><F>{file}</F><F>{ is a }</F><F>{file}</F><F>{ reference}</F>",
os.str());
// check that there's a post doc and no post line references
os.str("");
bufferedOutput.writePostDoc();
cout << "postdoc: " << os.str() << endl;
assertEquals(
"<PD>{file} - readtags.h):112<PD>{\n}<PD>{file} - readtags.h):72<PD>{\n}",
os.str());
os.str("");
bufferedOutput.writePostLine();
assertEquals("", os.str());
cout << "test_formatreferences: SUCCESS" << endl;
return 0;
}
|