forked from cryptonotefoundation/cryptonote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestJsonValue.cpp
executable file
·54 lines (43 loc) · 1.03 KB
/
TestJsonValue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "gtest/gtest.h"
#include <Common/JsonValue.h>
using Common::JsonValue;
namespace {
std::vector<std::string> goodPatterns{
"{}",
" {} ",
" { } ",
"100",
"[10,20,30]",
" [ 10 , \n 20 , \n 30 ] ",
"{\"prop\": 100}",
"{\"prop\": 100, \"prop2\": [100, 20, 30] }",
"{\"prop\": 100, \"prop2\": { \"p\":\"test\" } }",
};
std::vector<std::string> badPatterns{
"",
"1..2",
"\n\n",
"{",
"[",
"[100,",
"[[]",
"\"",
"{\"prop: 100 }",
"{\"prop\" 100 }",
"{ prop: 100 }",
};
}
TEST(JsonValue, testGoodPatterns) {
for (const auto& p : goodPatterns) {
std::cout << "Pattern: " << p << std::endl;
ASSERT_NO_THROW(Common::JsonValue::fromString(p));
}
}
TEST(JsonValue, testBadPatterns) {
for (const auto& p : badPatterns) {
ASSERT_ANY_THROW(Common::JsonValue::fromString(p));
}
}