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()); +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy