Changed arrays to use {} when converted to string; added tests

master
krzys-h 2016-06-21 12:58:43 +02:00
parent 5f7a8dbd5d
commit c304ecd0ca
2 changed files with 29 additions and 2 deletions

View File

@ -343,10 +343,12 @@ std::string CBotVarClass::GetValString()
res += " ("; res += " (";
} }
} }
res += " )";
} }
else else
{ {
res = "( "; res = "{ ";
CBotVar* pv = m_pVar; CBotVar* pv = m_pVar;
while ( pv != nullptr ) while ( pv != nullptr )
@ -355,9 +357,10 @@ std::string CBotVarClass::GetValString()
if ( pv->GetNext() != nullptr ) res += ", "; if ( pv->GetNext() != nullptr ) res += ", ";
pv = pv->GetNext(); pv = pv->GetNext();
} }
res += " }";
} }
res += " )";
return res; return res;
} }

View File

@ -485,6 +485,30 @@ TEST_F(CBotUT, VarImplicitCast)
); );
} }
TEST_F(CBotUT, ToString)
{
ExecuteTest(
"extern void ArrayToString()\n"
"{\n"
" int[] array = {2, 4, 6};\n"
" string arrayStr = \"\"+array;\n"
" ASSERT(arrayStr == \"{ 2, 4, 6 }\");\n"
"}\n"
);
ExecuteTest(
"public class Test { int a = 1337; }\n"
"extern void ClassToString()\n"
"{\n"
" Test test();\n"
" string testStr = \"\"+test;\n"
" ASSERT(testStr == \"Pointer to Test( a=1337 )\");\n"
"}\n"
);
// TODO: IntrinsicClassToString ? (e.g. point)
}
TEST_F(CBotUT, Arrays) TEST_F(CBotUT, Arrays)
{ {
ExecuteTest( ExecuteTest(