1 /*
2  * Copyright (C) 2009 Tommi Maekitalo
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11  * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12  * NON-INFRINGEMENT.  See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  */
19 
20 #include "../src/template.h"
21 
22 #include "gtest/gtest.h"
23 
24 namespace
25 {
26 class TemplateTest : public ::testing::Test, private zim::TemplateParser::Event
27 {
28  public:
29   std::string result;
30   zim::TemplateParser parser;
31 
TemplateTest()32   TemplateTest() : parser(this) {}
33 
34  private:
onData(const std::string & data)35   void onData(const std::string& data) { result += data; }
36 
onToken(const std::string & token)37   void onToken(const std::string& token)
38   {
39     result += "T(";
40     result += token;
41     result += ')';
42   }
43 
onLink(char ns,const std::string & title)44   void onLink(char ns, const std::string& title)
45   {
46     result += "L(";
47     result += ns;
48     result += ", ";
49     result += title;
50     result += ')';
51   }
52 };
53 
TEST_F(TemplateTest,ZeroTemplate)54 TEST_F(TemplateTest, ZeroTemplate)
55 {
56   parser.parse("<html><body><h1>Hi</h1></body></html>");
57   parser.flush();
58 
59   ASSERT_EQ(result, "<html><body><h1>Hi</h1></body></html>");
60 }
61 
TEST_F(TemplateTest,Token)62 TEST_F(TemplateTest, Token)
63 {
64   parser.parse("<html><%content%></html>");
65   parser.flush();
66 
67   ASSERT_EQ(result, "<html>T(content)</html>");
68 }
69 
TEST_F(TemplateTest,Link)70 TEST_F(TemplateTest, Link)
71 {
72   parser.parse("<html><%/A/Article%></html>");
73   parser.flush();
74 
75   ASSERT_EQ(result, "<html>L(A, Article)</html>");
76 }
77 
78 }  // namespace
79