Skip to content

Commit b9fd92b

Browse files
committed
test, fix: correct the unit test
The unit test only tested for the '|' literal indicator. But in some cases it should have been '|-'. If a string does not end with an '\n' it has to use '|-' to indicate that the trailing new line is not part of the string. Additionally, I also added a explicit test for '|+'.
1 parent 1870e4b commit b9fd92b

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

test/integration/emitter_test.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ TEST_F(EmitterTest, StringFormat) {
101101
out << "string";
102102
out << EndSeq;
103103

104-
ExpectEmit("- 'string'\n- \"string\"\n- |\n string");
104+
ExpectEmit("- 'string'\n- \"string\"\n- |-\n string");
105105
}
106106

107107
TEST_F(EmitterTest, IntBase) {
@@ -409,7 +409,7 @@ TEST_F(EmitterTest, ScalarFormat) {
409409
"- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit "
410410
"double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted "
411411
"scalar\"\n- a "
412-
"non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n "
412+
"non-\"auto-detected\" double-quoted scalar\n- |-\n literal scalar\n "
413413
" "
414414
"that may span\n many, many\n lines and have \"whatever\" "
415415
"crazy\tsymbols that we like");
@@ -424,18 +424,34 @@ TEST_F(EmitterTest, LiteralWithoutTrailingSpaces) {
424424
out << YAML::EndMap;
425425

426426
ExpectEmit(
427-
"key: |\n"
427+
"key: |-\n"
428428
" expect that with two newlines\n\n"
429429
" no spaces are emitted in the empty line");
430430
}
431431

432+
TEST_F(EmitterTest, LiteralWithAndWithoutTrailingEmptyLines) {
433+
out << BeginSeq;
434+
out << Literal << "A\nB";
435+
out << Literal << "A\nB\n";
436+
out << Literal << "A\nB\n\n\n";
437+
out << "something";
438+
out << EndSeq;
439+
440+
ExpectEmit(
441+
"- |-\n A\n B\n"
442+
"- |\n A\n B\n"
443+
"- |+\n A\n B\n\n\n"
444+
"- something");
445+
}
446+
447+
432448
TEST_F(EmitterTest, AutoLongKeyScalar) {
433449
out << BeginMap;
434450
out << Key << Literal << "multi-line\nscalar";
435451
out << Value << "and its value";
436452
out << EndMap;
437453

438-
ExpectEmit("? |\n multi-line\n scalar\n: and its value");
454+
ExpectEmit("? |-\n multi-line\n scalar\n: and its value");
439455
}
440456

441457
TEST_F(EmitterTest, LongKeyFlowMap) {
@@ -717,7 +733,7 @@ TEST_F(EmitterTest, ComplexDoc) {
717733
"given: Dorothy\n family: Gale\nitems:\n - part_no: A4786\n "
718734
"descrip: Water Bucket (Filled)\n price: 1.47\n quantity: 4\n - "
719735
"part_no: E1628\n descrip: High Heeled \"Ruby\" Slippers\n price: "
720-
"100.27\n quantity: 1\nbill-to: &id001\n street: |\n 123 Tornado "
736+
"100.27\n quantity: 1\nbill-to: &id001\n street: |-\n 123 Tornado "
721737
"Alley\n Suite 16\n city: East Westville\n state: KS\nship-to: "
722738
"*id001");
723739
}

0 commit comments

Comments
 (0)