isInteger.cpp 759 B

123456789101112131415161718192021222324252627282930313233343536
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Text/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("FloatNotInteger") {
  12. REQUIRE_FALSE(isInteger("3.14"));
  13. REQUIRE_FALSE(isInteger("-3.14"));
  14. REQUIRE_FALSE(isInteger("+3.14"));
  15. }
  16. SECTION("Spaces") {
  17. REQUIRE_FALSE(isInteger("42 "));
  18. REQUIRE_FALSE(isInteger(" 42"));
  19. }
  20. SECTION("Valid") {
  21. REQUIRE(isInteger("42"));
  22. REQUIRE(isInteger("-42"));
  23. REQUIRE(isInteger("+42"));
  24. }
  25. SECTION("ExtraSign") {
  26. REQUIRE_FALSE(isInteger("--42"));
  27. REQUIRE_FALSE(isInteger("++42"));
  28. }
  29. }