isFloat.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/isFloat.hpp>
  9. using namespace ArduinoJson::Polyfills;
  10. struct Polyfills_IsFloat_Tests : testing::Test {
  11. void check(bool expected, const char* input) {
  12. bool actual = isFloat(input);
  13. EXPECT_EQ(expected, actual) << input;
  14. }
  15. };
  16. #define TEST_(X) TEST_F(Polyfills_IsFloat_Tests, X)
  17. TEST_(Null) {
  18. check(false, NULL);
  19. }
  20. TEST_(NoExponent) {
  21. check(true, "3.14");
  22. check(true, "-3.14");
  23. check(true, "+3.14");
  24. }
  25. TEST_(IntegralPartMissing) {
  26. check(true, ".14");
  27. check(true, "-.14");
  28. check(true, "+.14");
  29. }
  30. TEST_(FractionalPartMissing) {
  31. check(true, "3.");
  32. check(true, "-3.e14");
  33. check(true, "+3.e-14");
  34. }
  35. TEST_(NoDot) {
  36. check(true, "3e14");
  37. check(true, "3e-14");
  38. check(true, "3e+14");
  39. }
  40. TEST_(Integer) {
  41. check(false, "14");
  42. check(false, "-14");
  43. check(false, "+14");
  44. }
  45. TEST_(ExponentMissing) {
  46. check(false, "3.14e");
  47. check(false, "3.14e-");
  48. check(false, "3.14e+");
  49. }
  50. TEST_(JustASign) {
  51. check(false, "-");
  52. check(false, "+");
  53. }
  54. TEST_(Empty) {
  55. check(false, "");
  56. }
  57. TEST_(NaN) {
  58. check(true, "NaN");
  59. check(false, "n");
  60. check(false, "N");
  61. check(false, "nan");
  62. check(false, "-NaN");
  63. check(false, "+NaN");
  64. }
  65. TEST_(Infinity) {
  66. check(true, "Infinity");
  67. check(true, "+Infinity");
  68. check(true, "-Infinity");
  69. check(false, "infinity");
  70. check(false, "Inf");
  71. }