diff --git a/content.tmpl b/content.tmpl
new file mode 100644
--- /dev/null
+++ b/content.tmpl
@@ -0,0 +1,1 @@
+{{ a_variable }}
diff --git a/example.py b/example.py
new file mode 100644
--- /dev/null
+++ b/example.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+from jinja2 import Environment, PackageLoader
+
+if __name__ == '__main__':
+    env = Environment(loader=PackageLoader('example', '.'))
+    template = env.get_template('example.tmpl')
+    print(template.render(
+        a_variable = "Hello,World!",
+        navigation = [ { 'href': 'content/a.html', 'caption': 'A'},
+                       { 'href': 'content/b.html', 'caption': 'B'} ]
+    ))
diff --git a/example.tmpl b/example.tmpl
new file mode 100644
--- /dev/null
+++ b/example.tmpl
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html lang="en">
+<head>
+  <title>My Webpage</title>
+</head>
+<body>
+  <ul id="navigation">
+    {% for item in navigation %}
+    <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
+    {% endfor %}
+  </ul>
+
+  <h1>My Webpage</h1>
+  {% include "content.tmpl" %}
+</body>
+</html>
diff --git a/haiji.cabal b/haiji.cabal
--- a/haiji.cabal
+++ b/haiji.cabal
@@ -2,7 +2,7 @@
 --  see http://haskell.org/cabal/users-guide/
 
 name:                haiji
-version:             0.3.1.0
+version:             0.3.2.0
 synopsis:            A typed template engine, subset of jinja2
 description:         Haiji is a template engine which is subset of jinja2.
                      This is designed to free from the unintended rendering result
@@ -14,7 +14,37 @@
 copyright:           Copyright (c) 2014-2019, Noriyuki OHKAWA
 category:            Text
 build-type:          Simple
--- extra-source-files:
+extra-source-files:  example.py
+                     example.tmpl
+                     content.tmpl
+                     test/HTML_escape.tmpl
+                     test/arith.tmpl
+                     test/child.tmpl
+                     test/comment.tmpl
+                     test/comparison.tmpl
+                     test/condition.tmpl
+                     test/empty.tmpl
+                     test/filter.tmpl
+                     test/foreach.tmpl
+                     test/foreach_else_block.tmpl
+                     test/include.tmpl
+                     test/included_0LF.tmpl
+                     test/included_1LF.tmpl
+                     test/included_2LF.tmpl
+                     test/lf1.tmpl
+                     test/lf2.tmpl
+                     test/line_with_newline.tmpl
+                     test/line_without_newline.tmpl
+                     test/logic.tmpl
+                     test/loop_variables.tmpl
+                     test/many_variables.tmpl
+                     test/parent.tmpl
+                     test/range.tmpl
+                     test/raw.tmpl
+                     test/set.tmpl
+                     test/string.tmpl
+                     test/variables.tmpl
+                     test/whitespace_control.tmpl
 cabal-version:       >=1.10
 
 source-repository head
diff --git a/src/Text/Haiji/Syntax/AST.hs b/src/Text/Haiji/Syntax/AST.hs
--- a/src/Text/Haiji/Syntax/AST.hs
+++ b/src/Text/Haiji/Syntax/AST.hs
@@ -95,10 +95,17 @@
   , parserStateInBaseTemplate = True
   }
 
+#if MIN_VERSION_base(4,13,0)
 newtype HaijiParser a =
   HaijiParser
   { unHaijiParser :: StateT ParserState Parser a
+  } deriving (Functor, Applicative, Alternative, Monad, MonadState ParserState, MonadFail)
+#else
+newtype HaijiParser a =
+  HaijiParser
+  { unHaijiParser :: StateT ParserState Parser a
   } deriving (Functor, Applicative, Alternative, Monad, MonadState ParserState)
+#endif
 
 runHaijiParser :: HaijiParser a -> Parser (a, ParserState)
 runHaijiParser p = runStateT (unHaijiParser p) defaultParserState
