MCPcopy Create free account
hub / github.com/anjo76/angelscript / Test

Function Test

sdk/tests/test_feature/source/test_scriptstring.cpp:89–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87bool Test2();
88
89bool Test()
90{
91 bool fail = false;
92 COutStream out;
93 CBufferedOutStream bout;
94 asIScriptEngine *engine = 0;
95 asIScriptModule *mod = 0;
96 int r;
97
98 // Test non-terminated heredoc string
99 // https://www.gamedev.net/forums/topic/714946-crash-parsing-non-terminated-heredoc-string/5459282/
100 {
101 engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
102 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
103 bout.buffer = "";
104
105 RegisterStdString(engine);
106
107 mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
108 mod->AddScriptSection("test",
109 "string str = \"\"\"\n"
110 "This is a heredoc string that has not been terminated\n");
111 r = mod->Build();
112 if (r >= 0)
113 TEST_FAILED;
114
115 if (bout.buffer != "test (1, 14) : Error : Non-terminated string literal\n")
116 {
117 PRINTF("%s", bout.buffer.c_str());
118 TEST_FAILED;
119 }
120
121 engine->ShutDownAndRelease();
122 }
123
124 // Test heredoc engine properties
125 // idea from discussion with Scott Bean
126 {
127 engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
128 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
129
130 RegisterScriptString(engine);
131
132 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
133
134 // without line break
135 engine->SetEngineProperty(asEP_HEREDOC_TRIM_MODE, 2);
136 r = ExecuteString(engine, "string s = \"\"\" \"\"\"; assert( s == '' ); \n");
137 if (r != asEXECUTION_FINISHED)
138 TEST_FAILED;
139
140 // with line break
141 engine->SetEngineProperty(asEP_HEREDOC_TRIM_MODE, 2);
142 r = ExecuteString(engine, "string s = \"\"\" \n \"\"\"; assert( s == '' ); \n");
143 if (r != asEXECUTION_FINISHED)
144 TEST_FAILED;
145
146 // without line break, no trimming

Callers

nothing calls this directly

Calls 15

RegisterStdStringFunction · 0.85
ExecuteStringFunction · 0.85
TestUTF16Function · 0.85
RegisterScriptArrayFunction · 0.85
CompareRelationFunction · 0.85
CompareEqualityFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
ShutDownAndReleaseMethod · 0.80
SetEnginePropertyMethod · 0.80

Tested by

no test coverage detected