aboutsummaryrefslogtreecommitdiffstats
path: root/template_test
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-02 10:46:00 +0900
committeripknHama <ipknhama@gmail.com>2014-08-02 22:32:49 +0900
commit615e648260a87eb2edabf4aefb456186800e67a1 (patch)
tree7bd8b268a960b2b7d322407160a9d152e32a9251 /template_test
parent9d1d65b08c4a4c33923935a5414d6e6f4fe59ceb (diff)
downloadcrow-615e648260a87eb2edabf4aefb456186800e67a1.tar.gz
crow-615e648260a87eb2edabf4aefb456186800e67a1.zip
mustache partial implementation
Diffstat (limited to 'template_test')
-rw-r--r--template_test/Makefile2
-rw-r--r--template_test/mustachetest.cc13
-rwxr-xr-xtemplate_test/test.py10
3 files changed, 18 insertions, 7 deletions
diff --git a/template_test/Makefile b/template_test/Makefile
index f03e8fb..ad0d49b 100644
--- a/template_test/Makefile
+++ b/template_test/Makefile
@@ -1,5 +1,5 @@
all:
- $(CXX) -std=c++11 -g -o mustachetest mustachetest.cc
+ $(CXX) -Wall -std=c++11 -g -o mustachetest mustachetest.cc
.PHONY: clean
clean:
rm -f mustachetest *.o
diff --git a/template_test/mustachetest.cc b/template_test/mustachetest.cc
index 3b80b5d..c4ac2c9 100644
--- a/template_test/mustachetest.cc
+++ b/template_test/mustachetest.cc
@@ -11,15 +11,22 @@ using namespace crow::mustache;
string read_all(const string& filename)
{
ifstream is(filename);
- string ret;
- copy(istreambuf_iterator<char>(is), istreambuf_iterator<char>(), back_inserter(ret));
- return ret;
+ return {istreambuf_iterator<char>(is), istreambuf_iterator<char>()};
}
int main()
{
auto data = json::load(read_all("data"));
auto templ = compile(read_all("template"));
+ auto partials = json::load(read_all("partials"));
+ set_loader([&](std::string name)->std::string
+ {
+ if (partials.count(name))
+ {
+ return partials[name].s();
+ }
+ return "";
+ });
context ctx(data);
cout << templ.render(ctx);
return 0;
diff --git a/template_test/test.py b/template_test/test.py
index f99ca23..22fcca0 100755
--- a/template_test/test.py
+++ b/template_test/test.py
@@ -8,14 +8,17 @@ for testfile in glob.glob("*.json"):
for test in testdoc["tests"]:
if "lambda" in test["data"]:
continue
- if "partials" in test:
- #print testfile, test["name"]
- continue
open('data', 'w').write(json.dumps(test["data"]))
open('template', 'w').write(test["template"])
+ if "partials" in test:
+ open('partials', 'w').write(json.dumps(test["partials"]))
+ else:
+ open('partials', 'w').write("{}")
ret = subprocess.check_output("./mustachetest")
print testfile, test["name"]
if ret != test["expected"]:
+ if 'partials' in test:
+ print 'partials:', json.dumps(test["partials"])
print json.dumps(test["data"])
print test["template"]
print 'Expected:',repr(test["expected"])
@@ -23,3 +26,4 @@ for testfile in glob.glob("*.json"):
assert ret == test["expected"]
os.unlink('data')
os.unlink('template')
+ os.unlink('partials')