summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-10-23 00:01:49 +0200
committerKevin Chabowski <kevin@kch42.de>2013-10-23 00:01:49 +0200
commitfc8f7eec23e8e95fc9a4a483bb69a1ee6866069d (patch)
treed7b9510e21e1c188894d821682327f5bfb9e225e /tests
parent04ee002e30b5451d505ee5abd9c6b97c40da2df0 (diff)
downloadste-fc8f7eec23e8e95fc9a4a483bb69a1ee6866069d.tar.gz
ste-fc8f7eec23e8e95fc9a4a483bb69a1ee6866069d.tar.bz2
ste-fc8f7eec23e8e95fc9a4a483bb69a1ee6866069d.zip
Added some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/dump_ast.php5
-rwxr-xr-xtests/mktest.sh15
-rwxr-xr-xtests/run_all.sh21
-rw-r--r--tests/test.php23
-rw-r--r--tests/test_loop/.gitignore3
-rw-r--r--tests/test_loop/code.php5
-rw-r--r--tests/test_loop/test.tpl3
-rw-r--r--tests/test_loop/want11
-rw-r--r--tests/test_simple/.gitignore3
-rw-r--r--tests/test_simple/code.php5
-rw-r--r--tests/test_simple/test.tpl1
-rw-r--r--tests/test_simple/want1
12 files changed, 96 insertions, 0 deletions
diff --git a/tests/dump_ast.php b/tests/dump_ast.php
new file mode 100644
index 0000000..418fbc8
--- /dev/null
+++ b/tests/dump_ast.php
@@ -0,0 +1,5 @@
+<?php
+
+require(dirname(__FILE__) . "/../stupid_template_engine.php");
+
+var_dump(\ste\Parser::parse(file_get_contents("php://stdin"), "-"));
diff --git a/tests/mktest.sh b/tests/mktest.sh
new file mode 100755
index 0000000..f249a7f
--- /dev/null
+++ b/tests/mktest.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+mkdir "$1"
+touch "$1/test.tpl"
+touch "$1/want"
+
+echo '<?php
+
+function test_func($ste) {
+
+}' > "$1/code.php"
+
+echo 'have
+*.ast
+*.transc.php' > "$1/.gitignore"
diff --git a/tests/run_all.sh b/tests/run_all.sh
new file mode 100755
index 0000000..75909d1
--- /dev/null
+++ b/tests/run_all.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+r=0
+for t in test_*; do
+ cd $t
+ php ../test.php > have
+ echo -n "$t: "
+ if cmp want have; then
+ echo "OK"
+ rm *.transc.php
+ else
+ echo "FAILED"
+ for tpl in *.tpl; do
+ php ../dump_ast.php < $tpl > $tpl.ast
+ done
+ r=1
+ fi
+ cd ..
+done
+
+exit $r \ No newline at end of file
diff --git a/tests/test.php b/tests/test.php
new file mode 100644
index 0000000..41713dc
--- /dev/null
+++ b/tests/test.php
@@ -0,0 +1,23 @@
+<?php
+
+require(dirname(__FILE__) . "/../stupid_template_engine.php");
+require("code.php");
+
+class TestStorage implements \ste\StorageAccess {
+ public function load($tpl, &$mode) {
+ $mode = \ste\MODE_SOURCE;
+ return file_get_contents($tpl);
+ }
+
+ public function save($tpl, $data, $mode) {
+ if($mode != \ste\MODE_TRANSCOMPILED) {
+ return;
+ }
+
+ file_put_contents("$tpl.transc.php", $data);
+ }
+}
+
+$ste = new \ste\STECore(new TestStorage());
+test_func($ste);
+echo $ste->exectemplate("test.tpl");
diff --git a/tests/test_loop/.gitignore b/tests/test_loop/.gitignore
new file mode 100644
index 0000000..de2a41b
--- /dev/null
+++ b/tests/test_loop/.gitignore
@@ -0,0 +1,3 @@
+have
+*.ast
+*.transc.php
diff --git a/tests/test_loop/code.php b/tests/test_loop/code.php
new file mode 100644
index 0000000..de8c553
--- /dev/null
+++ b/tests/test_loop/code.php
@@ -0,0 +1,5 @@
+<?php
+
+function test_func($ste) {
+
+}
diff --git a/tests/test_loop/test.tpl b/tests/test_loop/test.tpl
new file mode 100644
index 0000000..399f05a
--- /dev/null
+++ b/tests/test_loop/test.tpl
@@ -0,0 +1,3 @@
+<ste:for start="10" stop="0" step="-1" counter="i">
+$i
+</ste:for> \ No newline at end of file
diff --git a/tests/test_loop/want b/tests/test_loop/want
new file mode 100644
index 0000000..30b148d
--- /dev/null
+++ b/tests/test_loop/want
@@ -0,0 +1,11 @@
+10
+9
+8
+7
+6
+5
+4
+3
+2
+1
+0
diff --git a/tests/test_simple/.gitignore b/tests/test_simple/.gitignore
new file mode 100644
index 0000000..de2a41b
--- /dev/null
+++ b/tests/test_simple/.gitignore
@@ -0,0 +1,3 @@
+have
+*.ast
+*.transc.php
diff --git a/tests/test_simple/code.php b/tests/test_simple/code.php
new file mode 100644
index 0000000..4c0babc
--- /dev/null
+++ b/tests/test_simple/code.php
@@ -0,0 +1,5 @@
+<?php
+
+function test_func($ste) {
+ $ste->vars["foo"] = "World";
+}
diff --git a/tests/test_simple/test.tpl b/tests/test_simple/test.tpl
new file mode 100644
index 0000000..30a4f22
--- /dev/null
+++ b/tests/test_simple/test.tpl
@@ -0,0 +1 @@
+Hello $foo! \ No newline at end of file
diff --git a/tests/test_simple/want b/tests/test_simple/want
new file mode 100644
index 0000000..c57eff5
--- /dev/null
+++ b/tests/test_simple/want
@@ -0,0 +1 @@
+Hello World! \ No newline at end of file