From 82092e412a93f673bb15b81efbe23c6d1083c8d0 Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Sat, 12 Apr 2014 02:14:50 +0200 Subject: [PATCH] MathLib::isNullValue(): Fixed bug in detecting zero values. Improved test coverage of MathLib::IsNullValue(). --- lib/mathlib.cpp | 2 +- test/testmathlib.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index b5cf4bfc2..16a0c1c94 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -561,7 +561,7 @@ bool MathLib::isNullValue(const std::string &s) else if (*it == '.') state = DOT; else - return isValidSuffix(it, s.end()); + return false; break; case PLUSMINUS: if (*it == '0') diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 0bb102895..c82312c10 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -751,6 +751,14 @@ private: ASSERT_EQUALS(true, MathLib::isNullValue("+00.00E+1f")); ASSERT_EQUALS(true, MathLib::isNullValue("-00.00E+1f")); + // binary numbers + ASSERT_EQUALS(true, MathLib::isNullValue("0b00")); + ASSERT_EQUALS(true, MathLib::isNullValue("+0b00")); + ASSERT_EQUALS(true, MathLib::isNullValue("-0b00")); + // binary numbers (long) + ASSERT_EQUALS(true, MathLib::isNullValue("0b00L")); + ASSERT_EQUALS(true, MathLib::isNullValue("+0b00L")); + ASSERT_EQUALS(true, MathLib::isNullValue("-0b00L")); // negative testing ASSERT_EQUALS(false, MathLib::isNullValue("0.1")); ASSERT_EQUALS(false, MathLib::isNullValue("1.0")); @@ -760,6 +768,19 @@ private: ASSERT_EQUALS(false, MathLib::isNullValue("")); ASSERT_EQUALS(false, MathLib::isNullValue("x")); ASSERT_EQUALS(false, MathLib::isNullValue("garbage")); + ASSERT_EQUALS(false, MathLib::isNullValue("UL")); + ASSERT_EQUALS(false, MathLib::isNullValue("0x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0xx")); + ASSERT_EQUALS(false, MathLib::isNullValue("0x0x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0x000x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0b")); + ASSERT_EQUALS(false, MathLib::isNullValue("0bx")); + ASSERT_EQUALS(false, MathLib::isNullValue("0b0x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0b000x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0.0Ex")); + ASSERT_EQUALS(false, MathLib::isNullValue("0.0E-x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0.0E-1x")); + ASSERT_EQUALS(false, MathLib::isNullValue("0.0E-1fx")); // suffix LUL is not allowed ASSERT_EQUALS(false, MathLib::isNullValue("0LUL")); ASSERT_EQUALS(false, MathLib::isNullValue("+0LUL"));