diff --git a/api/String.h b/api/String.h index 73a872de..0bafd35a 100644 --- a/api/String.h +++ b/api/String.h @@ -89,6 +89,7 @@ class String // invalid string (i.e., "if (s)" will be true afterwards) bool reserve(unsigned int size); inline unsigned int length(void) const {return len;} + inline bool isEmpty(void) const { return length() == 0; } // creates a copy of the assigned value. if the value is null or // invalid, or if the memory allocation fails, the string will be diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp new file mode 100644 index 00000000..9f70f26d --- /dev/null +++ b/test/src/String/test_isEmpty.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +#include "StringPrinter.h" + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Testing String::isEmpty when string is empty", "[String-isEmpty-01]") +{ + arduino::String str; + REQUIRE(str.isEmpty()); +} + +TEST_CASE ("Testing String::isEmpty when string contains characters", "[String-isEmpty-02]") +{ + arduino::String str("Testing String::isEmpty"); + REQUIRE(!str.isEmpty()); +}