From b4a1fd5bb4b24cec6b1410209de3f9511a00ff28 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 14 Mar 2022 16:25:30 +0100 Subject: lib: adjust require(), render() and include() raw mode semantics - Let `require()` always evaluate the executed code in raw mode - Let `render()` always evaluate the executed code in template mode - Let `include()` inherit the raw mode semantics of the calling scope Signed-off-by: Jo-Philipp Wich --- tests/custom/03_stdlib/29_require | 26 +++++++++++--------------- tests/custom/03_stdlib/35_include | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) (limited to 'tests/custom/03_stdlib') diff --git a/tests/custom/03_stdlib/29_require b/tests/custom/03_stdlib/29_require index 681f3f7..4fb4216 100644 --- a/tests/custom/03_stdlib/29_require +++ b/tests/custom/03_stdlib/29_require @@ -42,15 +42,13 @@ Returns the value returned by the invoked module code (typically an object). -- End -- -- File require/test/module.uc -- -{% - print("This is require.test.module running!\n\n"); +print("This is require.test.module running!\n\n"); - return { - greeting: function(name) { - printf("Hello, %s!\n", name); - } - }; -%} +return { + greeting: function(name) { + printf("Hello, %s!\n", name); + } +}; -- End -- -- Expect stdout -- @@ -139,19 +137,17 @@ A compilation error in the module triggers an exception. -- End -- -- File require/test/broken.uc -- -{% - // Unclosed object to force syntax error - return { -%} +// Unclosed object to force syntax error +return { -- End -- -- Expect stderr -- Unable to compile module '.../require/test/broken.uc': Syntax error: Expecting label -In line 3, byte 11: +In line 2, byte 10: - ` return {` - Near here --^ + `return {` + ^-- Near here diff --git a/tests/custom/03_stdlib/35_include b/tests/custom/03_stdlib/35_include index 6d808f2..1d428f1 100644 --- a/tests/custom/03_stdlib/35_include +++ b/tests/custom/03_stdlib/35_include @@ -171,3 +171,35 @@ In line 12, byte 8: -- End -- + + +Ensure that included files inherit the parse mode of their calling file. + +-- Testcase -- +{% include("files/inctest.uc"); %} +-- End -- + +-- File inctest.uc -- +print("Test\n"); +-- End -- + +-- Expect stdout -- +print("Test\n"); +-- End -- + + +-- Testcase -- +include("files/inctest.uc"); +-- End -- + +-- Args -- +-R +-- End -- + +-- File inctest.uc -- +print("Test\n"); +-- End -- + +-- Expect stdout -- +Test +-- End -- -- cgit v1.2.3