isInteger.cpp 831 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2023
  3. // MIT License
  4. #include <ArduinoJson/Polyfills/isInteger.hpp>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::Internals;
  7. TEST_CASE("isInteger()") {
  8. SECTION("Null") {
  9. REQUIRE_FALSE(isInteger(NULL));
  10. }
  11. SECTION("Empty String") {
  12. REQUIRE_FALSE(isInteger(""));
  13. }
  14. SECTION("FloatNotInteger") {
  15. REQUIRE_FALSE(isInteger("3.14"));
  16. REQUIRE_FALSE(isInteger("-3.14"));
  17. REQUIRE_FALSE(isInteger("+3.14"));
  18. }
  19. SECTION("Spaces") {
  20. REQUIRE_FALSE(isInteger("42 "));
  21. REQUIRE_FALSE(isInteger(" 42"));
  22. }
  23. SECTION("Valid") {
  24. REQUIRE(isInteger("42"));
  25. REQUIRE(isInteger("-42"));
  26. REQUIRE(isInteger("+42"));
  27. }
  28. SECTION("ExtraSign") {
  29. REQUIRE_FALSE(isInteger("--42"));
  30. REQUIRE_FALSE(isInteger("++42"));
  31. }
  32. }