diff --git a/test/HTML_escape.tmpl b/test/HTML_escape.tmpl
new file mode 100644
--- /dev/null
+++ b/test/HTML_escape.tmpl
@@ -0,0 +1,1 @@
+{{ foo }}
diff --git a/test/arith.tmpl b/test/arith.tmpl
new file mode 100644
--- /dev/null
+++ b/test/arith.tmpl
@@ -0,0 +1,27 @@
+Pow
+{{ 2**3 }}
+{{ 2**31 }}
+{{ 2**32 }}
+{{ 2**63 }}
+{{ 2**64 }}
+{{ array|length**3**2 }}
+{{ array|length**(3**2) }}
+{{ (array|length**3)**2 }}
+{{ 3**array|length**2 }}
+{{ (3**array|length)**2 }}
+{{ 3**(array|length**2) }}
+
+Mul/Div/Mod
+{{ 5//2 }}
+{{ 5*2 }}
+{{ 5//2*3 }}
+{{ 5*2//3 }}
+{{ 5%2 }}
+{{ 5%2*3 }}
+{{ 5*2%3 }}
+
+Add/Sub
+{{ 5+2 }}
+{{ 5-2 }}
+{{ 5+2-3 }}
+{{ 5-2+3 }}
diff --git a/test/child.tmpl b/test/child.tmpl
new file mode 100644
--- /dev/null
+++ b/test/child.tmpl
@@ -0,0 +1,6 @@
+{% extends "test/parent.tmpl" %}
+{% block title %}{{ super() }}{{ baz }}{{ super() }}{% endblock %}
+{% block head %}
+ {{ super() }}
+ <style type="text/css"></style>
+{% endblock %}
diff --git a/test/comment.tmpl b/test/comment.tmpl
new file mode 100644
--- /dev/null
+++ b/test/comment.tmpl
@@ -0,0 +1,3 @@
+test
+{# comment #} #}
+test
diff --git a/test/comparison.tmpl b/test/comparison.tmpl
new file mode 100644
--- /dev/null
+++ b/test/comparison.tmpl
@@ -0,0 +1,27 @@
+1 == 1: {{ 1 == 1 }}
+1 == 2: {{ 1 == 2 }}
+value == value: {{ value == value }}
+value == 1: {{ value == 1 }}
+(1 == 1) == (1 == 1): {{ (1 == 1) == (1 == 1) }}
+(value == value) == (1 == 1): {{ (value == value) == (1 == 1) }}
+
+1 != 1: {{ 1 != 1 }}
+1 != 2: {{ 1 != 2 }}
+value != value: {{ value != value }}
+value != 1: {{ value != 1 }}
+(1 != 1) != (1 != 1): {{ (1 != 1) != (1 != 1) }}
+(value != value) != (1 != 1): {{ (value != value) != (1 != 1) }}
+
+1 > 1: {{ 1 > 1 }}
+1 > 2: {{ 1 > 2 }}
+1 >= 1: {{ 1 >= 1 }}
+1 >= 2: {{ 1 >= 2 }}
+1 < 1: {{ 1 < 1 }}
+1 < 2: {{ 1 < 2 }}
+1 <= 1: {{ 1 <= 1 }}
+1 <= 2: {{ 1 <= 2 }}
+
+"test" == "test": {{ "test" == "test" }}
+"test" == text: {{ "text" == text }}
+"test" > "test": {{ "test" > "test" }}
+"test" <= text: {{ "text" <= text }}
diff --git a/test/condition.tmpl b/test/condition.tmpl
new file mode 100644
--- /dev/null
+++ b/test/condition.tmpl
@@ -0,0 +1,21 @@
+{% if foo %}テスト{% endif %}
+
+{% if foo %}真{% else %}偽{% endif %}
+
+{% if foo %}
+foo = True
+{% if bar %}
+bar = True
+{% else %}
+bar = False
+{% endif %}
+A
+{% else %}
+foo = Fasle
+{% if baz %}
+baz = True
+{% else %}
+baz = False
+{% endif %}
+B
+{% endif %}
diff --git a/test/empty.tmpl b/test/empty.tmpl
new file mode 100644
--- /dev/null
+++ b/test/empty.tmpl
diff --git a/test/filter.tmpl b/test/filter.tmpl
new file mode 100644
--- /dev/null
+++ b/test/filter.tmpl
@@ -0,0 +1,2 @@
+{{ value|abs }}
+{{ array|length }}
diff --git a/test/foreach.tmpl b/test/foreach.tmpl
new file mode 100644
--- /dev/null
+++ b/test/foreach.tmpl
@@ -0,0 +1,3 @@
+{% for bar in foo %}
+  ループ{{ bar }}
+{% endfor %}
diff --git a/test/foreach_else_block.tmpl b/test/foreach_else_block.tmpl
new file mode 100644
--- /dev/null
+++ b/test/foreach_else_block.tmpl
@@ -0,0 +1,9 @@
+{% for bar in foo %}
+  ループ{{ bar }}
+{% else %}
+  空
+{% endfor %}
+
+{% for bar in foo %}
+  ループ{{ bar }}
+{% endfor %}
diff --git a/test/include.tmpl b/test/include.tmpl
new file mode 100644
--- /dev/null
+++ b/test/include.tmpl
@@ -0,0 +1,5 @@
+{% for bar in foo %}
+  {% include "test/included_0LF.tmpl" %}
+  {% include "test/included_1LF.tmpl" %}
+  {% include "test/included_2LF.tmpl" %}
+{% endfor %}
diff --git a/test/included_0LF.tmpl b/test/included_0LF.tmpl
new file mode 100644
--- /dev/null
+++ b/test/included_0LF.tmpl
@@ -0,0 +1,1 @@
+{{ bar }}
diff --git a/test/included_1LF.tmpl b/test/included_1LF.tmpl
new file mode 100644
--- /dev/null
+++ b/test/included_1LF.tmpl
@@ -0,0 +1,1 @@
+{{ bar }}
diff --git a/test/included_2LF.tmpl b/test/included_2LF.tmpl
new file mode 100644
--- /dev/null
+++ b/test/included_2LF.tmpl
@@ -0,0 +1,2 @@
+{{ bar }}
+
diff --git a/test/lf1.tmpl b/test/lf1.tmpl
new file mode 100644
--- /dev/null
+++ b/test/lf1.tmpl
@@ -0,0 +1,1 @@
+
diff --git a/test/lf2.tmpl b/test/lf2.tmpl
new file mode 100644
--- /dev/null
+++ b/test/lf2.tmpl
@@ -0,0 +1,2 @@
+
+
diff --git a/test/line_with_newline.tmpl b/test/line_with_newline.tmpl
new file mode 100644
--- /dev/null
+++ b/test/line_with_newline.tmpl
@@ -0,0 +1,1 @@
+foo
diff --git a/test/line_without_newline.tmpl b/test/line_without_newline.tmpl
new file mode 100644
--- /dev/null
+++ b/test/line_without_newline.tmpl
@@ -0,0 +1,1 @@
+foo
diff --git a/test/logic.tmpl b/test/logic.tmpl
new file mode 100644
--- /dev/null
+++ b/test/logic.tmpl
@@ -0,0 +1,29 @@
+{{ true and true }}
+{{ true and false }}
+{{ false and true }}
+{{ false and false }}
+{{ true and 1 == 1 }}
+
+{{ true or true }}
+{{ true or false }}
+{{ false or true }}
+{{ false or false }}
+{{ true or 1 == 1 }}
+
+{{ true or true and true }}
+{{ true or true and false }}
+{{ true or false and true }}
+{{ true or false and false }}
+{{ false or true and true }}
+{{ false or true and false }}
+{{ false or false and true }}
+{{ false or false and false }}
+
+{{ true and true or true }}
+{{ true and true or false }}
+{{ true and false or true }}
+{{ true and false or false }}
+{{ false and true or true }}
+{{ false and true or false }}
+{{ false and false or true }}
+{{ false and false or false }}
diff --git a/test/loop_variables.tmpl b/test/loop_variables.tmpl
new file mode 100644
--- /dev/null
+++ b/test/loop_variables.tmpl
@@ -0,0 +1,9 @@
+{% for bar in foo %}
+  {{ loop.index }}
+  {{ loop.index0 }}
+  {{ loop.revindex }}
+  {{ loop.revindex0 }}
+  {% if loop.first %}first{% endif %}
+  {% if loop.last %}last{% endif %}
+  {{ loop.length }}
+{% endfor %}
diff --git a/test/many_variables.tmpl b/test/many_variables.tmpl
new file mode 100644
--- /dev/null
+++ b/test/many_variables.tmpl
@@ -0,0 +1,17 @@
+{{ a }}
+{{ b }}
+{{ c }}
+{{ d }}
+{{ e }}
+{{ f }}
+{{ g }}
+{{ h }}
+{{ i }}
+{{ j }}
+{{ k }}
+{{ l }}
+{{ m }}
+{{ n }}
+{{ o }}
+{{ p }}
+{{ q }}
diff --git a/test/parent.tmpl b/test/parent.tmpl
new file mode 100644
--- /dev/null
+++ b/test/parent.tmpl
@@ -0,0 +1,11 @@
+<html>
+<head>
+{% block head %}
+  <title>{{ foo }}{% block title %}{% endblock %}</title>
+{% endblock %}
+</head>
+<body>
+  {{ bar }}
+  {% block missing %}child missing this block{% endblock %}
+</body>
+</html>
diff --git a/test/range.tmpl b/test/range.tmpl
new file mode 100644
--- /dev/null
+++ b/test/range.tmpl
@@ -0,0 +1,21 @@
+{% for i in range(3) %}
+{{ i }}
+{% endfor %}
+
+{% for i in range(1,3) %}
+{{ i }}
+{% endfor %}
+
+{% for i in range(1,5,2) %}
+{{ i }}
+{% endfor %}
+
+{% for i in range(value + 2) %}
+{{ i }}
+{% endfor %}
+
+{% for a in array %}
+{% for i in range(a) %}
+{{ i }}
+{% endfor %}
+{% endfor %}
diff --git a/test/raw.tmpl b/test/raw.tmpl
new file mode 100644
--- /dev/null
+++ b/test/raw.tmpl
@@ -0,0 +1,9 @@
+int main() {
+{% raw %}
+  <ul>
+  {% for item in seq %}
+    <li>{{ item }}</li>
+  {% endfor %}
+  </ul>
+{% endraw %}
+}
diff --git a/test/set.tmpl b/test/set.tmpl
new file mode 100644
--- /dev/null
+++ b/test/set.tmpl
@@ -0,0 +1,11 @@
+{%- for y in ys %}
+setにもスコープが存在する．変数を辞書に追加した後，
+{%- set prev_loop = loop %}
+ここから
+{%- for x in xs %}
+{{ prev_loop.index0 }} {{ loop.index0 }}
+{%- endfor %}
+ここまでをincludeと同じような扱いにする必要がある
+{{ prev_loop.index0 }}
+{%- endfor %}
+ここにsetした変数を書いたらエラー
diff --git a/test/string.tmpl b/test/string.tmpl
new file mode 100644
--- /dev/null
+++ b/test/string.tmpl
@@ -0,0 +1,6 @@
+{{ 'test' }}
+{{ "test" }}
+{{ '\'"' }}
+{{ "'\"" }}
+{{ '\n' }}
+{{ "\t" }}
diff --git a/test/variables.tmpl b/test/variables.tmpl
new file mode 100644
--- /dev/null
+++ b/test/variables.tmpl
@@ -0,0 +1,8 @@
+{{ foo }}
+{{ _foo }}
+{{ Foo }}
+{{ F__o_o__ }}
+{{ F1a2b3c }}
+{{ true }}
+{{ false }}
+{{ 1 }}
diff --git a/test/whitespace_control.tmpl b/test/whitespace_control.tmpl
new file mode 100644
--- /dev/null
+++ b/test/whitespace_control.tmpl
@@ -0,0 +1,5 @@
+  {%- for item in seq -%}
+    {{ item }}
+  {%- endfor -%}
+
+test
