MCPcopy Create free account
hub / github.com/pboettch/json-schema-validator / testStringFormat

Function testStringFormat

test/string-format-check-test.cpp:6–34  ·  view source on GitHub ↗

@return number of failed tests */

Source from the content-addressed store, hash-verified

4
5/** @return number of failed tests */
6size_t
7testStringFormat(const std::string &format,
8 const std::vector<std::pair<std::string, bool>> &stringValidTests)
9{
10 size_t numberOfErrors = 0;
11
12 for (auto stringValid = stringValidTests.begin(); stringValid != stringValidTests.end(); ++stringValid) {
13 std::cout << "[INFO] Testing " << format << ": " << stringValid->first << "\n";
14
15 try {
16 nlohmann::json_schema::default_string_format_check(format, stringValid->first);
17
18 if (!stringValid->second) {
19 ++numberOfErrors;
20 std::cerr << "[ERROR] String with " << format << " format '" << stringValid->first
21 << "' validated even though it should NOT!\n";
22 }
23 } catch (std::exception &exception) {
24 std::cout << "[INFO] Validation failed with: " << exception.what() << "\n";
25 if (stringValid->second) {
26 ++numberOfErrors;
27 std::cerr << "[ERROR] String with " << format << " format '" << stringValid->first
28 << "' did NOT validate even though it should!\n";
29 }
30 }
31 }
32
33 return numberOfErrors;
34}
35
36int main()
37{

Callers 1

mainFunction · 0.85

Calls 2

whatMethod · 0.80

Tested by

no test coverage detected