isInteger.cpp 886 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <gtest/gtest.h>
  8. #include <ArduinoJson/Polyfills/isInteger.hpp>
  9. using namespace ArduinoJson::Polyfills;
  10. struct Polyfills_IsInteger_Tests : testing::Test {
  11. void check(bool expected, const char* input) {
  12. bool actual = isInteger(input);
  13. EXPECT_EQ(expected, actual) << input;
  14. }
  15. };
  16. #define TEST_(X) TEST_F(Polyfills_IsInteger_Tests, X)
  17. TEST_(Null) {
  18. check(false, NULL);
  19. }
  20. TEST_(FloatNotInteger) {
  21. check(false, "3.14");
  22. check(false, "-3.14");
  23. check(false, "+3.14");
  24. }
  25. TEST_(Spaces) {
  26. check(false, "42 ");
  27. check(false, " 42");
  28. }
  29. TEST_(Valid) {
  30. check(true, "42");
  31. check(true, "-42");
  32. check(true, "+42");
  33. }
  34. TEST_(ExtraSign) {
  35. check(false, "--42");
  36. check(false, "++42");
  37. }