diff options
| author | Martin Hořeňovský | 2026-07-23 14:26:17 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-07-23 14:26:26 +0200 |
| commit | c267251e709c52cda421e9490c5cbaf62914fa52 (patch) | |
| tree | a1330c2158cd39ac376d05fca0960a58cda679d7 | |
| parent | 0cc833ea95bb7136c99be1b5b105780cae5766ff (diff) | |
| download | catch3-c267251e709c52cda421e9490c5cbaf62914fa52.tar.gz | |
Better support for infs and NaNs in JSON writer
As the types and values sent into the writer are determined by Catch2,
I do not expect to actually need this support, but it is better to have
it and not be surprised in the future.
20 files changed, 441 insertions, 18 deletions
diff --git a/src/catch2/internal/catch_jsonwriter.cpp b/src/catch2/internal/catch_jsonwriter.cpp index 6a994f11..d5122dbc 100644 --- a/src/catch2/internal/catch_jsonwriter.cpp +++ b/src/catch2/internal/catch_jsonwriter.cpp @@ -7,8 +7,10 @@ // SPDX-License-Identifier: BSL-1.0 #include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_jsonwriter.hpp> +#include <catch2/internal/catch_polyfills.hpp> #include <catch2/internal/catch_unreachable.hpp> +#include <cmath> #include <locale> namespace Catch { @@ -145,10 +147,30 @@ namespace Catch { writeImpl( value, true ); } + void JsonValueWriter::write( float value ) && { + writeFloatingPoint( value ); + } + + void JsonValueWriter::write( double value ) && { + writeFloatingPoint( value ); + } + void JsonValueWriter::write( bool value ) && { writeImpl( value ? "true"_sr : "false"_sr, false ); } + template <typename T> + void JsonValueWriter::writeFloatingPoint( T value ) { + if ( Catch::isnan( value ) ) { + writeImpl( "NaN"_sr, false ); + } else if ( std::isinf( value ) ) { + writeImpl( value < 0 ? "-Infinity"_sr : "Infinity"_sr, false ); + } else { + m_sstream << value; + writeImpl( m_sstream.str(), false ); + } + } + void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) { if ( quote ) { m_os << '"'; } size_t current_start = 0; diff --git a/src/catch2/internal/catch_jsonwriter.hpp b/src/catch2/internal/catch_jsonwriter.hpp index 8b3d2bc1..c07d7d75 100644 --- a/src/catch2/internal/catch_jsonwriter.hpp +++ b/src/catch2/internal/catch_jsonwriter.hpp @@ -39,11 +39,19 @@ namespace Catch { writeImpl( value, !std::is_arithmetic<T>::value ); } void write( StringRef value ) &&; + void write( float value ) &&; + void write( double value ) &&; void write( bool value ) &&; private: void writeImpl( StringRef value, bool quote ); + // Helper to deal with non-finite floating point values, which + // are not standard JSON, but we use JS/Python/etc. approach of + // emitting `NaN`, `Infinity`, `-Infinity` as number(like). + template <typename T> + void writeFloatingPoint( T value ); + // Without this SFINAE, this overload is a better match // for `std::string`, `char const*`, `char const[N]` args. // While it would still work, it would cause code bloat diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index b0028998..a25bc52a 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -190,6 +190,8 @@ Nor would this :test-result: PASS Inequality checks that should succeed :test-result: PASS JsonWriter :test-result: PASS JsonWriter escapes characters in strings properly +:test-result: PASS JsonWriter serializes non-finite FP using Python spelling - double +:test-result: PASS JsonWriter serializes non-finite FP using Python spelling - float :test-result: PASS JsonWriter serializes numbers independently of the global locale :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 9602395a..3f846b7b 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -188,6 +188,8 @@ :test-result: PASS Inequality checks that should succeed :test-result: PASS JsonWriter :test-result: PASS JsonWriter escapes characters in strings properly +:test-result: PASS JsonWriter serializes non-finite FP using Python spelling - double +:test-result: PASS JsonWriter serializes non-finite FP using Python spelling - float :test-result: PASS JsonWriter serializes numbers independently of the global locale :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index d669bce4..7989d276 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1248,6 +1248,12 @@ Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\n\"" for: ""\n"" == Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" +Json.tests.cpp:<line number>: passed: sstream.str() == "NaN" for: "NaN" == "NaN" +Json.tests.cpp:<line number>: passed: sstream.str() == "Infinity" for: "Infinity" == "Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "NaN" for: "NaN" == "NaN" +Json.tests.cpp:<line number>: passed: sstream.str() == "Infinity" for: "Infinity" == "Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" Json.tests.cpp:<line number>: passed: sstream.str(), ContainsSubstring( "\"double\": 1.5," ) && ContainsSubstring( "\"int\": 1234567," ) && ContainsSubstring( "\"bool-1\": true," ) && ContainsSubstring( "\"bool-2\": false," ) && ContainsSubstring( "\"array\": [\n 2.5,\n 1234567\n ]\n}" ) for: "{ "double": 1.5, "int": 1234567, @@ -3014,7 +3020,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: -test cases: 452 | 332 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2417 | 2216 passed | 158 failed | 43 failed as expected +test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 712b1259..ffe7a2f6 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -1246,6 +1246,12 @@ Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\n\"" for: ""\n"" == Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" +Json.tests.cpp:<line number>: passed: sstream.str() == "NaN" for: "NaN" == "NaN" +Json.tests.cpp:<line number>: passed: sstream.str() == "Infinity" for: "Infinity" == "Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "NaN" for: "NaN" == "NaN" +Json.tests.cpp:<line number>: passed: sstream.str() == "Infinity" for: "Infinity" == "Infinity" +Json.tests.cpp:<line number>: passed: sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" Json.tests.cpp:<line number>: passed: sstream.str(), ContainsSubstring( "\"double\": 1.5," ) && ContainsSubstring( "\"int\": 1234567," ) && ContainsSubstring( "\"bool-1\": true," ) && ContainsSubstring( "\"bool-2\": false," ) && ContainsSubstring( "\"array\": [\n 2.5,\n 1234567\n ]\n}" ) for: "{ "double": 1.5, "int": 1234567, @@ -3003,7 +3009,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: -test cases: 452 | 332 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2417 | 2216 passed | 158 failed | 43 failed as expected +test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index a833734a..344c5b03 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1743,6 +1743,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 452 | 350 passed | 76 failed | 7 skipped | 19 failed as expected -assertions: 2395 | 2216 passed | 136 failed | 43 failed as expected +test cases: 454 | 352 passed | 76 failed | 7 skipped | 19 failed as expected +assertions: 2401 | 2222 passed | 136 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 2de0a3a5..0729823f 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -8220,6 +8220,78 @@ with expansion: ""\\/\t\r\n"" == ""\\/\t\r\n"" ------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + NaN +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "NaN" ) +with expansion: + "NaN" == "NaN" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + Pos nf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "Infinity" ) +with expansion: + "Infinity" == "Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + Neg inf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "-Infinity" ) +with expansion: + "-Infinity" == "-Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + NaN +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "NaN" ) +with expansion: + "NaN" == "NaN" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + Pos nf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "Infinity" ) +with expansion: + "Infinity" == "Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + Neg inf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "-Infinity" ) +with expansion: + "-Infinity" == "-Infinity" + +------------------------------------------------------------------------------- JsonWriter serializes numbers independently of the global locale ------------------------------------------------------------------------------- Json.tests.cpp:<line number> @@ -20159,6 +20231,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 452 | 332 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2417 | 2216 passed | 158 failed | 43 failed as expected +test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 9b6f023c..3db4bfc8 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -8218,6 +8218,78 @@ with expansion: ""\\/\t\r\n"" == ""\\/\t\r\n"" ------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + NaN +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "NaN" ) +with expansion: + "NaN" == "NaN" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + Pos nf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "Infinity" ) +with expansion: + "Infinity" == "Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - double + Neg inf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "-Infinity" ) +with expansion: + "-Infinity" == "-Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + NaN +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "NaN" ) +with expansion: + "NaN" == "NaN" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + Pos nf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "Infinity" ) +with expansion: + "Infinity" == "Infinity" + +------------------------------------------------------------------------------- +JsonWriter serializes non-finite FP using Python spelling - float + Neg inf +------------------------------------------------------------------------------- +Json.tests.cpp:<line number> +............................................................................... + +Json.tests.cpp:<line number>: PASSED: + REQUIRE( sstream.str() == "-Infinity" ) +with expansion: + "-Infinity" == "-Infinity" + +------------------------------------------------------------------------------- JsonWriter serializes numbers independently of the global locale ------------------------------------------------------------------------------- Json.tests.cpp:<line number> @@ -20148,6 +20220,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 452 | 332 passed | 96 failed | 6 skipped | 18 failed as expected -assertions: 2417 | 2216 passed | 158 failed | 43 failed as expected +test cases: 454 | 334 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2423 | 2222 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index c84565d5..f58412b6 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2429" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2435" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -774,6 +774,14 @@ at Condition.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/carriage return in a string is escaped" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/tab in a string is escaped" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/combination of characters is escaped" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/NaN" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/Pos nf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/Neg inf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/NaN" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/Pos nf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/Neg inf" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter serializes numbers independently of the global locale" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Lambdas in assertions" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Less-than inequalities with different epsilons" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index f4ff03d6..c80e5855 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuites> - <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2429" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="141" skipped="12" tests="2435" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -773,6 +773,14 @@ at Condition.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/carriage return in a string is escaped" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/tab in a string is escaped" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter escapes characters in strings properly/combination of characters is escaped" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/NaN" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/Pos nf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - double/Neg inf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/NaN" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/Pos nf" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="JsonWriter serializes non-finite FP using Python spelling - float/Neg inf" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="JsonWriter serializes numbers independently of the global locale" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Lambdas in assertions" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Less-than inequalities with different epsilons" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index dceaca40..17c26f36 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -262,6 +262,14 @@ at AssertionHandler.tests.cpp:<line number> <testCase name="JsonWriter escapes characters in strings properly/carriage return in a string is escaped" duration="{duration}"/> <testCase name="JsonWriter escapes characters in strings properly/tab in a string is escaped" duration="{duration}"/> <testCase name="JsonWriter escapes characters in strings properly/combination of characters is escaped" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/NaN" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/Pos nf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/Neg inf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/NaN" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/Pos nf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/Neg inf" duration="{duration}"/> <testCase name="JsonWriter serializes numbers independently of the global locale" duration="{duration}"/> </file> <file path="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp"> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 250b45ae..4c113189 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -261,6 +261,14 @@ at AssertionHandler.tests.cpp:<line number> <testCase name="JsonWriter escapes characters in strings properly/carriage return in a string is escaped" duration="{duration}"/> <testCase name="JsonWriter escapes characters in strings properly/tab in a string is escaped" duration="{duration}"/> <testCase name="JsonWriter escapes characters in strings properly/combination of characters is escaped" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/NaN" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/Pos nf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - double/Neg inf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/NaN" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/Pos nf" duration="{duration}"/> + <testCase name="JsonWriter serializes non-finite FP using Python spelling - float/Neg inf" duration="{duration}"/> <testCase name="JsonWriter serializes numbers independently of the global locale" duration="{duration}"/> </file> <file path="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp"> diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 7e9a19d6..4ac7f09f 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -2054,6 +2054,18 @@ ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" # JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "NaN" for: "NaN" == "NaN" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "Infinity" for: "Infinity" == "Infinity" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "NaN" for: "NaN" == "NaN" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "Infinity" for: "Infinity" == "Infinity" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" # JsonWriter serializes numbers independently of the global locale ok {test-number} - sstream.str(), ContainsSubstring( "\"double\": 1.5," ) && ContainsSubstring( "\"int\": 1234567," ) && ContainsSubstring( "\"bool-1\": true," ) && ContainsSubstring( "\"bool-2\": false," ) && ContainsSubstring( "\"array\": [\n 2.5,\n 1234567\n ]\n}" ) for: "{ "double": 1.5, "int": 1234567, "bool-1": true, "bool-2": false, "array": [ 2.5, 1234567 ] }" ( contains: ""double": 1.5," and contains: ""int": 1234567," and contains: ""bool-1": true," and contains: ""bool-2": false," and contains: ""array": [ 2.5, 1234567 ] }" ) # Lambdas in assertions @@ -4853,5 +4865,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2429 +1..2435 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index edcb7813..3f1d56aa 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -2052,6 +2052,18 @@ ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" # JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "NaN" for: "NaN" == "NaN" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "Infinity" for: "Infinity" == "Infinity" +# JsonWriter serializes non-finite FP using Python spelling - double +ok {test-number} - sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "NaN" for: "NaN" == "NaN" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "Infinity" for: "Infinity" == "Infinity" +# JsonWriter serializes non-finite FP using Python spelling - float +ok {test-number} - sstream.str() == "-Infinity" for: "-Infinity" == "-Infinity" # JsonWriter serializes numbers independently of the global locale ok {test-number} - sstream.str(), ContainsSubstring( "\"double\": 1.5," ) && ContainsSubstring( "\"int\": 1234567," ) && ContainsSubstring( "\"bool-1\": true," ) && ContainsSubstring( "\"bool-2\": false," ) && ContainsSubstring( "\"array\": [\n 2.5,\n 1234567\n ]\n}" ) for: "{ "double": 1.5, "int": 1234567, "bool-1": true, "bool-2": false, "array": [ 2.5, 1234567 ] }" ( contains: ""double": 1.5," and contains: ""int": 1234567," and contains: ""bool-1": true," and contains: ""bool-2": false," and contains: ""array": [ 2.5, 1234567 ] }" ) # Lambdas in assertions @@ -4842,5 +4854,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2429 +1..2435 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index fc65c1c6..16fe73f9 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -470,6 +470,10 @@ ##teamcity[testFinished name='JsonWriter' duration="{duration}"] ##teamcity[testStarted name='JsonWriter escapes characters in strings properly'] ##teamcity[testFinished name='JsonWriter escapes characters in strings properly' duration="{duration}"] +##teamcity[testStarted name='JsonWriter serializes non-finite FP using Python spelling - double'] +##teamcity[testFinished name='JsonWriter serializes non-fini |