Skip to content

Commit c459f31

Browse files
doc: improve the hello-world test and doc
1 parent 200c991 commit c459f31

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To begin with we will see an example of parsing a hello-world program and see wh
2727

2828
int main()
2929
{
30-
std::cout << "Hello World!\n";
30+
std::cout << "Hello, World!\n";
3131

3232
return 0;
3333
}
@@ -74,6 +74,14 @@ TEST_CASE("Parsing hello world program")
7474
cppast::CppConstBinomialExprEPtr coutHelloWorld = mainBodyMembers[0];
7575
REQUIRE(coutHelloWorld);
7676
CHECK(coutHelloWorld->oper() == cppast::CppBinaryOperator::INSERTION);
77+
78+
cppast::CppConstNameExprEPtr coutOperand1 = &(coutHelloWorld->term1());
79+
REQUIRE(coutOperand1);
80+
CHECK(coutOperand1->value() == "std::cout");
81+
82+
cppast::CppConstStringLiteralExprEPtr coutOperand2 = &(coutHelloWorld->term2());
83+
REQUIRE(coutOperand2);
84+
CHECK(coutOperand2->value() == "\"Hello, World!\\n\"");
7785
}
7886

7987
```

cppparser/test/unit/test-files/hello-world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int main()
44
{
5-
std::cout << "Hello World!\n";
5+
std::cout << "Hello, World!\n";
66

77
return 0;
88
}

cppparser/test/unit/test-hello-world.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ TEST_CASE("Parsing hello world program")
3131
cppast::CppConstBinomialExprEPtr coutHelloWorld = mainBodyMembers[0];
3232
REQUIRE(coutHelloWorld);
3333
CHECK(coutHelloWorld->oper() == cppast::CppBinaryOperator::INSERTION);
34+
35+
cppast::CppConstNameExprEPtr coutOperand1 = &(coutHelloWorld->term1());
36+
REQUIRE(coutOperand1);
37+
CHECK(coutOperand1->value() == "std::cout");
38+
39+
cppast::CppConstStringLiteralExprEPtr coutOperand2 = &(coutHelloWorld->term2());
40+
REQUIRE(coutOperand2);
41+
CHECK(coutOperand2->value() == "\"Hello, World!\\n\"");
3442
}

0 commit comments

Comments
 (0)