summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/02_runtime/02_this
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2021-03-19 16:54:55 +0100
committerJo-Philipp Wich <jo@mein.io>2021-04-23 00:42:30 +0200
commit2b59097c3f61fa901e91ac4cea48940760439578 (patch)
tree958d739a78f959dfcd55b3d76e6e970ca53fa1c6 /tests/custom/02_runtime/02_this
parent80393611fb6634abcc0da1dee2da7c4418dbde8d (diff)
tests: create custom tests from current tests cases
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'tests/custom/02_runtime/02_this')
-rw-r--r--tests/custom/02_runtime/02_this50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/custom/02_runtime/02_this b/tests/custom/02_runtime/02_this
new file mode 100644
index 0000000..d8e85d2
--- /dev/null
+++ b/tests/custom/02_runtime/02_this
@@ -0,0 +1,50 @@
+The "this" object accesses the current function context.
+
+-- Expect stdout --
+true
+true
+-- End --
+
+-- Testcase --
+{%
+ // Functions not invoked on objects have no this context
+ function test() {
+ return (this === null);
+ }
+
+ // When invoked, "this" will point to the object containing the function
+ let o;
+ o = {
+ test: function() {
+ return (this === o);
+ }
+ };
+
+ print(test(), "\n");
+ print(o.test(), "\n");
+%}
+-- End --
+
+Test that the context is properly restored if function call arguments are
+dot or bracket expressions as well.
+
+-- Expect stdout --
+true
+true
+-- End --
+
+-- Testcase --
+{%
+ let o;
+ o = {
+ test: function() {
+ return (this === o);
+ }
+ };
+
+ let dummy = { foo: true, bar: false };
+
+ print(o.test(dummy.foo, dummy.bar), "\n");
+ print(o.test(dummy.foo, o.test(dummy.foo, dummy.bar)), "\n");
+%}
+-- End --