From c304ecd0cab9b62670d384d8ae93d9ab66c4d1fc Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 21 Jun 2016 12:58:43 +0200 Subject: [PATCH] Changed arrays to use {} when converted to string; added tests --- src/CBot/CBotVar/CBotVarClass.cpp | 7 +++++-- test/unit/CBot/CBot_test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp index 919b43a6..08acffbe 100644 --- a/src/CBot/CBotVar/CBotVarClass.cpp +++ b/src/CBot/CBotVar/CBotVarClass.cpp @@ -343,10 +343,12 @@ std::string CBotVarClass::GetValString() res += " ("; } } + + res += " )"; } else { - res = "( "; + res = "{ "; CBotVar* pv = m_pVar; while ( pv != nullptr ) @@ -355,9 +357,10 @@ std::string CBotVarClass::GetValString() if ( pv->GetNext() != nullptr ) res += ", "; pv = pv->GetNext(); } + + res += " }"; } - res += " )"; return res; } diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index e8cdcd1d..c0d5e122 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -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) { ExecuteTest(