Fix special character escaping in JsonWriter

This commit is contained in:
Martin Hořeňovský 2023-11-14 23:35:22 +01:00
parent 7bf136b501
commit 733b901dd2
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
19 changed files with 557 additions and 45 deletions

View File

@ -47,10 +47,26 @@ namespace Catch {
m_sstream << value;
while ( true ) {
char c = m_sstream.get();
if ( m_sstream.eof() ) { break; }
// see https://www.json.org/json-en.html, string definition for the escape list
if ( c == '"' ) {
m_os << '\\' << '"';
m_os << "\\\"";
} else if ( c == '\\' ) {
m_os << "\\\\";
// Note that while forward slash _can_ be escaped, it
// does not have to be, if JSON is not further embedded
// somewhere where forward slash is meaningful.
} else if ( c == '\b' ) {
m_os << "\\b";
} else if ( c == '\f' ) {
m_os << "\\f";
} else if ( c == '\n' ) {
m_os << "\\n";
} else if ( c == '\r' ) {
m_os << "\\r";
} else if ( c == '\t') {
m_os << "\\t";
} else {
m_os << c;
}

View File

@ -171,6 +171,7 @@ Nor would this
:test-result: XFAIL Inequality checks that should fail
:test-result: PASS Inequality checks that should succeed
:test-result: PASS JsonWriter
:test-result: PASS JsonWriter escapes charaters in strings properly
:test-result: PASS Lambdas in assertions
:test-result: PASS Less-than inequalities with different epsilons
:test-result: PASS ManuallyRegistered

View File

@ -169,6 +169,7 @@
:test-result: XFAIL Inequality checks that should fail
:test-result: PASS Inequality checks that should succeed
:test-result: PASS JsonWriter
:test-result: PASS JsonWriter escapes charaters in strings properly
:test-result: PASS Lambdas in assertions
:test-result: PASS Less-than inequalities with different epsilons
:test-result: PASS ManuallyRegistered

View File

@ -1055,7 +1055,15 @@ Json.tests.cpp:<line number>: passed: stream.str() == "[\n]" for: "[
"[
]"
Json.tests.cpp:<line number>: passed: stream.str() == "\"custom\"" for: ""custom"" == ""custom""
Json.tests.cpp:<line number>: passed: stream.str() == "\"\\\"\"" for: ""\""" == ""\"""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\"\"" for: ""\""" == ""\"""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"/\"" for: ""/"" == ""/""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\b\"" for: ""\b"" == ""\b""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\f\"" for: ""\f"" == ""\f""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\n\"" for: ""\n"" == ""\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""
Compilation.tests.cpp:<line number>: passed: []() { return true; }() for: true
Approx.tests.cpp:<line number>: passed: d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 )
Approx.tests.cpp:<line number>: passed: d <= Approx( 1.23 ) for: 1.23 <= Approx( 1.23 )
@ -2675,7 +2683,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: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected
test cases: 415 | 310 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2254 | 2073 passed | 146 failed | 35 failed as expected

View File

@ -1053,7 +1053,15 @@ Json.tests.cpp:<line number>: passed: stream.str() == "[\n]" for: "[
"[
]"
Json.tests.cpp:<line number>: passed: stream.str() == "\"custom\"" for: ""custom"" == ""custom""
Json.tests.cpp:<line number>: passed: stream.str() == "\"\\\"\"" for: ""\""" == ""\"""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\"\"" for: ""\""" == ""\"""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"/\"" for: ""/"" == ""/""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\b\"" for: ""\b"" == ""\b""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\f\"" for: ""\f"" == ""\f""
Json.tests.cpp:<line number>: passed: sstream.str() == "\"\\n\"" for: ""\n"" == ""\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""
Compilation.tests.cpp:<line number>: passed: []() { return true; }() for: true
Approx.tests.cpp:<line number>: passed: d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 )
Approx.tests.cpp:<line number>: passed: d <= Approx( 1.23 ) for: 1.23 <= Approx( 1.23 )
@ -2664,7 +2672,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: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected
test cases: 415 | 310 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2254 | 2073 passed | 146 failed | 35 failed as expected

View File

@ -1588,6 +1588,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 414 | 323 passed | 70 failed | 7 skipped | 14 failed as expected
assertions: 2229 | 2065 passed | 129 failed | 35 failed as expected
test cases: 415 | 324 passed | 70 failed | 7 skipped | 14 failed as expected
assertions: 2237 | 2073 passed | 129 failed | 35 failed as expected

View File

@ -7436,17 +7436,113 @@ with expansion:
""custom"" == ""custom""
-------------------------------------------------------------------------------
JsonWriter
String with a quote shall be espaced
JsonWriter escapes charaters in strings properly
Quote in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( stream.str() == "\"\\\"\"" )
REQUIRE( sstream.str() == "\"\\\"\"" )
with expansion:
""\""" == ""\"""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Backslash in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\\\\"" )
with expansion:
""\\"" == ""\\""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Forward slash in a string is **not** escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"/\"" )
with expansion:
""/"" == ""/""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Backspace in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\b\"" )
with expansion:
""\b"" == ""\b""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Formfeed in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\f\"" )
with expansion:
""\f"" == ""\f""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
linefeed in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\n\"" )
with expansion:
""\n"" == ""\n""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
carriage return in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\r\"" )
with expansion:
""\r"" == ""\r""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
tab in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\t\"" )
with expansion:
""\t"" == ""\t""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
combination of characters is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\\\/\\t\\r\\n\"" )
with expansion:
""\\/\t\r\n"" == ""\\/\t\r\n""
-------------------------------------------------------------------------------
Lambdas in assertions
-------------------------------------------------------------------------------
@ -18595,6 +18691,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected
test cases: 415 | 310 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2254 | 2073 passed | 146 failed | 35 failed as expected

View File

@ -7434,17 +7434,113 @@ with expansion:
""custom"" == ""custom""
-------------------------------------------------------------------------------
JsonWriter
String with a quote shall be espaced
JsonWriter escapes charaters in strings properly
Quote in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( stream.str() == "\"\\\"\"" )
REQUIRE( sstream.str() == "\"\\\"\"" )
with expansion:
""\""" == ""\"""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Backslash in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\\\\"" )
with expansion:
""\\"" == ""\\""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Forward slash in a string is **not** escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"/\"" )
with expansion:
""/"" == ""/""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Backspace in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\b\"" )
with expansion:
""\b"" == ""\b""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
Formfeed in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\f\"" )
with expansion:
""\f"" == ""\f""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
linefeed in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\n\"" )
with expansion:
""\n"" == ""\n""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
carriage return in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\r\"" )
with expansion:
""\r"" == ""\r""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
tab in a string is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\t\"" )
with expansion:
""\t"" == ""\t""
-------------------------------------------------------------------------------
JsonWriter escapes charaters in strings properly
combination of characters is escaped
-------------------------------------------------------------------------------
Json.tests.cpp:<line number>
...............................................................................
Json.tests.cpp:<line number>: PASSED:
REQUIRE( sstream.str() == "\"\\\\/\\t\\r\\n\"" )
with expansion:
""\\/\t\r\n"" == ""\\/\t\r\n""
-------------------------------------------------------------------------------
Lambdas in assertions
-------------------------------------------------------------------------------
@ -18584,6 +18680,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 414 | 309 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2246 | 2065 passed | 146 failed | 35 failed as expected
test cases: 415 | 310 passed | 85 failed | 6 skipped | 14 failed as expected
assertions: 2254 | 2073 passed | 146 failed | 35 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2258" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2266" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@ -862,7 +862,15 @@ at Condition.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="JsonWriter/Moved from JsonObjectWriter shall not insert superfluous brace" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/Moved from JsonArrayWriter shall not insert superfluous bracket" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/Custom class shall be quoted" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/String with a quote shall be espaced" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Quote in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Backslash in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Forward slash in a string is **not** escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Backspace in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Formfeed in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/linefeed in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/carriage return in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/tab in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/combination of characters is escaped" 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"/>
<testcase classname="<exe-name>.global" name="ManuallyRegistered" time="{duration}" status="run"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2258" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" skipped="12" tests="2266" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="&quot;*&quot; ~[!nonportable] ~[!benchmark] ~[approvals]"/>
@ -861,7 +861,15 @@ at Condition.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="JsonWriter/Moved from JsonObjectWriter shall not insert superfluous brace" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/Moved from JsonArrayWriter shall not insert superfluous bracket" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/Custom class shall be quoted" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter/String with a quote shall be espaced" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Quote in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Backslash in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Forward slash in a string is **not** escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Backspace in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/Formfeed in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/linefeed in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/carriage return in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/tab in a string is escaped" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="JsonWriter escapes charaters in strings properly/combination of characters is escaped" 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"/>
<testcase classname="<exe-name>.global" name="ManuallyRegistered" time="{duration}" status="run"/>

View File

@ -140,7 +140,15 @@ at AssertionHandler.tests.cpp:<line number>
<testCase name="JsonWriter/Moved from JsonObjectWriter shall not insert superfluous brace" duration="{duration}"/>
<testCase name="JsonWriter/Moved from JsonArrayWriter shall not insert superfluous bracket" duration="{duration}"/>
<testCase name="JsonWriter/Custom class shall be quoted" duration="{duration}"/>
<testCase name="JsonWriter/String with a quote shall be espaced" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Quote in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Backslash in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Forward slash in a string is **not** escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Backspace in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Formfeed in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/linefeed in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/carriage return in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/tab in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/combination of characters is escaped" duration="{duration}"/>
</file>
<file path="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp">
<testCase name="Parse uints/proper inputs" duration="{duration}"/>

View File

@ -139,7 +139,15 @@ at AssertionHandler.tests.cpp:<line number>
<testCase name="JsonWriter/Moved from JsonObjectWriter shall not insert superfluous brace" duration="{duration}"/>
<testCase name="JsonWriter/Moved from JsonArrayWriter shall not insert superfluous bracket" duration="{duration}"/>
<testCase name="JsonWriter/Custom class shall be quoted" duration="{duration}"/>
<testCase name="JsonWriter/String with a quote shall be espaced" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Quote in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Backslash in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Forward slash in a string is **not** escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Backspace in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/Formfeed in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/linefeed in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/carriage return in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/tab in a string is escaped" duration="{duration}"/>
<testCase name="JsonWriter escapes charaters in strings properly/combination of characters is escaped" duration="{duration}"/>
</file>
<file path="tests/<exe-name>/IntrospectiveTests/Parse.tests.cpp">
<testCase name="Parse uints/proper inputs" duration="{duration}"/>

View File

@ -1884,8 +1884,24 @@ ok {test-number} - stream.str() == "{\n}" for: "{ }" == "{ }"
ok {test-number} - stream.str() == "[\n]" for: "[ ]" == "[ ]"
# JsonWriter
ok {test-number} - stream.str() == "\"custom\"" for: ""custom"" == ""custom""
# JsonWriter
ok {test-number} - stream.str() == "\"\\\"\"" for: ""\""" == ""\"""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\"\"" for: ""\""" == ""\"""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"/\"" for: ""/"" == ""/""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\b\"" for: ""\b"" == ""\b""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\f\"" for: ""\f"" == ""\f""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\n\"" for: ""\n"" == ""\n""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n""
# Lambdas in assertions
ok {test-number} - []() { return true; }() for: true
# Less-than inequalities with different epsilons
@ -4521,5 +4537,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2258
1..2266

View File

@ -1882,8 +1882,24 @@ ok {test-number} - stream.str() == "{\n}" for: "{ }" == "{ }"
ok {test-number} - stream.str() == "[\n]" for: "[ ]" == "[ ]"
# JsonWriter
ok {test-number} - stream.str() == "\"custom\"" for: ""custom"" == ""custom""
# JsonWriter
ok {test-number} - stream.str() == "\"\\\"\"" for: ""\""" == ""\"""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\"\"" for: ""\""" == ""\"""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"/\"" for: ""/"" == ""/""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\b\"" for: ""\b"" == ""\b""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\f\"" for: ""\f"" == ""\f""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\n\"" for: ""\n"" == ""\n""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t""
# JsonWriter escapes charaters in strings properly
ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n""
# Lambdas in assertions
ok {test-number} - []() { return true; }() for: true
# Less-than inequalities with different epsilons
@ -4510,5 +4526,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2258
1..2266

View File

@ -422,6 +422,8 @@
##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"]
##teamcity[testStarted name='JsonWriter']
##teamcity[testFinished name='JsonWriter' duration="{duration}"]
##teamcity[testStarted name='JsonWriter escapes charaters in strings properly']
##teamcity[testFinished name='JsonWriter escapes charaters in strings properly' duration="{duration}"]
##teamcity[testStarted name='Lambdas in assertions']
##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"]
##teamcity[testStarted name='Less-than inequalities with different epsilons']

View File

@ -422,6 +422,8 @@
##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"]
##teamcity[testStarted name='JsonWriter']
##teamcity[testFinished name='JsonWriter' duration="{duration}"]
##teamcity[testStarted name='JsonWriter escapes charaters in strings properly']
##teamcity[testFinished name='JsonWriter escapes charaters in strings properly' duration="{duration}"]
##teamcity[testStarted name='Lambdas in assertions']
##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"]
##teamcity[testStarted name='Less-than inequalities with different epsilons']

View File

@ -8946,10 +8946,13 @@ C
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="String with a quote shall be espaced" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="JsonWriter escapes charaters in strings properly" tags="[JsonWriter]" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Section name="Quote in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
stream.str() == "\"\\\"\""
sstream.str() == "\"\\\"\""
</Original>
<Expanded>
""\""" == ""\"""
@ -8957,6 +8960,94 @@ C
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Backslash in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\\\\""
</Original>
<Expanded>
""\\"" == ""\\""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Forward slash in a string is **not** escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"/\""
</Original>
<Expanded>
""/"" == ""/""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Backspace in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\b\""
</Original>
<Expanded>
""\b"" == ""\b""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Formfeed in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\f\""
</Original>
<Expanded>
""\f"" == ""\f""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="linefeed in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\n\""
</Original>
<Expanded>
""\n"" == ""\n""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="carriage return in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\r\""
</Original>
<Expanded>
""\r"" == ""\r""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="tab in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\t\""
</Original>
<Expanded>
""\t"" == ""\t""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="combination of characters is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\\\/\\t\\r\\n\""
</Original>
<Expanded>
""\\/\t\r\n"" == ""\\/\t\r\n""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="Lambdas in assertions" filename="tests/<exe-name>/UsageTests/Compilation.tests.cpp" >
@ -21562,6 +21653,6 @@ b1!
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2065" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="309" failures="85" expectedFailures="14" skips="6"/>
<OverallResults successes="2073" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="310" failures="85" expectedFailures="14" skips="6"/>
</Catch2TestRun>

View File

@ -8946,10 +8946,13 @@ C
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="String with a quote shall be espaced" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="JsonWriter escapes charaters in strings properly" tags="[JsonWriter]" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Section name="Quote in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
stream.str() == "\"\\\"\""
sstream.str() == "\"\\\"\""
</Original>
<Expanded>
""\""" == ""\"""
@ -8957,6 +8960,94 @@ C
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Backslash in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\\\\""
</Original>
<Expanded>
""\\"" == ""\\""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Forward slash in a string is **not** escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"/\""
</Original>
<Expanded>
""/"" == ""/""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Backspace in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\b\""
</Original>
<Expanded>
""\b"" == ""\b""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="Formfeed in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\f\""
</Original>
<Expanded>
""\f"" == ""\f""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="linefeed in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\n\""
</Original>
<Expanded>
""\n"" == ""\n""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="carriage return in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\r\""
</Original>
<Expanded>
""\r"" == ""\r""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="tab in a string is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\t\""
</Original>
<Expanded>
""\t"" == ""\t""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<Section name="combination of characters is escaped" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Json.tests.cpp" >
<Original>
sstream.str() == "\"\\\\/\\t\\r\\n\""
</Original>
<Expanded>
""\\/\t\r\n"" == ""\\/\t\r\n""
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/>
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<TestCase name="Lambdas in assertions" filename="tests/<exe-name>/UsageTests/Compilation.tests.cpp" >
@ -21561,6 +21652,6 @@ b1!
</Section>
<OverallResult success="true" skips="0"/>
</TestCase>
<OverallResults successes="2065" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="309" failures="85" expectedFailures="14" skips="6"/>
<OverallResults successes="2073" failures="146" expectedFailures="35" skips="12"/>
<OverallResultsCases successes="310" failures="85" expectedFailures="14" skips="6"/>
</Catch2TestRun>

View File

@ -14,14 +14,14 @@
namespace {
struct Custom {};
std::ostream& operator<<( std::ostream& os, Custom const& ) {
static std::ostream& operator<<( std::ostream& os, Custom const& ) {
return os << "custom";
}
} // namespace
TEST_CASE( "JsonWriter", "[JSON][JsonWriter]" ) {
std::stringstream stream{};
std::stringstream stream;
SECTION( "Newly constructed JsonWriter does nothing" ) {
Catch::JsonValueWriter writer{ stream };
REQUIRE( stream.str() == "" );
@ -109,8 +109,44 @@ TEST_CASE( "JsonWriter", "[JSON][JsonWriter]" ) {
Catch::JsonValueWriter{ stream }.write( Custom{} );
REQUIRE( stream.str() == "\"custom\"" );
}
SECTION( "String with a quote shall be espaced" ) {
Catch::JsonValueWriter{ stream }.write( "\"" );
REQUIRE( stream.str() == "\"\\\"\"" );
}
TEST_CASE( "JsonWriter escapes charaters in strings properly", "[JsonWriter]" ) {
std::stringstream sstream;
SECTION( "Quote in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\"" );
REQUIRE( sstream.str() == "\"\\\"\"" );
}
SECTION("Backslash in a string is escaped") {
Catch::JsonValueWriter{ sstream }.write( "\\" );
REQUIRE( sstream.str() == "\"\\\\\"" );
}
SECTION( "Forward slash in a string is **not** escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "/" );
REQUIRE( sstream.str() == "\"/\"" );
}
SECTION( "Backspace in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\b" );
REQUIRE( sstream.str() == "\"\\b\"" );
}
SECTION( "Formfeed in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\f" );
REQUIRE( sstream.str() == "\"\\f\"" );
}
SECTION( "linefeed in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\n" );
REQUIRE( sstream.str() == "\"\\n\"" );
}
SECTION( "carriage return in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\r" );
REQUIRE( sstream.str() == "\"\\r\"" );
}
SECTION( "tab in a string is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\t" );
REQUIRE( sstream.str() == "\"\\t\"" );
}
SECTION( "combination of characters is escaped" ) {
Catch::JsonValueWriter{ sstream }.write( "\\/\t\r\n" );
REQUIRE( sstream.str() == "\"\\\\/\\t\\r\\n\"" );
}
}