summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-09-15 22:27:12 +0200
committerJo-Philipp Wich <jo@mein.io>2020-09-15 22:27:12 +0200
commit8a8f86c54ddf9e5ddd3b06e3067ee61a538c35c0 (patch)
treeb78267d45bfefae62cc48b8c49b9fd402bdddfac
parent52ac5c3f4b086415dedcff90ddec871f970335cc (diff)
tests: add test for "this" context
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--tests/02_runtime/02_this28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/02_runtime/02_this b/tests/02_runtime/02_this
new file mode 100644
index 0000000..2c47811
--- /dev/null
+++ b/tests/02_runtime/02_this
@@ -0,0 +1,28 @@
+The "this" object accesses the current function context.
+
+-- Expect stdout --
+
+-- End --
+true
+true
+-- Testcase --
+{%
+ local g = this;
+
+ // Functions not invoked on objects have no this context
+ function test() {
+ print(this, "\n");
+ return (this === null);
+ }
+
+ // When invoked, "this" will point to the object containing the function
+ local o = {
+ test: function() {
+ return (this === o);
+ }
+ };
+
+ print(test(), "\n");
+ print(o.test(), "\n");
+%}
+-- End --