Skip to content

Commit 73674dd

Browse files
added simple log formatter
1 parent beb2f98 commit 73674dd

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/sjv/sjv.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,15 @@ namespace sjv
201201
return true;
202202
};
203203

204+
std::string sjv::log2str()
205+
{
206+
std::stringstream s;
207+
208+
for (log_item i: log)
209+
{
210+
s << i.first << ": " << i.second << std::endl;
211+
s << std::endl;
212+
}
213+
return s.str();
214+
}
204215
} // namespace sjv

src/sjv/sjv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ namespace sjv
3636
// message list
3737
typedef std::pair<std::string,std::string> log_item;
3838
std::vector<log_item> log;
39+
40+
// log to string
41+
std::string log2str();
3942
};
4043

4144
} // namespace sjv

tests/test_validator.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST_CASE("single_rule", "[validator]")
2929
sjv::sjv sjv;
3030

3131
REQUIRE(sjv.verify_json(input,rules));
32+
3233
}
3334

3435
TEST_CASE("only_one_rule_can_be_valid", "[validator]")
@@ -189,3 +190,31 @@ TEST_CASE("type_object", "[validator]")
189190
REQUIRE(!sjv.verify_json(input,rules));
190191

191192
}
193+
194+
TEST_CASE("file1", "[validator]")
195+
{
196+
json input = R"(
197+
{
198+
"string1": "teststring"
199+
}
200+
)"_json;
201+
202+
json rules = R"(
203+
[
204+
{
205+
"pointer": "/",
206+
"type": "object",
207+
"required": ["string1"]
208+
}
209+
]
210+
)"_json;
211+
212+
sjv::sjv sjv;
213+
214+
sjv.strict = true;
215+
216+
bool r = sjv.verify_json(input,rules);
217+
std:: string s = sjv.log2str();
218+
INFO(s);
219+
REQUIRE(r);
220+
}

0 commit comments

Comments
 (0)