Added a test with a NULL string

This commit is contained in:
Benoît Blanchon
2014-06-26 13:14:09 +02:00
parent d12e25bd8a
commit 18587d132b
2 changed files with 16 additions and 1 deletions

View File

@ -8,6 +8,11 @@
void StringBuilder::append(const char* s)
{
if (!s)
{
return append("null");
}
char* tail = buffer + length;
while (*s && length<capacity)
@ -20,7 +25,11 @@ void StringBuilder::append(const char* s)
void StringBuilder::appendEscaped(const char* s)
{
if (length > capacity - 3) return;
if (length > capacity - 2)
{
// not enough from for quotes
return;
}
buffer[length++] = '"';

View File

@ -28,6 +28,12 @@ namespace JsonGeneratorTests
assertResultIs("");
}
TEST_METHOD(Null)
{
append(NULL);
assertResultIs("null");
}
TEST_METHOD(OneString)
{
append("ABCD");