/
test_datanode.cpp
72 lines (60 loc) · 1.76 KB
/
test_datanode.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "es-test.hpp"
// Include only the tested class's header.
#include "../../source/DataNode.h"
// ... and any system includes needed for the test file.
#include <string>
#include <vector>
namespace { // test namespace
// #region mock data
// Insert file-local data here, e.g. classes, structs, or fixtures that will be useful
// to help test this class/method.
// #endregion mock data
// #region unit tests
SCENARIO( "Creating a DataNode", "[DataNode]") {
const DataNode root;
GIVEN( "When created" ) {
THEN( "it has the correct default properties" ) {
CHECK( root.Size() == 0 );
CHECK_FALSE( root.HasChildren() );
CHECK( root.Tokens().empty() );
}
THEN( "it preallocates capacity for tokens" ) {
CHECK( root.Tokens().capacity() == 4 );
}
}
GIVEN( "When created without a parent" ) {
THEN( "it prints its token trace at the correct level" ) {
CHECK( root.PrintTrace() == 0 );
}
}
GIVEN( "When created with a parent" ) {
const DataNode child(&root);
THEN( "it still has the correct default properties" ) {
CHECK( child.Size() == 0 );
CHECK_FALSE( child.HasChildren() );
CHECK( child.Tokens().empty() );
}
THEN( "it prints its token trace at the correct level" ) {
CHECK( child.PrintTrace() == 2 );
}
THEN( "no automatic registration with the parent is done" ) {
CHECK_FALSE( root.HasChildren() );
}
}
}
SCENARIO( "Determining if a token is numeric", "[IsNumber][Parsing][DataNode]" ) {
GIVEN( "An integer string" ) {
THEN( "IsNumber returns true" ) {
auto strNum = GENERATE(as<std::string>{}
, "1"
, "10"
, "100"
, "1000000000000000"
);
CAPTURE( strNum ); // Log the value if the assertion fails.
CHECK( DataNode::IsNumber(strNum) );
}
}
}
// #endregion unit tests
} // test namespace