Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

major style improvements for all files

  • Loading branch information...
commit 2544a48fcb4f552d105124c78a3255ec719cf22f 1 parent 89d17a5
@mrtazz authored
View
24 include/context.hpp
@@ -5,24 +5,22 @@
*/
#ifndef PLUSTACHE_CONTEXT_H
#define PLUSTACHE_CONTEXT_H
-#include <iostream>
-#include "plustache_types.hpp"
-
-using namespace std;
+#include <iostream>
+#include "include/plustache_types.hpp"
-class context {
+class Context {
public:
- context ();
- ~context ();
- int add(string key, string value);
- int add(string key, CollectionType c);
- int add(string key, ObjectType o);
- int add(ObjectType o);
- CollectionType get(string key);
+ Context ();
+ ~Context ();
+ int add(const std::string& key, const std::string& value);
+ int add(const std::string& key, PlustacheTypes::CollectionType& c);
+ int add(const std::string& key, const PlustacheTypes::ObjectType& o);
+ int add(const PlustacheTypes::ObjectType& o);
+ PlustacheTypes::CollectionType get(const std::string& key) const;
private:
/* data */
- map<string, CollectionType> ctx;
+ std::map<std::string, PlustacheTypes::CollectionType> ctx;
};
#endif
View
14 include/plustache_types.hpp
@@ -3,15 +3,17 @@
* @brief header file for plustache types
* @author Daniel Schauenberg <d@unwiredcouch.com>
*/
-#ifndef PLUSTACHE_TYPES_H
-#define PLUSTACHE_TYPES_H
+#ifndef PLUSTACHE_TYPES_H_
+#define PLUSTACHE_TYPES_H_
+
#include <string>
#include <map>
#include <vector>
-using namespace std;
+namespace PlustacheTypes {
+/* typedefs */
+typedef std::map<std::string, std::string> ObjectType;
+typedef std::vector<ObjectType> CollectionType;
+}
-/* defines */
-typedef vector< map<string, string> > CollectionType;
-typedef map<string, string> ObjectType;
#endif
View
44 include/template.hpp
@@ -11,38 +11,40 @@
#include <boost/algorithm/string/trim.hpp>
#include <boost/regex.hpp>
-#include <plustache_types.hpp>
-#include <context.hpp>
-
-using namespace std;
-using namespace boost;
+#include "include/plustache_types.hpp"
+#include "include/context.hpp"
class template_t {
+ typedef PlustacheTypes::ObjectType ObjectType;
+ typedef PlustacheTypes::CollectionType CollectionType;
public:
template_t ();
- template_t (string tmpl_path);
+ template_t (std::string& tmpl_path);
~template_t ();
- string render(string tmplate, context ctx);
- string render(string tmplate, ObjectType ctx);
+ std::string render(const std::string& tmplate, const Context& ctx);
+ std::string render(const std::string& tmplate, const ObjectType& ctx);
private:
- string template_path;
+ std::string template_path;
/* opening and closing tags */
- string otag;
- string ctag;
+ std::string otag;
+ std::string ctag;
/* regex */
- regex tag;
- regex section;
- regex escape_chars;
+ boost::regex tag;
+ boost::regex section;
+ boost::regex escape_chars;
/* lut for HTML escape chars */
- map<string, string> escape_lut;
+ std::map<std::string, std::string> escape_lut;
/* render and helper methods */
- string render_tags(string tmplate, context ctx);
- string render_sections(string tmplate, context ctx);
- string html_escape(string s);
- string get_partial(string partial);
- void change_delimiter(string opentag, string closetag);
+ std::string render_tags(const std::string& tmplate,
+ const Context& ctx);
+ std::string render_sections(const std::string& tmplate,
+ const Context& ctx);
+ std::string html_escape(const std::string& s);
+ std::string get_partial(const std::string& partial) const;
+ void change_delimiter(const std::string& opentag,
+ const std::string& closetag);
void compile_data();
- string get_template(string tmpl);
+ std::string get_template(const std::string& tmpl);
};
#endif
View
14 rakefile
@@ -32,8 +32,8 @@ BIN_OBJECTS = BIN_FILES.collect { |fn|
}
# include dirs
-INCLUDE_DIRS = ["."]
-LDFLAGS = []
+INCLUDE_DIRS = [".", "/usr/local/include"]
+LDFLAGS = ["-L /usr/local/lib"]
res = %x[uname].chomp
if res == "Darwin"
@@ -47,7 +47,7 @@ end
# compiler/linker stuff
CC = "g++"
LD = "g++"
-CCFLAGS = ["-O3","-Wall", "-fPIC", "-I #{INCLUDE_DIRS.join(" -I")}"]
+CCFLAGS = ["-O3","-Wall", "-fPIC", "-I #{INCLUDE_DIRS.join(" -I ")}"]
# task definitions
@@ -62,7 +62,7 @@ namespace :test do
desc "task for style and error checking with cppcheck"
task :style do
- sh "cppcheck --enable=all src/"
+ sh "cppcheck -I #{INCLUDE_DIRS.join(" -I ")} --enable=all src/"
end
end
@@ -108,7 +108,7 @@ directory BINDIR
file APPLICATION => BINDIR
file APPLICATION => SRC_OBJECTS + BIN_OBJECTS do |t|
sh "#{LD} #{SRC_OBJECTS} #{BIN_OBJECTS} -o #{t.name} #{LDFLAGS.join(" ")} \
--lboost_regex-mt"
+-lboost_regex"
end
# rules for unit testing
@@ -116,7 +116,7 @@ directory BINDIR
file TEST => BINDIR
file TEST => SRC_OBJECTS + TEST_OBJECTS do |t|
sh "#{LD} #{TEST_OBJECTS} #{SRC_OBJECTS} -o #{t.name} #{LDFLAGS.join(" ")} \
--lboost_regex-mt -lgtest"
+-lboost_regex -lgtest"
end
# rules for static library
@@ -130,7 +130,7 @@ end
directory LIBDIR
file DYNAMIC_LIB => LIBDIR
file DYNAMIC_LIB => SRC_OBJECTS do |t|
- sh "#{LD} #{DYNFLAGS.join(" ")} -o #{DYNAMIC_LIB} #{SRC_OBJECTS} -lboost_regex-mt"
+ sh "#{LD} #{DYNFLAGS.join(" ")} -o #{DYNAMIC_LIB} #{SRC_OBJECTS} -lboost_regex"
end
# compile rules for object files
View
62 src/context.cpp
@@ -4,43 +4,44 @@
* @author Daniel Schauenberg <d@unwiredcouch.com>
*/
-#include <context.hpp>
+#include "include/context.hpp"
+#include "include/plustache_types.hpp"
-context::context()
+Context::Context()
{
}
-context::~context()
+Context::~Context()
{
}
/**
- * @brief method to add a simple key/value to the context
+ * @brief method to add a simple key/value to the Context
*
* @param key
* @param value
*
* @return 0 on success
*/
-int context::add(string key, string value)
+int Context::add(const std::string& key, const std::string& value)
{
- ObjectType obj;
+ PlustacheTypes::ObjectType obj;
obj[key] = value;
ctx[key].push_back(obj);
return 0;
}
/**
- * @brief method to add a collection to a specific key in the context
+ * @brief method to add a collection to a specific key in the Context
*
* @param key to store the data
* @param c Collection to add
*
* @return 0 on success
*/
-int context::add(string key, CollectionType c)
+int Context::add(const std::string& key, PlustacheTypes::CollectionType& c)
{
if (ctx.find(key) == ctx.end())
{
@@ -48,7 +49,7 @@ int context::add(string key, CollectionType c)
}
else
{
- for(CollectionType::iterator it = c.begin();
+ for(PlustacheTypes::CollectionType::iterator it = c.begin();
it != c.end(); ++it)
{
(*this).add(key, (*it));
@@ -58,20 +59,20 @@ int context::add(string key, CollectionType c)
}
/**
- * @brief method to add an additional object to a collection in the context
+ * @brief method to add an additional object to a collection in the Context
*
* @param key for the collection
* @param o object to add
*
* @return 0
*/
-int context::add(string key, ObjectType o)
+int Context::add(const std::string& key, const PlustacheTypes::ObjectType& o)
{
if (ctx.find(key) == ctx.end())
{
- CollectionType c;
- c.push_back(o);
- ctx[key] = c;
+ PlustacheTypes::CollectionType c;
+ c.push_back(o);
+ ctx[key] = c;
}
else
{
@@ -82,15 +83,15 @@ int context::add(string key, ObjectType o)
}
/**
- * @brief method to add fields of an ObjectType directly to the context
+ * @brief method to add fields of an ObjectType directly to the Context
*
* @param o ObjectType with fields
*
* @return 0
*/
-int context::add(ObjectType o)
+int Context::add(const PlustacheTypes::ObjectType& o)
{
- for(ObjectType::const_iterator it = o.begin();
+ for(PlustacheTypes::ObjectType::const_iterator it = o.begin();
it != o.end(); it++)
{
(*this).add(it->first, it->second);
@@ -99,7 +100,7 @@ int context::add(ObjectType o)
}
/**
- * @brief method to get a value from the context
+ * @brief method to get a value from the Context
*
* This is a generic getter which always returns a collection
* (vector of maps) for a keyword. If the return value is a collection, the
@@ -111,15 +112,20 @@ int context::add(ObjectType o)
*
* @return collection for the keyword
*/
-CollectionType context::get(string key)
+PlustacheTypes::CollectionType Context::get(const std::string& key) const
{
- CollectionType ret;
- ret = ctx[key];
- if (ret.size() < 1)
- {
- ObjectType o;
- o[key] = "";
- ret.push_back(o);
- }
- return ret;
+ PlustacheTypes::CollectionType ret;
+ std::map<std::string, PlustacheTypes::CollectionType> :: const_iterator it;
+ it = ctx.find(key);
+ if (it == ctx.end())
+ {
+ PlustacheTypes::ObjectType o;
+ o[key] = "";
+ ret.push_back(o);
+ }
+ else
+ {
+ ret = it->second;
+ }
+ return ret;
}
View
9 src/main.cpp
@@ -1,7 +1,16 @@
#include <template.hpp>
+#include <context.hpp>
+#include <iostream>
int main(int argc, const char *argv[])
{
template_t t;
+ string str_template;
+ str_template = "text {{foo}} text";
+ context ctx;
+ ctx.add("foo", "bla");
+ string s;
+ s = t.render(str_template, ctx);
+ cout << s << endl;
return 0;
}
View
236 src/template.cpp
@@ -4,7 +4,14 @@
* @author Daniel Schauenberg <d@unwiredcouch.com>
*/
-#include <template.hpp>
+#include "include/template.hpp"
+
+#include <string>
+#include <boost/regex.hpp>
+#include <boost/algorithm/string/trim.hpp>
+
+#include "include/plustache_types.hpp"
+#include "include/context.hpp"
/**
* @brief constructor taking no arguments
@@ -21,7 +28,7 @@ template_t::template_t()
*
* @param tmpl_path path to the template directory
*/
-template_t::template_t(string tmpl_path)
+template_t::template_t(std::string& tmpl_path)
{
template_path = tmpl_path;
}
@@ -37,7 +44,7 @@ void template_t::compile_data()
escape_lut[">"] = "&gt;";
escape_lut["\\"] = "&#92;";
escape_lut["\""] = "&quot;";
- // regex for what to escape in a html string
+ // regex for what to escape in a html std::string
escape_chars.assign("(<|>|\"|\\\\|&)");
otag = "\\{\\{";
ctag = "\\}\\}";
@@ -58,45 +65,48 @@ template_t::~template_t()
/**
* @brief method to render tags with a given map
*
- * @param tmplate template string to render
+ * @param tmplate template std::string to render
* @param ctx map of values
*
- * @return rendered string
+ * @return rendered std::string
*/
-string template_t::render_tags(string tmplate, context ctx)
+std::string template_t::render_tags(const std::string& tmplate,
+ const Context& ctx)
{
// initialize data
- string ret = "";
- string rest = "";
- string::const_iterator start, end;
- match_results<std::string::const_iterator> matches;
+ std::string ret = "";
+ std::string rest = "";
+ std::string::const_iterator start, end;
+ boost::match_results<std::string::const_iterator> matches;
start = tmplate.begin();
end = tmplate.end();
- // return whole string when no tags are found
- if (!regex_search(start, end, matches, tag, match_default | format_all))
+ // return whole std::string when no tags are found
+ if (!regex_search(start, end, matches, tag,
+ boost::match_default | boost::format_all))
{
ret = tmplate;
}
// loop through tags and replace
- while (regex_search(start, end, matches, tag, match_default | format_all))
+ while (regex_search(start, end, matches, tag,
+ boost::match_default | boost::format_all))
{
- string modifier(matches[1].first, matches[1].second);
- string key(matches[2].first, matches[2].second);
- algorithm::trim(key);
- algorithm::trim(modifier);
- string text(start, matches[0].second);
- string repl;
+ std::string modifier(matches[1].first, matches[1].second);
+ std::string key(matches[2].first, matches[2].second);
+ boost::algorithm::trim(key);
+ boost::algorithm::trim(modifier);
+ std::string text(start, matches[0].second);
+ std::string repl;
// don't html escape this
if (modifier == "&" || modifier == "{")
{
try
{
// get value
- string s = ctx.get(key)[0][key];
- // escape backslash in string
- const string f = "\\";
+ std::string s = ctx.get(key)[0][key];
+ // escape backslash in std::string
+ const std::string f = "\\";
size_t found = s.find(f);
- while(found != string::npos)
+ while(found != std::string::npos)
{
s.replace(found,f.length(),"\\\\");
found = s.find(f, found+2);
@@ -113,7 +123,8 @@ string template_t::render_tags(string tmplate, context ctx)
// found a partial
else if (modifier == ">")
{
- repl.assign(template_t::render(template_t::get_partial(key), ctx));
+ std::string partial = template_t::get_partial(key);
+ repl.assign(template_t::render(partial, ctx));
}
// normal tag
else
@@ -126,24 +137,25 @@ string template_t::render_tags(string tmplate, context ctx)
}
// replace
- ret += regex_replace(text, tag, repl, match_default | format_all);
+ ret += regex_replace(text, tag, repl,
+ boost::match_default | boost::format_all);
// change delimiter after was removed
if (modifier == "=")
{
// regex for finding delimiters
- regex delim("(.+?) (.+?)=");
+ boost::regex delim("(.+?) (.+?)=");
// match object
- match_results<std::string::const_iterator> delim_m;
+ boost::match_results<std::string::const_iterator> delim_m;
// search for the delimiters
- regex_search(matches[2].first, matches[2].second, delim_m, delim,
- match_default | format_all);
+ boost::regex_search(matches[2].first, matches[2].second, delim_m, delim,
+ boost::match_default | boost::format_all);
// set new otag and ctag
- string new_otag = delim_m[1];
- string new_ctag = delim_m[2];
+ std::string new_otag = delim_m[1];
+ std::string new_ctag = delim_m[2];
// change delimiters
template_t::change_delimiter(new_otag, new_ctag);
}
- // set start for next tag and rest of string
+ // set start for next tag and rest of std::string
rest.assign(matches[0].second, end);
start = matches[0].second;
}
@@ -155,39 +167,40 @@ string template_t::render_tags(string tmplate, context ctx)
/**
* @brief method to render sections with a given map
*
- * @param tmplate template string to render
+ * @param tmplate template std::string to render
* @param ctx map of values
*
- * @return rendered string
+ * @return rendered std::string
*/
-string template_t::render_sections(string tmplate, context ctx)
+std::string template_t::render_sections(const std::string& tmplate,
+ const Context& ctx)
{
// initialize data structures
- string ret = "";
- string rest = "";
- string::const_iterator start, end;
- match_results<std::string::const_iterator> matches;
+ std::string ret = "";
+ std::string rest = "";
+ std::string::const_iterator start, end;
+ boost::match_results<std::string::const_iterator> matches;
start = tmplate.begin();
end = tmplate.end();
// return the whole template if no sections are found
- if (!regex_search(start, end, matches, section,
- match_default | format_all))
+ if (!boost::regex_search(start, end, matches, section,
+ boost::match_default | boost::format_all))
{
ret = tmplate;
}
// loop through sections and render
- while (regex_search(start, end, matches, section,
- match_default | format_all))
+ while (boost::regex_search(start, end, matches, section,
+ boost::match_default | boost::format_all))
{
- // string assignments
- string text(start, matches[0].second);
- string key(matches[2].first, matches[2].second);
- string modifier(matches[1]);
+ // std::string assignments
+ std::string text(start, matches[0].second);
+ std::string key(matches[2].first, matches[2].second);
+ std::string modifier(matches[1]);
// trimming
- algorithm::trim(key);
- algorithm::trim(modifier);
- string repl = "";
- string show = "false";
+ boost::algorithm::trim(key);
+ boost::algorithm::trim(modifier);
+ std::string repl = "";
+ std::string show = "false";
CollectionType values;
values = ctx.get(key);
if (values.size() == 1)
@@ -215,8 +228,8 @@ string template_t::render_sections(string tmplate, context ctx)
// assign replacement content
if (show == "true")
{
- if (regex_search(matches[3].first, matches[3].second,
- section, match_default | format_all))
+ if (boost::regex_search(matches[3].first, matches[3].second, section,
+ boost::match_default | boost::format_all))
{
repl.assign(template_t::render_sections(matches[3], ctx));
}
@@ -225,7 +238,7 @@ string template_t::render_sections(string tmplate, context ctx)
for(CollectionType::iterator it = values.begin();
it != values.end(); ++it)
{
- context small_ctx;
+ Context small_ctx;
small_ctx = ctx;
small_ctx.add(*it);
repl += template_t::render_tags(matches[3], small_ctx);
@@ -233,7 +246,8 @@ string template_t::render_sections(string tmplate, context ctx)
}
}
else repl.assign("");
- ret += regex_replace(text, section, repl, match_default | format_all);
+ ret += boost::regex_replace(text, section, repl,
+ boost::match_default | boost::format_all);
rest.assign(matches[0].second, end);
start = matches[0].second;
}
@@ -245,38 +259,39 @@ string template_t::render_sections(string tmplate, context ctx)
/**
* @brief method for rendering a template
*
- * @param tmplate template to render as raw string or file path
+ * @param tmplate template to render as raw std::string or file path
* @param ctx context object
*
- * @return rendered string
+ * @return rendered std::string
*/
-string template_t::render(string tmplate, context ctx)
+std::string template_t::render(const std::string& tmplate, const Context& ctx)
{
// get template
- string tmp = get_template(tmplate);
+ std::string tmp = get_template(tmplate);
- string first = template_t::render_sections(tmp, ctx);
- string second = template_t::render_tags(first, ctx);
+ std::string first = template_t::render_sections(tmp, ctx);
+ std::string second = template_t::render_tags(first, ctx);
return second;
}
/**
* @brief method for rendering a template
*
- * @param tmplate template to render as raw string or filepath
+ * @param tmplate template to render as raw std::string or filepath
* @param ctx map of values
*
- * @return rendered string
+ * @return rendered std::string
*/
-string template_t::render(string tmplate, ObjectType ctx)
+std::string template_t::render(const std::string& tmplate,
+ const ObjectType& ctx)
{
// get template
- string tmp = get_template(tmplate);
- context contxt;
+ std::string tmp = get_template(tmplate);
+ Context contxt;
contxt.add(ctx);
- string first = template_t::render_sections(tmp, contxt);
- string second = template_t::render_tags(first, contxt);
+ std::string first = template_t::render_sections(tmp, contxt);
+ std::string second = template_t::render_tags(first, contxt);
return second;
}
@@ -286,38 +301,38 @@ string template_t::render(string tmplate, ObjectType ctx)
/**
- * @brief method to escape html strings
+ * @brief method to escape html std::strings
*
- * @param s string to escape
+ * @param s std::string to escape
*
- * @return escaped string
+ * @return escaped std::string
*/
-string template_t::html_escape(string s)
+std::string template_t::html_escape(const std::string& s)
{
- /** initialize working strings and iterators */
- string ret = "";
- string rest = "";
- string::const_iterator start, end;
- match_results<std::string::const_iterator> matches;
+ /** initialize working std::strings and iterators */
+ std::string ret = "";
+ std::string rest = "";
+ std::string::const_iterator start, end;
+ boost::match_results<std::string::const_iterator> matches;
start = s.begin();
end = s.end();
- // return original string if nothing is found
- if (!regex_search(start, end, matches, escape_chars,
- match_default | format_all))
+ // return original std::string if nothing is found
+ if (!boost::regex_search(start, end, matches, escape_chars,
+ boost::match_default | boost::format_all))
{
ret = s;
}
// search for html chars
- while (regex_search(start, end, matches, escape_chars,
- match_default | format_all))
+ while (boost::regex_search(start, end, matches, escape_chars,
+ boost::match_default | boost::format_all))
{
- string key(matches[0].first, matches[0].second);
- string text(start, matches[0].second);
- algorithm::trim(key);
- string repl;
+ std::string key(matches[0].first, matches[0].second);
+ std::string text(start, matches[0].second);
+ boost::algorithm::trim(key);
+ std::string repl;
repl = escape_lut[key];
- ret += regex_replace(text, escape_chars, repl,
- match_default | format_all);
+ ret += boost::regex_replace(text, escape_chars, repl,
+ boost::match_default | boost::format_all);
rest.assign(matches[0].second, end);
start = matches[0].second;
}
@@ -331,31 +346,31 @@ string template_t::html_escape(string s)
*
* @param s name of the partial to load
*
- * @return partial template as string
+ * @return partial template as std::string
*/
-string template_t::get_partial(string partial)
+std::string template_t::get_partial(const std::string& partial) const
{
- string ret = "";
- string file_with_path = template_path;
- partial += ".mustache";
+ std::string ret = "";
+ std::string file_with_path = template_path;
file_with_path += partial;
+ file_with_path += ".mustache";
// file path with template path prefix
- ifstream extended_file(file_with_path.c_str());
+ std::ifstream extended_file(file_with_path.c_str());
// true if it was a valid file path
if (extended_file.is_open())
{
- ret.assign((istreambuf_iterator<char>(extended_file)),
- istreambuf_iterator<char>());
+ ret.assign((std::istreambuf_iterator<char>(extended_file)),
+ std::istreambuf_iterator<char>());
extended_file.close();
}
else
{
// file path without prefix
- ifstream file(partial.c_str());
+ std::ifstream file(partial.c_str());
if(file.is_open())
{
- ret.assign((istreambuf_iterator<char>(file)),
- istreambuf_iterator<char>());
+ ret.assign((std::istreambuf_iterator<char>(file)),
+ std::istreambuf_iterator<char>());
file.close();
}
}
@@ -368,7 +383,8 @@ string template_t::get_partial(string partial)
* @param opentag delimiter for open tag
* @param closetag delimiter for closed tag
*/
-void template_t::change_delimiter(string opentag, string closetag)
+void template_t::change_delimiter(const std::string& opentag,
+ const std::string& closetag)
{
otag = opentag;
ctag = closetag;
@@ -383,26 +399,26 @@ void template_t::change_delimiter(string opentag, string closetag)
*
* @param tmpl path to template or template directory
*
- * @return template as string
+ * @return template as std::string
*/
-string template_t::get_template(string tmpl)
+std::string template_t::get_template(const std::string& tmpl)
{
- // string to hold the template
- string tmp = "";
- ifstream file(tmpl.c_str());
- ifstream file_from_tmpl_dir((template_path + tmpl).c_str());
+ // std::string to hold the template
+ std::string tmp = "";
+ std::ifstream file(tmpl.c_str());
+ std::ifstream file_from_tmpl_dir((template_path + tmpl).c_str());
// true if it was a valid local file path
if (file.is_open())
{
- tmp.assign((istreambuf_iterator<char>(file)),
- istreambuf_iterator<char>());
+ tmp.assign((std::istreambuf_iterator<char>(file)),
+ std::istreambuf_iterator<char>());
file.close();
}
// maybe the template is in the standard directory
else if (file_from_tmpl_dir.is_open())
{
- tmp.assign((istreambuf_iterator<char>(file_from_tmpl_dir)),
- istreambuf_iterator<char>());
+ tmp.assign((std::istreambuf_iterator<char>(file_from_tmpl_dir)),
+ std::istreambuf_iterator<char>());
file_from_tmpl_dir.close();
}
View
22 tests/test_change_delimiter.cpp
@@ -1,18 +1,22 @@
-#include "include/template.hpp"
+#include <string>
+#include <map>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class ChangeDelimiterTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- string result_notfound;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ std::string result_notfound;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
ChangeDelimiterTest()
{
@@ -53,14 +57,14 @@ class ChangeDelimiterTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(ChangeDelimiterTest, TestChangeDelimiterFromString)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
EXPECT_EQ(expected, result_string);
}
TEST_F(ChangeDelimiterTest, TestChangeDelimiterFromFile)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
EXPECT_EQ(expected, result_file);
}
View
36 tests/test_collections_plustache.cpp
@@ -1,17 +1,21 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/context.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class CollectionsTest : public ::testing::Test
{
protected:
- string result_single;
- string result_multiple;
- string result_multiple_fields;
- string template_string;
- string template_single_string;
+ std::string result_single;
+ std::string result_multiple;
+ std::string result_multiple_fields;
+ std::string template_string;
+ std::string template_single_string;
CollectionsTest()
{
@@ -33,28 +37,28 @@ class CollectionsTest : public ::testing::Test
template_single_string += "{{/ people}}";
// single entry
- ObjectType tom;
- ObjectType jerry;
+ PlustacheTypes::ObjectType tom;
+ PlustacheTypes::ObjectType jerry;
tom["name"] = "Tom";
- context ctx_single;
+ Context ctx_single;
ctx_single.add("me", "Daniel");
ctx_single.add("people",tom);
// multiple entries
jerry["name"] = "Jerry";
- CollectionType b_multiple;
+ PlustacheTypes::CollectionType b_multiple;
b_multiple.push_back(tom);
b_multiple.push_back(jerry);
- context ctx_multiple;
+ Context ctx_multiple;
ctx_multiple.add("me", "Daniel");
ctx_multiple.add("people", b_multiple);
// multiple fields
tom["work"] = "Accounting";
jerry["work"] = "Magic";
- CollectionType b_multiple_fields;
+ PlustacheTypes::CollectionType b_multiple_fields;
b_multiple_fields.push_back(tom);
- context ctx;
+ Context ctx;
ctx.add("me", "Daniel");
ctx.add("people", b_multiple_fields);
ctx.add("people", jerry);
@@ -76,14 +80,14 @@ class CollectionsTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(CollectionsTest, TestCollectionsSingle)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "Hi Tom!";
EXPECT_EQ(expected, result_single);
}
TEST_F(CollectionsTest, TestCollectionsMultiple)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "Hi Tom!";
expected += "Hi Jerry!";
EXPECT_EQ(expected, result_multiple);
@@ -91,7 +95,7 @@ TEST_F(CollectionsTest, TestCollectionsMultiple)
TEST_F(CollectionsTest, TestCollectionMultipleWithMultipleFields)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "Hi Daniel, I am Tom, I do Accounting.";
expected += "Hi Daniel, I am Jerry, I do Magic.";
EXPECT_EQ(expected, result_multiple_fields);
View
31 tests/test_html_escape_plustache.cpp
@@ -1,21 +1,24 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class HtmlEscapeTest : public ::testing::Test
{
protected:
- string result_escaped_string;
- string result_escaped_file;
- string result_unescaped_string;
- string result_unescaped_file;
- string escaped_string;
- string unescaped_string;
- map<string, string> ctx;
- string escaped_file;
- string unescaped_file;
+ std::string result_escaped_string;
+ std::string result_escaped_file;
+ std::string result_unescaped_string;
+ std::string result_unescaped_file;
+ std::string escaped_string;
+ std::string unescaped_string;
+ PlustacheTypes::ObjectType ctx;
+ std::string escaped_file;
+ std::string unescaped_file;
HtmlEscapeTest()
{
@@ -65,7 +68,7 @@ class HtmlEscapeTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(HtmlEscapeTest, TestHtmlEscapeMustacheFromString)
{
- string expected = "text &lt;pre&gt;&quot;&#92;&amp;foo&#92;&lt;\
+ std::string expected = "text &lt;pre&gt;&quot;&#92;&amp;foo&#92;&lt;\
/pre&gt; text\n";
expected += "text &lt;pre&gt;&quot;&#92;&#92;&amp;&lt;/pre&gt; text";
EXPECT_EQ(expected, result_escaped_string);
@@ -73,7 +76,7 @@ TEST_F(HtmlEscapeTest, TestHtmlEscapeMustacheFromString)
TEST_F(HtmlEscapeTest, TestHtmlEscapeMustacheFromFile)
{
- string expected = "text &lt;pre&gt;&quot;&#92;&amp;foo&#92;&lt;\
+ std::string expected = "text &lt;pre&gt;&quot;&#92;&amp;foo&#92;&lt;\
/pre&gt; text\n";
expected += "text &lt;pre&gt;&quot;&#92;&#92;&amp;&lt;/pre&gt; text";
EXPECT_EQ(expected, result_escaped_file);
@@ -81,14 +84,14 @@ TEST_F(HtmlEscapeTest, TestHtmlEscapeMustacheFromFile)
TEST_F(HtmlEscapeTest, TestHtmlUnEscapeMustacheFromString)
{
- string expected = "text <pre>\"\\&foo\\</pre> text\n";
+ std::string expected = "text <pre>\"\\&foo\\</pre> text\n";
expected += "text <pre>\"\\\\&</pre> text";
EXPECT_EQ(expected, result_unescaped_string);
}
TEST_F(HtmlEscapeTest, TestHtmlUnEscapeMustacheFromFile)
{
- string expected = "text <pre>\"\\&foo\\</pre> text\n";
+ std::string expected = "text <pre>\"\\&foo\\</pre> text\n";
expected += "text <pre>\"\\\\&</pre> text";
EXPECT_EQ(expected, result_unescaped_file);
}
View
21 tests/test_inverted_sections.cpp
@@ -1,17 +1,20 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class InvertedSectionsTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
InvertedSectionsTest()
{
@@ -38,7 +41,7 @@ class InvertedSectionsTest : public ::testing::Test
template_string += "{{/ stealth}}";
file = "sections.mustache";
- ofstream myfile;
+ std::ofstream myfile;
myfile.open (file.c_str());
myfile << template_string;
myfile.close();
@@ -63,7 +66,7 @@ class InvertedSectionsTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(InvertedSectionsTest, TestInvertedSectionMustacheFromString)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
expected += "Hope you can see me.";
expected += "me too.";
@@ -72,7 +75,7 @@ TEST_F(InvertedSectionsTest, TestInvertedSectionMustacheFromString)
TEST_F(InvertedSectionsTest, TestInvertedSectionMustacheFromFile)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
expected += "Hope you can see me.";
expected += "me too.";
View
17 tests/test_multiple_plustache.cpp
@@ -1,18 +1,21 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class MultipleTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- string expected;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ std::string expected;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
MultipleTest()
{
}
View
21 tests/test_nested_sections_plustache.cpp
@@ -1,17 +1,20 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class NestedSectionsTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
NestedSectionsTest()
{
@@ -32,7 +35,7 @@ class NestedSectionsTest : public ::testing::Test
template_string += "{{/ showme}}";
file = "sections.mustache";
- ofstream myfile;
+ std::ofstream myfile;
myfile.open (file.c_str());
myfile << template_string;
myfile.close();
@@ -56,7 +59,7 @@ class NestedSectionsTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(NestedSectionsTest, TestSectionMustacheFromString)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.\n";
expected += "If you don't see this, something went wrong.";
EXPECT_EQ(expected, result_string);
@@ -64,7 +67,7 @@ TEST_F(NestedSectionsTest, TestSectionMustacheFromString)
TEST_F(NestedSectionsTest, TestSectionMustacheFromFile)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.\n";
expected += "If you don't see this, something went wrong.";
EXPECT_EQ(expected, result_file);
View
25 tests/test_partials_plustache.cpp
@@ -1,19 +1,22 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class PartialsTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- string partial_string;
- map<string, string> ctx;
- string file;
- string partial_file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ std::string partial_string;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
+ std::string partial_file;
PartialsTest()
{
@@ -34,7 +37,7 @@ class PartialsTest : public ::testing::Test
file = "sections.mustache";
partial_file = "next_more.mustache";
- ofstream myfile;
+ std::ofstream myfile;
// write template to file
myfile.open (file.c_str());
myfile << template_string;
@@ -64,7 +67,7 @@ class PartialsTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(PartialsTest, TestPartialsFromString)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.\n";
expected += "What do I like? Turtles!!";
EXPECT_EQ(expected, result_string);
@@ -72,7 +75,7 @@ TEST_F(PartialsTest, TestPartialsFromString)
TEST_F(PartialsTest, TestPartialsMustacheFromFile)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.\n";
expected += "What do I like? Turtles!!";
EXPECT_EQ(expected, result_file);
View
21 tests/test_sections_plustache.cpp
@@ -1,17 +1,20 @@
-#include "include/template.hpp"
+#include <string>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+#include "include/plustache_types.hpp"
+
// The fixture for testing class Foo.
class SectionsTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ PlustacheTypes::ObjectType ctx;
+ std::string file;
SectionsTest()
{
@@ -32,7 +35,7 @@ class SectionsTest : public ::testing::Test
template_string += "{{/ dontshowme}}";
file = "sections.mustache";
- ofstream myfile;
+ std::ofstream myfile;
myfile.open (file.c_str());
myfile << template_string;
myfile.close();
@@ -56,14 +59,14 @@ class SectionsTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(SectionsTest, TestSectionMustacheFromString)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
EXPECT_EQ(expected, result_string);
}
TEST_F(SectionsTest, TestSectionMustacheFromFile)
{
- string expected = "Hi I am Daniel.\n";
+ std::string expected = "Hi I am Daniel.\n";
expected += "I like turtles.";
EXPECT_EQ(expected, result_file);
}
View
25 tests/test_simple_plustache.cpp
@@ -1,19 +1,22 @@
-#include "include/template.hpp"
+#include <string>
+#include <map>
#include <iostream>
#include <fstream>
#include <gtest/gtest.h>
+#include "include/template.hpp"
+
// The fixture for testing class Foo.
class SimpleTest : public ::testing::Test
{
protected:
- string result_string;
- string result_file;
- string template_string;
- string result_notfound;
- string notfound;
- map<string, string> ctx;
- string file;
+ std::string result_string;
+ std::string result_file;
+ std::string template_string;
+ std::string result_notfound;
+ std::string notfound;
+ std::map<std::string, std::string> ctx;
+ std::string file;
SimpleTest()
{
@@ -51,17 +54,17 @@ class SimpleTest : public ::testing::Test
// Tests that a simple mustache tag is replaced
TEST_F(SimpleTest, TestSimpleMustacheFromString)
{
- const string expected = "text replaced text";
+ const std::string expected = "text replaced text";
EXPECT_EQ(expected, result_string);
}
TEST_F(SimpleTest, TestSimpleMustacheFromFile)
{
- const string expected = "text replaced text";
+ const std::string expected = "text replaced text";
EXPECT_EQ(expected, result_file);
}
TEST_F(SimpleTest, TestSimpleNotFoundMustacheFromString)
{
- const string expected = "text text";
+ const std::string expected = "text text";
EXPECT_EQ(expected, result_notfound);
}
Please sign in to comment.
Something went wrong with that request. Please try again.