isInteger.cpp 850 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://bblanchon.github.io/ArduinoJson/
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson/Polyfills/isInteger.hpp>
  8. #include <catch.hpp>
  9. using namespace ArduinoJson::Polyfills;
  10. TEST_CASE("isInteger()") {
  11. SECTION("Null") {
  12. REQUIRE_FALSE(isInteger(NULL));
  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. }