Skip to content

Commit

Permalink
Merge pull request #220 from alranel/isempty
Browse files Browse the repository at this point in the history
Add String::isEmpty()
  • Loading branch information
aentinger authored Nov 8, 2023
2 parents 2c4e96c + 73e2d09 commit fc9a636
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/src/String/test_isEmpty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Arduino. All rights reserved.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <catch.hpp>

#include <api/String.h>

#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());
}

0 comments on commit fc9a636

Please sign in to comment.