The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1686 lines
70 KiB

2 months ago
  1. #include "handler_test.h"
  2. #include "specexamples.h" // IWYU pragma: keep
  3. #include "yaml-cpp/yaml.h" // IWYU pragma: keep
  4. #include "gmock/gmock.h"
  5. #include "gtest/gtest.h"
  6. using ::testing::_;
  7. #define EXPECT_THROW_PARSER_EXCEPTION(statement, message) \
  8. ASSERT_THROW(statement, ParserException); \
  9. try { \
  10. statement; \
  11. } catch (const ParserException& e) { \
  12. EXPECT_EQ(e.msg, message); \
  13. }
  14. namespace YAML {
  15. namespace {
  16. typedef HandlerTest HandlerSpecTest;
  17. TEST_F(HandlerSpecTest, Ex2_1_SeqScalars) {
  18. EXPECT_CALL(handler, OnDocumentStart(_));
  19. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  20. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  21. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  22. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  23. EXPECT_CALL(handler, OnSequenceEnd());
  24. EXPECT_CALL(handler, OnDocumentEnd());
  25. Parse(ex2_1);
  26. }
  27. TEST_F(HandlerSpecTest, Ex2_2_MappingScalarsToScalars) {
  28. EXPECT_CALL(handler, OnDocumentStart(_));
  29. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  30. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  31. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  32. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  33. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.278"));
  34. EXPECT_CALL(handler, OnScalar(_, "?", 0, "rbi"));
  35. EXPECT_CALL(handler, OnScalar(_, "?", 0, "147"));
  36. EXPECT_CALL(handler, OnMapEnd());
  37. EXPECT_CALL(handler, OnDocumentEnd());
  38. Parse(ex2_2);
  39. }
  40. TEST_F(HandlerSpecTest, Ex2_3_MappingScalarsToSequences) {
  41. EXPECT_CALL(handler, OnDocumentStart(_));
  42. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  43. EXPECT_CALL(handler, OnScalar(_, "?", 0, "american"));
  44. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  45. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Boston Red Sox"));
  46. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Detroit Tigers"));
  47. EXPECT_CALL(handler, OnScalar(_, "?", 0, "New York Yankees"));
  48. EXPECT_CALL(handler, OnSequenceEnd());
  49. EXPECT_CALL(handler, OnScalar(_, "?", 0, "national"));
  50. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  51. EXPECT_CALL(handler, OnScalar(_, "?", 0, "New York Mets"));
  52. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chicago Cubs"));
  53. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Atlanta Braves"));
  54. EXPECT_CALL(handler, OnSequenceEnd());
  55. EXPECT_CALL(handler, OnMapEnd());
  56. EXPECT_CALL(handler, OnDocumentEnd());
  57. Parse(ex2_3);
  58. }
  59. TEST_F(HandlerSpecTest, Ex2_4_SequenceOfMappings) {
  60. EXPECT_CALL(handler, OnDocumentStart(_));
  61. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  62. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  63. EXPECT_CALL(handler, OnScalar(_, "?", 0, "name"));
  64. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  65. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  66. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  67. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  68. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.278"));
  69. EXPECT_CALL(handler, OnMapEnd());
  70. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  71. EXPECT_CALL(handler, OnScalar(_, "?", 0, "name"));
  72. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  73. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  74. EXPECT_CALL(handler, OnScalar(_, "?", 0, "63"));
  75. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  76. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.288"));
  77. EXPECT_CALL(handler, OnMapEnd());
  78. EXPECT_CALL(handler, OnSequenceEnd());
  79. EXPECT_CALL(handler, OnDocumentEnd());
  80. Parse(ex2_4);
  81. }
  82. TEST_F(HandlerSpecTest, Ex2_5_SequenceOfSequences) {
  83. EXPECT_CALL(handler, OnDocumentStart(_));
  84. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  85. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  86. EXPECT_CALL(handler, OnScalar(_, "?", 0, "name"));
  87. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  88. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  89. EXPECT_CALL(handler, OnSequenceEnd());
  90. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  91. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  92. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  93. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.278"));
  94. EXPECT_CALL(handler, OnSequenceEnd());
  95. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  96. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  97. EXPECT_CALL(handler, OnScalar(_, "?", 0, "63"));
  98. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.288"));
  99. EXPECT_CALL(handler, OnSequenceEnd());
  100. EXPECT_CALL(handler, OnSequenceEnd());
  101. EXPECT_CALL(handler, OnDocumentEnd());
  102. Parse(ex2_5);
  103. }
  104. TEST_F(HandlerSpecTest, Ex2_6_MappingOfMappings) {
  105. EXPECT_CALL(handler, OnDocumentStart(_));
  106. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  107. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  108. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  109. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  110. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  111. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  112. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.278"));
  113. EXPECT_CALL(handler, OnMapEnd());
  114. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  115. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  116. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  117. EXPECT_CALL(handler, OnScalar(_, "?", 0, "63"));
  118. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  119. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.288"));
  120. EXPECT_CALL(handler, OnMapEnd());
  121. EXPECT_CALL(handler, OnMapEnd());
  122. EXPECT_CALL(handler, OnDocumentEnd());
  123. Parse(ex2_6);
  124. }
  125. TEST_F(HandlerSpecTest, Ex2_7_TwoDocumentsInAStream) {
  126. EXPECT_CALL(handler, OnDocumentStart(_));
  127. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  128. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  129. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  130. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  131. EXPECT_CALL(handler, OnSequenceEnd());
  132. EXPECT_CALL(handler, OnDocumentEnd());
  133. EXPECT_CALL(handler, OnDocumentStart(_));
  134. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  135. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chicago Cubs"));
  136. EXPECT_CALL(handler, OnScalar(_, "?", 0, "St Louis Cardinals"));
  137. EXPECT_CALL(handler, OnSequenceEnd());
  138. EXPECT_CALL(handler, OnDocumentEnd());
  139. Parse(ex2_7);
  140. }
  141. TEST_F(HandlerSpecTest, Ex2_8_PlayByPlayFeed) {
  142. EXPECT_CALL(handler, OnDocumentStart(_));
  143. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  144. EXPECT_CALL(handler, OnScalar(_, "?", 0, "time"));
  145. EXPECT_CALL(handler, OnScalar(_, "?", 0, "20:03:20"));
  146. EXPECT_CALL(handler, OnScalar(_, "?", 0, "player"));
  147. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  148. EXPECT_CALL(handler, OnScalar(_, "?", 0, "action"));
  149. EXPECT_CALL(handler, OnScalar(_, "?", 0, "strike (miss)"));
  150. EXPECT_CALL(handler, OnMapEnd());
  151. EXPECT_CALL(handler, OnDocumentEnd());
  152. EXPECT_CALL(handler, OnDocumentStart(_));
  153. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  154. EXPECT_CALL(handler, OnScalar(_, "?", 0, "time"));
  155. EXPECT_CALL(handler, OnScalar(_, "?", 0, "20:03:47"));
  156. EXPECT_CALL(handler, OnScalar(_, "?", 0, "player"));
  157. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  158. EXPECT_CALL(handler, OnScalar(_, "?", 0, "action"));
  159. EXPECT_CALL(handler, OnScalar(_, "?", 0, "grand slam"));
  160. EXPECT_CALL(handler, OnMapEnd());
  161. EXPECT_CALL(handler, OnDocumentEnd());
  162. Parse(ex2_8);
  163. }
  164. TEST_F(HandlerSpecTest, Ex2_9_SingleDocumentWithTwoComments) {
  165. EXPECT_CALL(handler, OnDocumentStart(_));
  166. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  167. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  168. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  169. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  170. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  171. EXPECT_CALL(handler, OnSequenceEnd());
  172. EXPECT_CALL(handler, OnScalar(_, "?", 0, "rbi"));
  173. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  174. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  175. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  176. EXPECT_CALL(handler, OnSequenceEnd());
  177. EXPECT_CALL(handler, OnMapEnd());
  178. EXPECT_CALL(handler, OnDocumentEnd());
  179. Parse(ex2_9);
  180. }
  181. TEST_F(HandlerSpecTest, Ex2_10_SimpleAnchor) {
  182. EXPECT_CALL(handler, OnDocumentStart(_));
  183. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  184. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  185. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  186. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  187. EXPECT_CALL(handler, OnAnchor(_, "SS"));
  188. EXPECT_CALL(handler, OnScalar(_, "?", 1, "Sammy Sosa"));
  189. EXPECT_CALL(handler, OnSequenceEnd());
  190. EXPECT_CALL(handler, OnScalar(_, "?", 0, "rbi"));
  191. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  192. EXPECT_CALL(handler, OnAlias(_, 1));
  193. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  194. EXPECT_CALL(handler, OnSequenceEnd());
  195. EXPECT_CALL(handler, OnMapEnd());
  196. EXPECT_CALL(handler, OnDocumentEnd());
  197. Parse(ex2_10);
  198. }
  199. TEST_F(HandlerSpecTest, Ex2_11_MappingBetweenSequences) {
  200. EXPECT_CALL(handler, OnDocumentStart(_));
  201. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  202. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  203. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Detroit Tigers"));
  204. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chicago cubs"));
  205. EXPECT_CALL(handler, OnSequenceEnd());
  206. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  207. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-07-23"));
  208. EXPECT_CALL(handler, OnSequenceEnd());
  209. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  210. EXPECT_CALL(handler, OnScalar(_, "?", 0, "New York Yankees"));
  211. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Atlanta Braves"));
  212. EXPECT_CALL(handler, OnSequenceEnd());
  213. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  214. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-07-02"));
  215. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-08-12"));
  216. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-08-14"));
  217. EXPECT_CALL(handler, OnSequenceEnd());
  218. EXPECT_CALL(handler, OnMapEnd());
  219. EXPECT_CALL(handler, OnDocumentEnd());
  220. Parse(ex2_11);
  221. }
  222. TEST_F(HandlerSpecTest, Ex2_12_CompactNestedMapping) {
  223. EXPECT_CALL(handler, OnDocumentStart(_));
  224. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  225. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  226. EXPECT_CALL(handler, OnScalar(_, "?", 0, "item"));
  227. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Super Hoop"));
  228. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quantity"));
  229. EXPECT_CALL(handler, OnScalar(_, "?", 0, "1"));
  230. EXPECT_CALL(handler, OnMapEnd());
  231. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  232. EXPECT_CALL(handler, OnScalar(_, "?", 0, "item"));
  233. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Basketball"));
  234. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quantity"));
  235. EXPECT_CALL(handler, OnScalar(_, "?", 0, "4"));
  236. EXPECT_CALL(handler, OnMapEnd());
  237. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  238. EXPECT_CALL(handler, OnScalar(_, "?", 0, "item"));
  239. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Big Shoes"));
  240. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quantity"));
  241. EXPECT_CALL(handler, OnScalar(_, "?", 0, "1"));
  242. EXPECT_CALL(handler, OnMapEnd());
  243. EXPECT_CALL(handler, OnSequenceEnd());
  244. EXPECT_CALL(handler, OnDocumentEnd());
  245. Parse(ex2_12);
  246. }
  247. TEST_F(HandlerSpecTest, Ex2_13_InLiteralsNewlinesArePreserved) {
  248. EXPECT_CALL(handler, OnDocumentStart(_));
  249. EXPECT_CALL(handler, OnScalar(_, "!", 0,
  250. "\\//||\\/||\n"
  251. "// || ||__"));
  252. EXPECT_CALL(handler, OnDocumentEnd());
  253. Parse(ex2_13);
  254. }
  255. TEST_F(HandlerSpecTest, Ex2_14_InFoldedScalarsNewlinesBecomeSpaces) {
  256. EXPECT_CALL(handler, OnDocumentStart(_));
  257. EXPECT_CALL(handler,
  258. OnScalar(_, "!", 0,
  259. "Mark McGwire's year was crippled by a knee injury."));
  260. EXPECT_CALL(handler, OnDocumentEnd());
  261. Parse(ex2_14);
  262. }
  263. TEST_F(HandlerSpecTest,
  264. Ex2_15_FoldedNewlinesArePreservedForMoreIndentedAndBlankLines) {
  265. EXPECT_CALL(handler, OnDocumentStart(_));
  266. EXPECT_CALL(
  267. handler,
  268. OnScalar(_, "!", 0,
  269. "Sammy Sosa completed another fine season with great stats.\n"
  270. "\n"
  271. " 63 Home Runs\n"
  272. " 0.288 Batting Average\n"
  273. "\n"
  274. "What a year!"));
  275. EXPECT_CALL(handler, OnDocumentEnd());
  276. Parse(ex2_15);
  277. }
  278. TEST_F(HandlerSpecTest, Ex2_16_IndentationDeterminesScope) {
  279. EXPECT_CALL(handler, OnDocumentStart(_));
  280. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  281. EXPECT_CALL(handler, OnScalar(_, "?", 0, "name"));
  282. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  283. EXPECT_CALL(handler, OnScalar(_, "?", 0, "accomplishment"));
  284. EXPECT_CALL(handler,
  285. OnScalar(_, "!", 0,
  286. "Mark set a major league home run record in 1998.\n"));
  287. EXPECT_CALL(handler, OnScalar(_, "?", 0, "stats"));
  288. EXPECT_CALL(handler, OnScalar(_, "!", 0,
  289. "65 Home Runs\n"
  290. "0.278 Batting Average\n"));
  291. EXPECT_CALL(handler, OnMapEnd());
  292. EXPECT_CALL(handler, OnDocumentEnd());
  293. Parse(ex2_16);
  294. }
  295. TEST_F(HandlerSpecTest, Ex2_17_QuotedScalars) {
  296. EXPECT_CALL(handler, OnDocumentStart(_));
  297. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  298. EXPECT_CALL(handler, OnScalar(_, "?", 0, "unicode"));
  299. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Sosa did fine.\xE2\x98\xBA"));
  300. EXPECT_CALL(handler, OnScalar(_, "?", 0, "control"));
  301. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\b1998\t1999\t2000\n"));
  302. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hex esc"));
  303. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\x0d\x0a is \r\n"));
  304. EXPECT_CALL(handler, OnScalar(_, "?", 0, "single"));
  305. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\"Howdy!\" he cried."));
  306. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quoted"));
  307. EXPECT_CALL(handler, OnScalar(_, "!", 0, " # Not a 'comment'."));
  308. EXPECT_CALL(handler, OnScalar(_, "?", 0, "tie-fighter"));
  309. EXPECT_CALL(handler, OnScalar(_, "!", 0, "|\\-*-/|"));
  310. EXPECT_CALL(handler, OnMapEnd());
  311. EXPECT_CALL(handler, OnDocumentEnd());
  312. Parse(ex2_17);
  313. }
  314. TEST_F(HandlerSpecTest, Ex2_18_MultiLineFlowScalars) {
  315. EXPECT_CALL(handler, OnDocumentStart(_));
  316. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  317. EXPECT_CALL(handler, OnScalar(_, "?", 0, "plain"));
  318. EXPECT_CALL(handler,
  319. OnScalar(_, "?", 0, "This unquoted scalar spans many lines."));
  320. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quoted"));
  321. EXPECT_CALL(handler, OnScalar(_, "!", 0, "So does this quoted scalar.\n"));
  322. EXPECT_CALL(handler, OnMapEnd());
  323. EXPECT_CALL(handler, OnDocumentEnd());
  324. Parse(ex2_18);
  325. }
  326. TEST_F(HandlerSpecTest, Ex2_19_Integers) {
  327. EXPECT_CALL(handler, OnDocumentStart(_));
  328. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  329. EXPECT_CALL(handler, OnScalar(_, "?", 0, "canonical"));
  330. EXPECT_CALL(handler, OnScalar(_, "?", 0, "12345"));
  331. EXPECT_CALL(handler, OnScalar(_, "?", 0, "decimal"));
  332. EXPECT_CALL(handler, OnScalar(_, "?", 0, "+12345"));
  333. EXPECT_CALL(handler, OnScalar(_, "?", 0, "octal"));
  334. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0o14"));
  335. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hexadecimal"));
  336. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0xC"));
  337. EXPECT_CALL(handler, OnMapEnd());
  338. EXPECT_CALL(handler, OnDocumentEnd());
  339. Parse(ex2_19);
  340. }
  341. TEST_F(HandlerSpecTest, Ex2_20_FloatingPoint) {
  342. EXPECT_CALL(handler, OnDocumentStart(_));
  343. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  344. EXPECT_CALL(handler, OnScalar(_, "?", 0, "canonical"));
  345. EXPECT_CALL(handler, OnScalar(_, "?", 0, "1.23015e+3"));
  346. EXPECT_CALL(handler, OnScalar(_, "?", 0, "exponential"));
  347. EXPECT_CALL(handler, OnScalar(_, "?", 0, "12.3015e+02"));
  348. EXPECT_CALL(handler, OnScalar(_, "?", 0, "fixed"));
  349. EXPECT_CALL(handler, OnScalar(_, "?", 0, "1230.15"));
  350. EXPECT_CALL(handler, OnScalar(_, "?", 0, "negative infinity"));
  351. EXPECT_CALL(handler, OnScalar(_, "?", 0, "-.inf"));
  352. EXPECT_CALL(handler, OnScalar(_, "?", 0, "not a number"));
  353. EXPECT_CALL(handler, OnScalar(_, "?", 0, ".NaN"));
  354. EXPECT_CALL(handler, OnMapEnd());
  355. EXPECT_CALL(handler, OnDocumentEnd());
  356. Parse(ex2_20);
  357. }
  358. TEST_F(HandlerSpecTest, Ex2_21_Miscellaneous) {
  359. EXPECT_CALL(handler, OnDocumentStart(_));
  360. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  361. EXPECT_CALL(handler, OnNull(_, 0));
  362. EXPECT_CALL(handler, OnNull(_, 0));
  363. EXPECT_CALL(handler, OnScalar(_, "?", 0, "booleans"));
  364. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  365. EXPECT_CALL(handler, OnScalar(_, "?", 0, "true"));
  366. EXPECT_CALL(handler, OnScalar(_, "?", 0, "false"));
  367. EXPECT_CALL(handler, OnSequenceEnd());
  368. EXPECT_CALL(handler, OnScalar(_, "?", 0, "string"));
  369. EXPECT_CALL(handler, OnScalar(_, "!", 0, "012345"));
  370. EXPECT_CALL(handler, OnMapEnd());
  371. EXPECT_CALL(handler, OnDocumentEnd());
  372. Parse(ex2_21);
  373. }
  374. TEST_F(HandlerSpecTest, Ex2_22_Timestamps) {
  375. EXPECT_CALL(handler, OnDocumentStart(_));
  376. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  377. EXPECT_CALL(handler, OnScalar(_, "?", 0, "canonical"));
  378. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-12-15T02:59:43.1Z"));
  379. EXPECT_CALL(handler, OnScalar(_, "?", 0, "iso8601"));
  380. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-12-14t21:59:43.10-05:00"));
  381. EXPECT_CALL(handler, OnScalar(_, "?", 0, "spaced"));
  382. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-12-14 21:59:43.10 -5"));
  383. EXPECT_CALL(handler, OnScalar(_, "?", 0, "date"));
  384. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2002-12-14"));
  385. EXPECT_CALL(handler, OnMapEnd());
  386. EXPECT_CALL(handler, OnDocumentEnd());
  387. Parse(ex2_22);
  388. }
  389. TEST_F(HandlerSpecTest, Ex2_23_VariousExplicitTags) {
  390. EXPECT_CALL(handler, OnDocumentStart(_));
  391. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  392. EXPECT_CALL(handler, OnScalar(_, "?", 0, "not-date"));
  393. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "2002-04-28"));
  394. EXPECT_CALL(handler, OnScalar(_, "?", 0, "picture"));
  395. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:binary", 0,
  396. "R0lGODlhDAAMAIQAAP//9/X\n"
  397. "17unp5WZmZgAAAOfn515eXv\n"
  398. "Pz7Y6OjuDg4J+fn5OTk6enp\n"
  399. "56enmleECcgggoBADs=\n"));
  400. EXPECT_CALL(handler, OnScalar(_, "?", 0, "application specific tag"));
  401. EXPECT_CALL(handler, OnScalar(_, "!something", 0,
  402. "The semantics of the tag\n"
  403. "above may be different for\n"
  404. "different documents."));
  405. EXPECT_CALL(handler, OnMapEnd());
  406. EXPECT_CALL(handler, OnDocumentEnd());
  407. Parse(ex2_23);
  408. }
  409. TEST_F(HandlerSpecTest, Ex2_24_GlobalTags) {
  410. EXPECT_CALL(handler, OnDocumentStart(_));
  411. EXPECT_CALL(handler, OnSequenceStart(_, "tag:clarkevans.com,2002:shape", 0,
  412. EmitterStyle::Block));
  413. EXPECT_CALL(handler, OnMapStart(_, "tag:clarkevans.com,2002:circle", 0,
  414. EmitterStyle::Block));
  415. EXPECT_CALL(handler, OnScalar(_, "?", 0, "center"));
  416. EXPECT_CALL(handler, OnAnchor(_, "ORIGIN"));
  417. EXPECT_CALL(handler, OnMapStart(_, "?", 1, EmitterStyle::Flow));
  418. EXPECT_CALL(handler, OnScalar(_, "?", 0, "x"));
  419. EXPECT_CALL(handler, OnScalar(_, "?", 0, "73"));
  420. EXPECT_CALL(handler, OnScalar(_, "?", 0, "y"));
  421. EXPECT_CALL(handler, OnScalar(_, "?", 0, "129"));
  422. EXPECT_CALL(handler, OnMapEnd());
  423. EXPECT_CALL(handler, OnScalar(_, "?", 0, "radius"));
  424. EXPECT_CALL(handler, OnScalar(_, "?", 0, "7"));
  425. EXPECT_CALL(handler, OnMapEnd());
  426. EXPECT_CALL(handler, OnMapStart(_, "tag:clarkevans.com,2002:line", 0,
  427. EmitterStyle::Block));
  428. EXPECT_CALL(handler, OnScalar(_, "?", 0, "start"));
  429. EXPECT_CALL(handler, OnAlias(_, 1));
  430. EXPECT_CALL(handler, OnScalar(_, "?", 0, "finish"));
  431. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  432. EXPECT_CALL(handler, OnScalar(_, "?", 0, "x"));
  433. EXPECT_CALL(handler, OnScalar(_, "?", 0, "89"));
  434. EXPECT_CALL(handler, OnScalar(_, "?", 0, "y"));
  435. EXPECT_CALL(handler, OnScalar(_, "?", 0, "102"));
  436. EXPECT_CALL(handler, OnMapEnd());
  437. EXPECT_CALL(handler, OnMapEnd());
  438. EXPECT_CALL(handler, OnMapStart(_, "tag:clarkevans.com,2002:label", 0,
  439. EmitterStyle::Block));
  440. EXPECT_CALL(handler, OnScalar(_, "?", 0, "start"));
  441. EXPECT_CALL(handler, OnAlias(_, 1));
  442. EXPECT_CALL(handler, OnScalar(_, "?", 0, "color"));
  443. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0xFFEEBB"));
  444. EXPECT_CALL(handler, OnScalar(_, "?", 0, "text"));
  445. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Pretty vector drawing."));
  446. EXPECT_CALL(handler, OnMapEnd());
  447. EXPECT_CALL(handler, OnSequenceEnd());
  448. EXPECT_CALL(handler, OnDocumentEnd());
  449. Parse(ex2_24);
  450. }
  451. TEST_F(HandlerSpecTest, Ex2_25_UnorderedSets) {
  452. EXPECT_CALL(handler, OnDocumentStart(_));
  453. EXPECT_CALL(handler,
  454. OnMapStart(_, "tag:yaml.org,2002:set", 0, EmitterStyle::Block));
  455. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  456. EXPECT_CALL(handler, OnNull(_, 0));
  457. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  458. EXPECT_CALL(handler, OnNull(_, 0));
  459. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  460. EXPECT_CALL(handler, OnNull(_, 0));
  461. EXPECT_CALL(handler, OnMapEnd());
  462. EXPECT_CALL(handler, OnDocumentEnd());
  463. Parse(ex2_25);
  464. }
  465. TEST_F(HandlerSpecTest, Ex2_26_OrderedMappings) {
  466. EXPECT_CALL(handler, OnDocumentStart(_));
  467. EXPECT_CALL(handler, OnSequenceStart(_, "tag:yaml.org,2002:omap", 0,
  468. EmitterStyle::Block));
  469. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  470. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Mark McGwire"));
  471. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  472. EXPECT_CALL(handler, OnMapEnd());
  473. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  474. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy Sosa"));
  475. EXPECT_CALL(handler, OnScalar(_, "?", 0, "63"));
  476. EXPECT_CALL(handler, OnMapEnd());
  477. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  478. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Ken Griffey"));
  479. EXPECT_CALL(handler, OnScalar(_, "?", 0, "58"));
  480. EXPECT_CALL(handler, OnMapEnd());
  481. EXPECT_CALL(handler, OnSequenceEnd());
  482. EXPECT_CALL(handler, OnDocumentEnd());
  483. Parse(ex2_26);
  484. }
  485. TEST_F(HandlerSpecTest, Ex2_27_Invoice) {
  486. EXPECT_CALL(handler, OnDocumentStart(_));
  487. EXPECT_CALL(handler, OnMapStart(_, "tag:clarkevans.com,2002:invoice", 0,
  488. EmitterStyle::Block));
  489. EXPECT_CALL(handler, OnScalar(_, "?", 0, "invoice"));
  490. EXPECT_CALL(handler, OnScalar(_, "?", 0, "34843"));
  491. EXPECT_CALL(handler, OnScalar(_, "?", 0, "date"));
  492. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-01-23"));
  493. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bill-to"));
  494. EXPECT_CALL(handler, OnAnchor(_, "id001"));
  495. EXPECT_CALL(handler, OnMapStart(_, "?", 1, EmitterStyle::Block));
  496. EXPECT_CALL(handler, OnScalar(_, "?", 0, "given"));
  497. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chris"));
  498. EXPECT_CALL(handler, OnScalar(_, "?", 0, "family"));
  499. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Dumars"));
  500. EXPECT_CALL(handler, OnScalar(_, "?", 0, "address"));
  501. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  502. EXPECT_CALL(handler, OnScalar(_, "?", 0, "lines"));
  503. EXPECT_CALL(handler, OnScalar(_, "!", 0,
  504. "458 Walkman Dr.\n"
  505. "Suite #292\n"));
  506. EXPECT_CALL(handler, OnScalar(_, "?", 0, "city"));
  507. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Royal Oak"));
  508. EXPECT_CALL(handler, OnScalar(_, "?", 0, "state"));
  509. EXPECT_CALL(handler, OnScalar(_, "?", 0, "MI"));
  510. EXPECT_CALL(handler, OnScalar(_, "?", 0, "postal"));
  511. EXPECT_CALL(handler, OnScalar(_, "?", 0, "48046"));
  512. EXPECT_CALL(handler, OnMapEnd());
  513. EXPECT_CALL(handler, OnMapEnd());
  514. EXPECT_CALL(handler, OnScalar(_, "?", 0, "ship-to"));
  515. EXPECT_CALL(handler, OnAlias(_, 1));
  516. EXPECT_CALL(handler, OnScalar(_, "?", 0, "product"));
  517. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  518. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  519. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sku"));
  520. EXPECT_CALL(handler, OnScalar(_, "?", 0, "BL394D"));
  521. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quantity"));
  522. EXPECT_CALL(handler, OnScalar(_, "?", 0, "4"));
  523. EXPECT_CALL(handler, OnScalar(_, "?", 0, "description"));
  524. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Basketball"));
  525. EXPECT_CALL(handler, OnScalar(_, "?", 0, "price"));
  526. EXPECT_CALL(handler, OnScalar(_, "?", 0, "450.00"));
  527. EXPECT_CALL(handler, OnMapEnd());
  528. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  529. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sku"));
  530. EXPECT_CALL(handler, OnScalar(_, "?", 0, "BL4438H"));
  531. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quantity"));
  532. EXPECT_CALL(handler, OnScalar(_, "?", 0, "1"));
  533. EXPECT_CALL(handler, OnScalar(_, "?", 0, "description"));
  534. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Super Hoop"));
  535. EXPECT_CALL(handler, OnScalar(_, "?", 0, "price"));
  536. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2392.00"));
  537. EXPECT_CALL(handler, OnMapEnd());
  538. EXPECT_CALL(handler, OnSequenceEnd());
  539. EXPECT_CALL(handler, OnScalar(_, "?", 0, "tax"));
  540. EXPECT_CALL(handler, OnScalar(_, "?", 0, "251.42"));
  541. EXPECT_CALL(handler, OnScalar(_, "?", 0, "total"));
  542. EXPECT_CALL(handler, OnScalar(_, "?", 0, "4443.52"));
  543. EXPECT_CALL(handler, OnScalar(_, "?", 0, "comments"));
  544. EXPECT_CALL(handler, OnScalar(_, "?", 0,
  545. "Late afternoon is best. Backup contact is "
  546. "Nancy Billsmer @ 338-4338."));
  547. EXPECT_CALL(handler, OnMapEnd());
  548. EXPECT_CALL(handler, OnDocumentEnd());
  549. Parse(ex2_27);
  550. }
  551. TEST_F(HandlerSpecTest, Ex2_28_LogFile) {
  552. EXPECT_CALL(handler, OnDocumentStart(_));
  553. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  554. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Time"));
  555. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-11-23 15:01:42 -5"));
  556. EXPECT_CALL(handler, OnScalar(_, "?", 0, "User"));
  557. EXPECT_CALL(handler, OnScalar(_, "?", 0, "ed"));
  558. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Warning"));
  559. EXPECT_CALL(handler,
  560. OnScalar(_, "?", 0, "This is an error message for the log file"));
  561. EXPECT_CALL(handler, OnMapEnd());
  562. EXPECT_CALL(handler, OnDocumentEnd());
  563. EXPECT_CALL(handler, OnDocumentStart(_));
  564. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  565. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Time"));
  566. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-11-23 15:02:31 -5"));
  567. EXPECT_CALL(handler, OnScalar(_, "?", 0, "User"));
  568. EXPECT_CALL(handler, OnScalar(_, "?", 0, "ed"));
  569. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Warning"));
  570. EXPECT_CALL(handler,
  571. OnScalar(_, "?", 0, "A slightly different error message."));
  572. EXPECT_CALL(handler, OnMapEnd());
  573. EXPECT_CALL(handler, OnDocumentEnd());
  574. EXPECT_CALL(handler, OnDocumentStart(_));
  575. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  576. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Date"));
  577. EXPECT_CALL(handler, OnScalar(_, "?", 0, "2001-11-23 15:03:17 -5"));
  578. EXPECT_CALL(handler, OnScalar(_, "?", 0, "User"));
  579. EXPECT_CALL(handler, OnScalar(_, "?", 0, "ed"));
  580. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Fatal"));
  581. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Unknown variable \"bar\""));
  582. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Stack"));
  583. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  584. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  585. EXPECT_CALL(handler, OnScalar(_, "?", 0, "file"));
  586. EXPECT_CALL(handler, OnScalar(_, "?", 0, "TopClass.py"));
  587. EXPECT_CALL(handler, OnScalar(_, "?", 0, "line"));
  588. EXPECT_CALL(handler, OnScalar(_, "?", 0, "23"));
  589. EXPECT_CALL(handler, OnScalar(_, "?", 0, "code"));
  590. EXPECT_CALL(handler, OnScalar(_, "!", 0, "x = MoreObject(\"345\\n\")\n"));
  591. EXPECT_CALL(handler, OnMapEnd());
  592. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  593. EXPECT_CALL(handler, OnScalar(_, "?", 0, "file"));
  594. EXPECT_CALL(handler, OnScalar(_, "?", 0, "MoreClass.py"));
  595. EXPECT_CALL(handler, OnScalar(_, "?", 0, "line"));
  596. EXPECT_CALL(handler, OnScalar(_, "?", 0, "58"));
  597. EXPECT_CALL(handler, OnScalar(_, "?", 0, "code"));
  598. EXPECT_CALL(handler, OnScalar(_, "!", 0, "foo = bar"));
  599. EXPECT_CALL(handler, OnMapEnd());
  600. EXPECT_CALL(handler, OnSequenceEnd());
  601. EXPECT_CALL(handler, OnMapEnd());
  602. EXPECT_CALL(handler, OnDocumentEnd());
  603. Parse(ex2_28);
  604. }
  605. // TODO: 5.1 - 5.2 BOM
  606. TEST_F(HandlerSpecTest, Ex5_3_BlockStructureIndicators) {
  607. EXPECT_CALL(handler, OnDocumentStart(_));
  608. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  609. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sequence"));
  610. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  611. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  612. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  613. EXPECT_CALL(handler, OnSequenceEnd());
  614. EXPECT_CALL(handler, OnScalar(_, "?", 0, "mapping"));
  615. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  616. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sky"));
  617. EXPECT_CALL(handler, OnScalar(_, "?", 0, "blue"));
  618. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sea"));
  619. EXPECT_CALL(handler, OnScalar(_, "?", 0, "green"));
  620. EXPECT_CALL(handler, OnMapEnd());
  621. EXPECT_CALL(handler, OnMapEnd());
  622. EXPECT_CALL(handler, OnDocumentEnd());
  623. Parse(ex5_3);
  624. }
  625. TEST_F(HandlerSpecTest, Ex5_4_FlowStructureIndicators) {
  626. EXPECT_CALL(handler, OnDocumentStart(_));
  627. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  628. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sequence"));
  629. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  630. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  631. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  632. EXPECT_CALL(handler, OnSequenceEnd());
  633. EXPECT_CALL(handler, OnScalar(_, "?", 0, "mapping"));
  634. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  635. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sky"));
  636. EXPECT_CALL(handler, OnScalar(_, "?", 0, "blue"));
  637. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sea"));
  638. EXPECT_CALL(handler, OnScalar(_, "?", 0, "green"));
  639. EXPECT_CALL(handler, OnMapEnd());
  640. EXPECT_CALL(handler, OnMapEnd());
  641. EXPECT_CALL(handler, OnDocumentEnd());
  642. Parse(ex5_4);
  643. }
  644. TEST_F(HandlerSpecTest, Ex5_5_CommentIndicator) { Parse(ex5_5); }
  645. TEST_F(HandlerSpecTest, Ex5_6_NodePropertyIndicators) {
  646. EXPECT_CALL(handler, OnDocumentStart(_));
  647. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  648. EXPECT_CALL(handler, OnScalar(_, "?", 0, "anchored"));
  649. EXPECT_CALL(handler, OnAnchor(_, "anchor"));
  650. EXPECT_CALL(handler, OnScalar(_, "!local", 1, "value"));
  651. EXPECT_CALL(handler, OnScalar(_, "?", 0, "alias"));
  652. EXPECT_CALL(handler, OnAlias(_, 1));
  653. EXPECT_CALL(handler, OnMapEnd());
  654. EXPECT_CALL(handler, OnDocumentEnd());
  655. Parse(ex5_6);
  656. }
  657. TEST_F(HandlerSpecTest, Ex5_7_BlockScalarIndicators) {
  658. EXPECT_CALL(handler, OnDocumentStart(_));
  659. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  660. EXPECT_CALL(handler, OnScalar(_, "?", 0, "literal"));
  661. EXPECT_CALL(handler, OnScalar(_, "!", 0, "some\ntext\n"));
  662. EXPECT_CALL(handler, OnScalar(_, "?", 0, "folded"));
  663. EXPECT_CALL(handler, OnScalar(_, "!", 0, "some text\n"));
  664. EXPECT_CALL(handler, OnMapEnd());
  665. EXPECT_CALL(handler, OnDocumentEnd());
  666. Parse(ex5_7);
  667. }
  668. TEST_F(HandlerSpecTest, Ex5_8_QuotedScalarIndicators) {
  669. EXPECT_CALL(handler, OnDocumentStart(_));
  670. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  671. EXPECT_CALL(handler, OnScalar(_, "?", 0, "single"));
  672. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text"));
  673. EXPECT_CALL(handler, OnScalar(_, "?", 0, "double"));
  674. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text"));
  675. EXPECT_CALL(handler, OnMapEnd());
  676. EXPECT_CALL(handler, OnDocumentEnd());
  677. Parse(ex5_8);
  678. }
  679. // TODO: 5.9 directive
  680. // TODO: 5.10 reserved indicator
  681. TEST_F(HandlerSpecTest, Ex5_11_LineBreakCharacters) {
  682. EXPECT_CALL(handler, OnDocumentStart(_));
  683. EXPECT_CALL(handler, OnScalar(_, "!", 0,
  684. "Line break (no glyph)\n"
  685. "Line break (glyphed)\n"));
  686. EXPECT_CALL(handler, OnDocumentEnd());
  687. Parse(ex5_11);
  688. }
  689. TEST_F(HandlerSpecTest, Ex5_12_TabsAndSpaces) {
  690. EXPECT_CALL(handler, OnDocumentStart(_));
  691. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  692. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quoted"));
  693. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Quoted\t"));
  694. EXPECT_CALL(handler, OnScalar(_, "?", 0, "block"));
  695. EXPECT_CALL(handler, OnScalar(_, "!", 0,
  696. "void main() {\n"
  697. "\tprintf(\"Hello, world!\\n\");\n"
  698. "}"));
  699. EXPECT_CALL(handler, OnMapEnd());
  700. EXPECT_CALL(handler, OnDocumentEnd());
  701. Parse(ex5_12);
  702. }
  703. TEST_F(HandlerSpecTest, Ex5_13_EscapedCharacters) {
  704. EXPECT_CALL(handler, OnDocumentStart(_));
  705. EXPECT_CALL(
  706. handler,
  707. OnScalar(_, "!", 0,
  708. "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " +
  709. std::string("\x00", 1) +
  710. " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A"));
  711. EXPECT_CALL(handler, OnDocumentEnd());
  712. Parse(ex5_13);
  713. }
  714. TEST_F(HandlerSpecTest, Ex5_14_InvalidEscapedCharacters) {
  715. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex5_14),
  716. std::string(ErrorMsg::INVALID_ESCAPE) + "c");
  717. }
  718. TEST_F(HandlerSpecTest, Ex6_1_IndentationSpaces) {
  719. EXPECT_CALL(handler, OnDocumentStart(_));
  720. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  721. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Not indented"));
  722. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  723. EXPECT_CALL(handler, OnScalar(_, "?", 0, "By one space"));
  724. EXPECT_CALL(handler, OnScalar(_, "!", 0, "By four\n spaces\n"));
  725. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Flow style"));
  726. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  727. EXPECT_CALL(handler, OnScalar(_, "?", 0, "By two"));
  728. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Also by two"));
  729. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Still by two"));
  730. EXPECT_CALL(handler, OnSequenceEnd());
  731. EXPECT_CALL(handler, OnMapEnd());
  732. EXPECT_CALL(handler, OnMapEnd());
  733. EXPECT_CALL(handler, OnDocumentEnd());
  734. Parse(ex6_1);
  735. }
  736. TEST_F(HandlerSpecTest, Ex6_2_IndentationIndicators) {
  737. EXPECT_CALL(handler, OnDocumentStart(_));
  738. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  739. EXPECT_CALL(handler, OnScalar(_, "?", 0, "a"));
  740. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  741. EXPECT_CALL(handler, OnScalar(_, "?", 0, "b"));
  742. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  743. EXPECT_CALL(handler, OnScalar(_, "?", 0, "c"));
  744. EXPECT_CALL(handler, OnScalar(_, "?", 0, "d"));
  745. EXPECT_CALL(handler, OnSequenceEnd());
  746. EXPECT_CALL(handler, OnSequenceEnd());
  747. EXPECT_CALL(handler, OnMapEnd());
  748. EXPECT_CALL(handler, OnDocumentEnd());
  749. Parse(ex6_2);
  750. }
  751. TEST_F(HandlerSpecTest, Ex6_3_SeparationSpaces) {
  752. EXPECT_CALL(handler, OnDocumentStart(_));
  753. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  754. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  755. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  756. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  757. EXPECT_CALL(handler, OnMapEnd());
  758. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  759. EXPECT_CALL(handler, OnScalar(_, "?", 0, "baz"));
  760. EXPECT_CALL(handler, OnScalar(_, "?", 0, "baz"));
  761. EXPECT_CALL(handler, OnSequenceEnd());
  762. EXPECT_CALL(handler, OnSequenceEnd());
  763. EXPECT_CALL(handler, OnDocumentEnd());
  764. Parse(ex6_3);
  765. }
  766. TEST_F(HandlerSpecTest, Ex6_4_LinePrefixes) {
  767. EXPECT_CALL(handler, OnDocumentStart(_));
  768. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  769. EXPECT_CALL(handler, OnScalar(_, "?", 0, "plain"));
  770. EXPECT_CALL(handler, OnScalar(_, "?", 0, "text lines"));
  771. EXPECT_CALL(handler, OnScalar(_, "?", 0, "quoted"));
  772. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text lines"));
  773. EXPECT_CALL(handler, OnScalar(_, "?", 0, "block"));
  774. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text\n \tlines\n"));
  775. EXPECT_CALL(handler, OnMapEnd());
  776. EXPECT_CALL(handler, OnDocumentEnd());
  777. Parse(ex6_4);
  778. }
  779. TEST_F(HandlerSpecTest, Ex6_5_EmptyLines) {
  780. EXPECT_CALL(handler, OnDocumentStart(_));
  781. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  782. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Folding"));
  783. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Empty line\nas a line feed"));
  784. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Chomping"));
  785. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Clipped empty lines\n"));
  786. EXPECT_CALL(handler, OnMapEnd());
  787. EXPECT_CALL(handler, OnDocumentEnd());
  788. Parse(ex6_5);
  789. }
  790. TEST_F(HandlerSpecTest, Ex6_6_LineFolding) {
  791. EXPECT_CALL(handler, OnDocumentStart(_));
  792. EXPECT_CALL(handler, OnScalar(_, "!", 0, "trimmed\n\n\nas space"));
  793. EXPECT_CALL(handler, OnDocumentEnd());
  794. Parse(ex6_6);
  795. }
  796. TEST_F(HandlerSpecTest, Ex6_7_BlockFolding) {
  797. EXPECT_CALL(handler, OnDocumentStart(_));
  798. EXPECT_CALL(handler, OnScalar(_, "!", 0, "foo \n\n\t bar\n\nbaz\n"));
  799. EXPECT_CALL(handler, OnDocumentEnd());
  800. Parse(ex6_7);
  801. }
  802. TEST_F(HandlerSpecTest, Ex6_8_FlowFolding) {
  803. EXPECT_CALL(handler, OnDocumentStart(_));
  804. EXPECT_CALL(handler, OnScalar(_, "!", 0, " foo\nbar\nbaz "));
  805. EXPECT_CALL(handler, OnDocumentEnd());
  806. Parse(ex6_8);
  807. }
  808. TEST_F(HandlerSpecTest, Ex6_9_SeparatedComment) {
  809. EXPECT_CALL(handler, OnDocumentStart(_));
  810. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  811. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  812. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  813. EXPECT_CALL(handler, OnMapEnd());
  814. EXPECT_CALL(handler, OnDocumentEnd());
  815. Parse(ex6_9);
  816. }
  817. TEST_F(HandlerSpecTest, Ex6_10_CommentLines) { Parse(ex6_10); }
  818. TEST_F(HandlerSpecTest, _MultiLineComments) {
  819. EXPECT_CALL(handler, OnDocumentStart(_));
  820. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  821. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  822. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  823. EXPECT_CALL(handler, OnMapEnd());
  824. EXPECT_CALL(handler, OnDocumentEnd());
  825. Parse(ex6_11);
  826. }
  827. TEST_F(HandlerSpecTest, Ex6_12_SeparationSpacesII) {
  828. EXPECT_CALL(handler, OnDocumentStart(_));
  829. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  830. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  831. EXPECT_CALL(handler, OnScalar(_, "?", 0, "first"));
  832. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sammy"));
  833. EXPECT_CALL(handler, OnScalar(_, "?", 0, "last"));
  834. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Sosa"));
  835. EXPECT_CALL(handler, OnMapEnd());
  836. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  837. EXPECT_CALL(handler, OnScalar(_, "?", 0, "hr"));
  838. EXPECT_CALL(handler, OnScalar(_, "?", 0, "65"));
  839. EXPECT_CALL(handler, OnScalar(_, "?", 0, "avg"));
  840. EXPECT_CALL(handler, OnScalar(_, "?", 0, "0.278"));
  841. EXPECT_CALL(handler, OnMapEnd());
  842. EXPECT_CALL(handler, OnMapEnd());
  843. EXPECT_CALL(handler, OnDocumentEnd());
  844. Parse(ex6_12);
  845. }
  846. TEST_F(HandlerSpecTest, Ex6_13_ReservedDirectives) {
  847. EXPECT_CALL(handler, OnDocumentStart(_));
  848. EXPECT_CALL(handler, OnScalar(_, "!", 0, "foo"));
  849. EXPECT_CALL(handler, OnDocumentEnd());
  850. Parse(ex6_13);
  851. }
  852. TEST_F(HandlerSpecTest, Ex6_14_YAMLDirective) {
  853. EXPECT_CALL(handler, OnDocumentStart(_));
  854. EXPECT_CALL(handler, OnScalar(_, "!", 0, "foo"));
  855. EXPECT_CALL(handler, OnDocumentEnd());
  856. Parse(ex6_14);
  857. }
  858. TEST_F(HandlerSpecTest, Ex6_15_InvalidRepeatedYAMLDirective) {
  859. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex6_15),
  860. ErrorMsg::REPEATED_YAML_DIRECTIVE);
  861. }
  862. TEST_F(HandlerSpecTest, Ex6_16_TagDirective) {
  863. EXPECT_CALL(handler, OnDocumentStart(_));
  864. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "foo"));
  865. EXPECT_CALL(handler, OnDocumentEnd());
  866. Parse(ex6_16);
  867. }
  868. TEST_F(HandlerSpecTest, Ex6_17_InvalidRepeatedTagDirective) {
  869. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex6_17),
  870. ErrorMsg::REPEATED_TAG_DIRECTIVE);
  871. }
  872. TEST_F(HandlerSpecTest, Ex6_18_PrimaryTagHandle) {
  873. EXPECT_CALL(handler, OnDocumentStart(_));
  874. EXPECT_CALL(handler, OnScalar(_, "!foo", 0, "bar"));
  875. EXPECT_CALL(handler, OnDocumentEnd());
  876. EXPECT_CALL(handler, OnDocumentStart(_));
  877. EXPECT_CALL(handler, OnScalar(_, "tag:example.com,2000:app/foo", 0, "bar"));
  878. EXPECT_CALL(handler, OnDocumentEnd());
  879. Parse(ex6_18);
  880. }
  881. TEST_F(HandlerSpecTest, Ex6_19_SecondaryTagHandle) {
  882. EXPECT_CALL(handler, OnDocumentStart(_));
  883. EXPECT_CALL(handler, OnScalar(_, "tag:example.com,2000:app/int", 0, "1 - 3"));
  884. EXPECT_CALL(handler, OnDocumentEnd());
  885. Parse(ex6_19);
  886. }
  887. TEST_F(HandlerSpecTest, Ex6_20_TagHandles) {
  888. EXPECT_CALL(handler, OnDocumentStart(_));
  889. EXPECT_CALL(handler, OnScalar(_, "tag:example.com,2000:app/foo", 0, "bar"));
  890. EXPECT_CALL(handler, OnDocumentEnd());
  891. Parse(ex6_20);
  892. }
  893. TEST_F(HandlerSpecTest, Ex6_21_LocalTagPrefix) {
  894. EXPECT_CALL(handler, OnDocumentStart(_));
  895. EXPECT_CALL(handler, OnScalar(_, "!my-light", 0, "fluorescent"));
  896. EXPECT_CALL(handler, OnDocumentEnd());
  897. EXPECT_CALL(handler, OnDocumentStart(_));
  898. EXPECT_CALL(handler, OnScalar(_, "!my-light", 0, "green"));
  899. EXPECT_CALL(handler, OnDocumentEnd());
  900. Parse(ex6_21);
  901. }
  902. TEST_F(HandlerSpecTest, Ex6_22_GlobalTagPrefix) {
  903. EXPECT_CALL(handler, OnDocumentStart(_));
  904. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  905. EXPECT_CALL(handler, OnScalar(_, "tag:example.com,2000:app/foo", 0, "bar"));
  906. EXPECT_CALL(handler, OnSequenceEnd());
  907. EXPECT_CALL(handler, OnDocumentEnd());
  908. Parse(ex6_22);
  909. }
  910. TEST_F(HandlerSpecTest, Ex6_23_NodeProperties) {
  911. EXPECT_CALL(handler, OnDocumentStart(_));
  912. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  913. EXPECT_CALL(handler, OnAnchor(_, "a1"));
  914. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 1, "foo"));
  915. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "bar"));
  916. EXPECT_CALL(handler, OnAnchor(_, "a2"));
  917. EXPECT_CALL(handler, OnScalar(_, "?", 2, "baz"));
  918. EXPECT_CALL(handler, OnAlias(_, 1));
  919. EXPECT_CALL(handler, OnMapEnd());
  920. EXPECT_CALL(handler, OnDocumentEnd());
  921. Parse(ex6_23);
  922. }
  923. TEST_F(HandlerSpecTest, Ex6_24_VerbatimTags) {
  924. EXPECT_CALL(handler, OnDocumentStart(_));
  925. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  926. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "foo"));
  927. EXPECT_CALL(handler, OnScalar(_, "!bar", 0, "baz"));
  928. EXPECT_CALL(handler, OnMapEnd());
  929. EXPECT_CALL(handler, OnDocumentEnd());
  930. Parse(ex6_24);
  931. }
  932. // TODO: Implement
  933. TEST_F(HandlerSpecTest, DISABLED_Ex6_25_InvalidVerbatimTags) {
  934. Parse(ex6_25);
  935. FAIL() << "not implemented yet";
  936. }
  937. TEST_F(HandlerSpecTest, Ex6_26_TagShorthands) {
  938. EXPECT_CALL(handler, OnDocumentStart(_));
  939. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  940. EXPECT_CALL(handler, OnScalar(_, "!local", 0, "foo"));
  941. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "bar"));
  942. EXPECT_CALL(handler,
  943. OnScalar(_, "tag:example.com,2000:app/tag%21", 0, "baz"));
  944. EXPECT_CALL(handler, OnSequenceEnd());
  945. EXPECT_CALL(handler, OnDocumentEnd());
  946. Parse(ex6_26);
  947. }
  948. TEST_F(HandlerSpecTest, Ex6_27a_InvalidTagShorthands) {
  949. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex6_27a),
  950. ErrorMsg::TAG_WITH_NO_SUFFIX);
  951. }
  952. // TODO: should we reject this one (since !h! is not declared)?
  953. TEST_F(HandlerSpecTest, DISABLED_Ex6_27b_InvalidTagShorthands) {
  954. Parse(ex6_27b);
  955. FAIL() << "not implemented yet";
  956. }
  957. TEST_F(HandlerSpecTest, Ex6_28_NonSpecificTags) {
  958. EXPECT_CALL(handler, OnDocumentStart(_));
  959. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  960. EXPECT_CALL(handler, OnScalar(_, "!", 0, "12"));
  961. EXPECT_CALL(handler, OnScalar(_, "?", 0, "12"));
  962. EXPECT_CALL(handler, OnScalar(_, "!", 0, "12"));
  963. EXPECT_CALL(handler, OnSequenceEnd());
  964. EXPECT_CALL(handler, OnDocumentEnd());
  965. Parse(ex6_28);
  966. }
  967. TEST_F(HandlerSpecTest, Ex6_29_NodeAnchors) {
  968. EXPECT_CALL(handler, OnDocumentStart(_));
  969. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  970. EXPECT_CALL(handler, OnScalar(_, "?", 0, "First occurrence"));
  971. EXPECT_CALL(handler, OnAnchor(_, "anchor"));
  972. EXPECT_CALL(handler, OnScalar(_, "?", 1, "Value"));
  973. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Second occurrence"));
  974. EXPECT_CALL(handler, OnAlias(_, 1));
  975. EXPECT_CALL(handler, OnMapEnd());
  976. EXPECT_CALL(handler, OnDocumentEnd());
  977. Parse(ex6_29);
  978. }
  979. TEST_F(HandlerSpecTest, Ex7_1_AliasNodes) {
  980. EXPECT_CALL(handler, OnDocumentStart(_));
  981. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  982. EXPECT_CALL(handler, OnScalar(_, "?", 0, "First occurrence"));
  983. EXPECT_CALL(handler, OnAnchor(_, "anchor"));
  984. EXPECT_CALL(handler, OnScalar(_, "?", 1, "Foo"));
  985. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Second occurrence"));
  986. EXPECT_CALL(handler, OnAlias(_, 1));
  987. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Override anchor"));
  988. EXPECT_CALL(handler, OnAnchor(_, "anchor"));
  989. EXPECT_CALL(handler, OnScalar(_, "?", 2, "Bar"));
  990. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Reuse anchor"));
  991. EXPECT_CALL(handler, OnAlias(_, 2));
  992. EXPECT_CALL(handler, OnMapEnd());
  993. EXPECT_CALL(handler, OnDocumentEnd());
  994. Parse(ex7_1);
  995. }
  996. TEST_F(HandlerSpecTest, Ex7_2_EmptyNodes) {
  997. EXPECT_CALL(handler, OnDocumentStart(_));
  998. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  999. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  1000. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, ""));
  1001. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, ""));
  1002. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  1003. EXPECT_CALL(handler, OnMapEnd());
  1004. EXPECT_CALL(handler, OnDocumentEnd());
  1005. Parse(ex7_2);
  1006. }
  1007. TEST_F(HandlerSpecTest, Ex7_3_CompletelyEmptyNodes) {
  1008. EXPECT_CALL(handler, OnDocumentStart(_));
  1009. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1010. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  1011. EXPECT_CALL(handler, OnNull(_, 0));
  1012. EXPECT_CALL(handler, OnNull(_, 0));
  1013. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  1014. EXPECT_CALL(handler, OnMapEnd());
  1015. EXPECT_CALL(handler, OnDocumentEnd());
  1016. Parse(ex7_3);
  1017. }
  1018. TEST_F(HandlerSpecTest, Ex7_4_DoubleQuotedImplicitKeys) {
  1019. EXPECT_CALL(handler, OnDocumentStart(_));
  1020. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1021. EXPECT_CALL(handler, OnScalar(_, "!", 0, "implicit block key"));
  1022. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1023. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1024. EXPECT_CALL(handler, OnScalar(_, "!", 0, "implicit flow key"));
  1025. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1026. EXPECT_CALL(handler, OnMapEnd());
  1027. EXPECT_CALL(handler, OnSequenceEnd());
  1028. EXPECT_CALL(handler, OnMapEnd());
  1029. EXPECT_CALL(handler, OnDocumentEnd());
  1030. Parse(ex7_4);
  1031. }
  1032. TEST_F(HandlerSpecTest, Ex7_5_DoubleQuotedLineBreaks) {
  1033. EXPECT_CALL(handler, OnDocumentStart(_));
  1034. EXPECT_CALL(
  1035. handler,
  1036. OnScalar(_, "!", 0,
  1037. "folded to a space,\nto a line feed, or \t \tnon-content"));
  1038. EXPECT_CALL(handler, OnDocumentEnd());
  1039. Parse(ex7_5);
  1040. }
  1041. TEST_F(HandlerSpecTest, Ex7_6_DoubleQuotedLines) {
  1042. EXPECT_CALL(handler, OnDocumentStart(_));
  1043. EXPECT_CALL(
  1044. handler,
  1045. OnScalar(_, "!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty "));
  1046. EXPECT_CALL(handler, OnDocumentEnd());
  1047. Parse(ex7_6);
  1048. }
  1049. TEST_F(HandlerSpecTest, Ex7_7_SingleQuotedCharacters) {
  1050. EXPECT_CALL(handler, OnDocumentStart(_));
  1051. EXPECT_CALL(handler, OnScalar(_, "!", 0, "here's to \"quotes\""));
  1052. EXPECT_CALL(handler, OnDocumentEnd());
  1053. Parse(ex7_7);
  1054. }
  1055. TEST_F(HandlerSpecTest, Ex7_8_SingleQuotedImplicitKeys) {
  1056. EXPECT_CALL(handler, OnDocumentStart(_));
  1057. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1058. EXPECT_CALL(handler, OnScalar(_, "!", 0, "implicit block key"));
  1059. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1060. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1061. EXPECT_CALL(handler, OnScalar(_, "!", 0, "implicit flow key"));
  1062. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1063. EXPECT_CALL(handler, OnMapEnd());
  1064. EXPECT_CALL(handler, OnSequenceEnd());
  1065. EXPECT_CALL(handler, OnMapEnd());
  1066. EXPECT_CALL(handler, OnDocumentEnd());
  1067. Parse(ex7_8);
  1068. }
  1069. TEST_F(HandlerSpecTest, Ex7_9_SingleQuotedLines) {
  1070. EXPECT_CALL(handler, OnDocumentStart(_));
  1071. EXPECT_CALL(
  1072. handler,
  1073. OnScalar(_, "!", 0, " 1st non-empty\n2nd non-empty 3rd non-empty "));
  1074. EXPECT_CALL(handler, OnDocumentEnd());
  1075. Parse(ex7_9);
  1076. }
  1077. TEST_F(HandlerSpecTest, Ex7_10_PlainCharacters) {
  1078. EXPECT_CALL(handler, OnDocumentStart(_));
  1079. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1080. EXPECT_CALL(handler, OnScalar(_, "?", 0, "::vector"));
  1081. EXPECT_CALL(handler, OnScalar(_, "!", 0, ": - ()"));
  1082. EXPECT_CALL(handler, OnScalar(_, "?", 0, "Up, up, and away!"));
  1083. EXPECT_CALL(handler, OnScalar(_, "?", 0, "-123"));
  1084. EXPECT_CALL(handler, OnScalar(_, "?", 0, "http://example.com/foo#bar"));
  1085. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1086. EXPECT_CALL(handler, OnScalar(_, "?", 0, "::vector"));
  1087. EXPECT_CALL(handler, OnScalar(_, "!", 0, ": - ()"));
  1088. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Up, up, and away!"));
  1089. EXPECT_CALL(handler, OnScalar(_, "?", 0, "-123"));
  1090. EXPECT_CALL(handler, OnScalar(_, "?", 0, "http://example.com/foo#bar"));
  1091. EXPECT_CALL(handler, OnSequenceEnd());
  1092. EXPECT_CALL(handler, OnSequenceEnd());
  1093. EXPECT_CALL(handler, OnDocumentEnd());
  1094. Parse(ex7_10);
  1095. }
  1096. TEST_F(HandlerSpecTest, Ex7_11_PlainImplicitKeys) {
  1097. EXPECT_CALL(handler, OnDocumentStart(_));
  1098. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1099. EXPECT_CALL(handler, OnScalar(_, "?", 0, "implicit block key"));
  1100. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1101. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1102. EXPECT_CALL(handler, OnScalar(_, "?", 0, "implicit flow key"));
  1103. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1104. EXPECT_CALL(handler, OnMapEnd());
  1105. EXPECT_CALL(handler, OnSequenceEnd());
  1106. EXPECT_CALL(handler, OnMapEnd());
  1107. EXPECT_CALL(handler, OnDocumentEnd());
  1108. Parse(ex7_11);
  1109. }
  1110. TEST_F(HandlerSpecTest, Ex7_12_PlainLines) {
  1111. EXPECT_CALL(handler, OnDocumentStart(_));
  1112. EXPECT_CALL(handler, OnScalar(_, "?", 0,
  1113. "1st non-empty\n2nd non-empty 3rd non-empty"));
  1114. EXPECT_CALL(handler, OnDocumentEnd());
  1115. Parse(ex7_12);
  1116. }
  1117. TEST_F(HandlerSpecTest, Ex7_13_FlowSequence) {
  1118. EXPECT_CALL(handler, OnDocumentStart(_));
  1119. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1120. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1121. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1122. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1123. EXPECT_CALL(handler, OnSequenceEnd());
  1124. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1125. EXPECT_CALL(handler, OnScalar(_, "?", 0, "three"));
  1126. EXPECT_CALL(handler, OnScalar(_, "?", 0, "four"));
  1127. EXPECT_CALL(handler, OnSequenceEnd());
  1128. EXPECT_CALL(handler, OnSequenceEnd());
  1129. EXPECT_CALL(handler, OnDocumentEnd());
  1130. Parse(ex7_13);
  1131. }
  1132. TEST_F(HandlerSpecTest, Ex7_14_FlowSequenceEntries) {
  1133. EXPECT_CALL(handler, OnDocumentStart(_));
  1134. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1135. EXPECT_CALL(handler, OnScalar(_, "!", 0, "double quoted"));
  1136. EXPECT_CALL(handler, OnScalar(_, "!", 0, "single quoted"));
  1137. EXPECT_CALL(handler, OnScalar(_, "?", 0, "plain text"));
  1138. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1139. EXPECT_CALL(handler, OnScalar(_, "?", 0, "nested"));
  1140. EXPECT_CALL(handler, OnSequenceEnd());
  1141. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1142. EXPECT_CALL(handler, OnScalar(_, "?", 0, "single"));
  1143. EXPECT_CALL(handler, OnScalar(_, "?", 0, "pair"));
  1144. EXPECT_CALL(handler, OnMapEnd());
  1145. EXPECT_CALL(handler, OnSequenceEnd());
  1146. EXPECT_CALL(handler, OnDocumentEnd());
  1147. Parse(ex7_14);
  1148. }
  1149. TEST_F(HandlerSpecTest, Ex7_15_FlowMappings) {
  1150. EXPECT_CALL(handler, OnDocumentStart(_));
  1151. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1152. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1153. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1154. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1155. EXPECT_CALL(handler, OnScalar(_, "?", 0, "three"));
  1156. EXPECT_CALL(handler, OnScalar(_, "?", 0, "four"));
  1157. EXPECT_CALL(handler, OnMapEnd());
  1158. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1159. EXPECT_CALL(handler, OnScalar(_, "?", 0, "five"));
  1160. EXPECT_CALL(handler, OnScalar(_, "?", 0, "six"));
  1161. EXPECT_CALL(handler, OnScalar(_, "?", 0, "seven"));
  1162. EXPECT_CALL(handler, OnScalar(_, "?", 0, "eight"));
  1163. EXPECT_CALL(handler, OnMapEnd());
  1164. EXPECT_CALL(handler, OnSequenceEnd());
  1165. EXPECT_CALL(handler, OnDocumentEnd());
  1166. Parse(ex7_15);
  1167. }
  1168. TEST_F(HandlerSpecTest, Ex7_16_FlowMappingEntries) {
  1169. EXPECT_CALL(handler, OnDocumentStart(_));
  1170. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1171. EXPECT_CALL(handler, OnScalar(_, "?", 0, "explicit"));
  1172. EXPECT_CALL(handler, OnScalar(_, "?", 0, "entry"));
  1173. EXPECT_CALL(handler, OnScalar(_, "?", 0, "implicit"));
  1174. EXPECT_CALL(handler, OnScalar(_, "?", 0, "entry"));
  1175. EXPECT_CALL(handler, OnNull(_, 0));
  1176. EXPECT_CALL(handler, OnNull(_, 0));
  1177. EXPECT_CALL(handler, OnMapEnd());
  1178. EXPECT_CALL(handler, OnDocumentEnd());
  1179. Parse(ex7_16);
  1180. }
  1181. TEST_F(HandlerSpecTest, Ex7_17_FlowMappingSeparateValues) {
  1182. EXPECT_CALL(handler, OnDocumentStart(_));
  1183. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1184. EXPECT_CALL(handler, OnScalar(_, "?", 0, "unquoted"));
  1185. EXPECT_CALL(handler, OnScalar(_, "!", 0, "separate"));
  1186. EXPECT_CALL(handler, OnScalar(_, "?", 0, "http://foo.com"));
  1187. EXPECT_CALL(handler, OnNull(_, 0));
  1188. EXPECT_CALL(handler, OnScalar(_, "?", 0, "omitted value"));
  1189. EXPECT_CALL(handler, OnNull(_, 0));
  1190. EXPECT_CALL(handler, OnNull(_, 0));
  1191. EXPECT_CALL(handler, OnScalar(_, "?", 0, "omitted key"));
  1192. EXPECT_CALL(handler, OnMapEnd());
  1193. EXPECT_CALL(handler, OnDocumentEnd());
  1194. Parse(ex7_17);
  1195. }
  1196. TEST_F(HandlerSpecTest, Ex7_18_FlowMappingAdjacentValues) {
  1197. EXPECT_CALL(handler, OnDocumentStart(_));
  1198. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1199. EXPECT_CALL(handler, OnScalar(_, "!", 0, "adjacent"));
  1200. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1201. EXPECT_CALL(handler, OnScalar(_, "!", 0, "readable"));
  1202. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1203. EXPECT_CALL(handler, OnScalar(_, "!", 0, "empty"));
  1204. EXPECT_CALL(handler, OnNull(_, 0));
  1205. EXPECT_CALL(handler, OnMapEnd());
  1206. EXPECT_CALL(handler, OnDocumentEnd());
  1207. Parse(ex7_18);
  1208. }
  1209. TEST_F(HandlerSpecTest, Ex7_19_SinglePairFlowMappings) {
  1210. EXPECT_CALL(handler, OnDocumentStart(_));
  1211. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1212. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1213. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  1214. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  1215. EXPECT_CALL(handler, OnMapEnd());
  1216. EXPECT_CALL(handler, OnSequenceEnd());
  1217. EXPECT_CALL(handler, OnDocumentEnd());
  1218. Parse(ex7_19);
  1219. }
  1220. TEST_F(HandlerSpecTest, Ex7_20_SinglePairExplicitEntry) {
  1221. EXPECT_CALL(handler, OnDocumentStart(_));
  1222. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1223. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1224. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo bar"));
  1225. EXPECT_CALL(handler, OnScalar(_, "?", 0, "baz"));
  1226. EXPECT_CALL(handler, OnMapEnd());
  1227. EXPECT_CALL(handler, OnSequenceEnd());
  1228. EXPECT_CALL(handler, OnDocumentEnd());
  1229. Parse(ex7_20);
  1230. }
  1231. TEST_F(HandlerSpecTest, Ex7_21_SinglePairImplicitEntries) {
  1232. EXPECT_CALL(handler, OnDocumentStart(_));
  1233. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1234. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1235. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1236. EXPECT_CALL(handler, OnScalar(_, "?", 0, "YAML"));
  1237. EXPECT_CALL(handler, OnScalar(_, "?", 0, "separate"));
  1238. EXPECT_CALL(handler, OnMapEnd());
  1239. EXPECT_CALL(handler, OnSequenceEnd());
  1240. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1241. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Default));
  1242. EXPECT_CALL(handler, OnNull(_, 0));
  1243. EXPECT_CALL(handler, OnScalar(_, "?", 0, "empty key entry"));
  1244. EXPECT_CALL(handler, OnMapEnd());
  1245. EXPECT_CALL(handler, OnSequenceEnd());
  1246. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1247. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1248. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1249. EXPECT_CALL(handler, OnScalar(_, "?", 0, "JSON"));
  1250. EXPECT_CALL(handler, OnScalar(_, "?", 0, "like"));
  1251. EXPECT_CALL(handler, OnMapEnd());
  1252. EXPECT_CALL(handler, OnScalar(_, "?", 0, "adjacent"));
  1253. EXPECT_CALL(handler, OnMapEnd());
  1254. EXPECT_CALL(handler, OnSequenceEnd());
  1255. EXPECT_CALL(handler, OnSequenceEnd());
  1256. EXPECT_CALL(handler, OnDocumentEnd());
  1257. Parse(ex7_21);
  1258. }
  1259. TEST_F(HandlerSpecTest, Ex7_22_InvalidImplicitKeys) {
  1260. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex7_22), ErrorMsg::END_OF_SEQ_FLOW);
  1261. }
  1262. TEST_F(HandlerSpecTest, Ex7_23_FlowContent) {
  1263. EXPECT_CALL(handler, OnDocumentStart(_));
  1264. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1265. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Flow));
  1266. EXPECT_CALL(handler, OnScalar(_, "?", 0, "a"));
  1267. EXPECT_CALL(handler, OnScalar(_, "?", 0, "b"));
  1268. EXPECT_CALL(handler, OnSequenceEnd());
  1269. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Flow));
  1270. EXPECT_CALL(handler, OnScalar(_, "?", 0, "a"));
  1271. EXPECT_CALL(handler, OnScalar(_, "?", 0, "b"));
  1272. EXPECT_CALL(handler, OnMapEnd());
  1273. EXPECT_CALL(handler, OnScalar(_, "!", 0, "a"));
  1274. EXPECT_CALL(handler, OnScalar(_, "!", 0, "b"));
  1275. EXPECT_CALL(handler, OnScalar(_, "?", 0, "c"));
  1276. EXPECT_CALL(handler, OnSequenceEnd());
  1277. EXPECT_CALL(handler, OnDocumentEnd());
  1278. Parse(ex7_23);
  1279. }
  1280. TEST_F(HandlerSpecTest, Ex7_24_FlowNodes) {
  1281. EXPECT_CALL(handler, OnDocumentStart(_));
  1282. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1283. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, "a"));
  1284. EXPECT_CALL(handler, OnScalar(_, "!", 0, "b"));
  1285. EXPECT_CALL(handler, OnAnchor(_, "anchor"));
  1286. EXPECT_CALL(handler, OnScalar(_, "!", 1, "c"));
  1287. EXPECT_CALL(handler, OnAlias(_, 1));
  1288. EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:str", 0, ""));
  1289. EXPECT_CALL(handler, OnSequenceEnd());
  1290. EXPECT_CALL(handler, OnDocumentEnd());
  1291. Parse(ex7_24);
  1292. }
  1293. TEST_F(HandlerSpecTest, Ex8_1_BlockScalarHeader) {
  1294. EXPECT_CALL(handler, OnDocumentStart(_));
  1295. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1296. EXPECT_CALL(handler, OnScalar(_, "!", 0, "literal\n"));
  1297. EXPECT_CALL(handler, OnScalar(_, "!", 0, " folded\n"));
  1298. EXPECT_CALL(handler, OnScalar(_, "!", 0, "keep\n\n"));
  1299. EXPECT_CALL(handler, OnScalar(_, "!", 0, " strip"));
  1300. EXPECT_CALL(handler, OnSequenceEnd());
  1301. EXPECT_CALL(handler, OnDocumentEnd());
  1302. Parse(ex8_1);
  1303. }
  1304. TEST_F(HandlerSpecTest, Ex8_2_BlockIndentationHeader) {
  1305. EXPECT_CALL(handler, OnDocumentStart(_));
  1306. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1307. EXPECT_CALL(handler, OnScalar(_, "!", 0, "detected\n"));
  1308. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\n\n# detected\n"));
  1309. EXPECT_CALL(handler, OnScalar(_, "!", 0, " explicit\n"));
  1310. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\t\ndetected\n"));
  1311. EXPECT_CALL(handler, OnSequenceEnd());
  1312. EXPECT_CALL(handler, OnDocumentEnd());
  1313. Parse(ex8_2);
  1314. }
  1315. TEST_F(HandlerSpecTest, Ex8_3a_InvalidBlockScalarIndentationIndicators) {
  1316. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex8_3a), ErrorMsg::END_OF_SEQ);
  1317. }
  1318. TEST_F(HandlerSpecTest, Ex8_3b_InvalidBlockScalarIndentationIndicators) {
  1319. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex8_3b), ErrorMsg::END_OF_SEQ);
  1320. }
  1321. TEST_F(HandlerSpecTest, Ex8_3c_InvalidBlockScalarIndentationIndicators) {
  1322. EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse(ex8_3c), ErrorMsg::END_OF_SEQ);
  1323. }
  1324. TEST_F(HandlerSpecTest, Ex8_4_ChompingFinalLineBreak) {
  1325. EXPECT_CALL(handler, OnDocumentStart(_));
  1326. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1327. EXPECT_CALL(handler, OnScalar(_, "?", 0, "strip"));
  1328. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text"));
  1329. EXPECT_CALL(handler, OnScalar(_, "?", 0, "clip"));
  1330. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text\n"));
  1331. EXPECT_CALL(handler, OnScalar(_, "?", 0, "keep"));
  1332. EXPECT_CALL(handler, OnScalar(_, "!", 0, "text\n"));
  1333. EXPECT_CALL(handler, OnMapEnd());
  1334. EXPECT_CALL(handler, OnDocumentEnd());
  1335. Parse(ex8_4);
  1336. }
  1337. TEST_F(HandlerSpecTest, DISABLED_Ex8_5_ChompingTrailingLines) {
  1338. EXPECT_CALL(handler, OnDocumentStart(_));
  1339. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1340. EXPECT_CALL(handler, OnScalar(_, "?", 0, "strip"));
  1341. EXPECT_CALL(handler, OnScalar(_, "!", 0, "# text"));
  1342. EXPECT_CALL(handler, OnScalar(_, "?", 0, "clip"));
  1343. EXPECT_CALL(handler, OnScalar(_, "!", 0, "# text\n"));
  1344. EXPECT_CALL(handler, OnScalar(_, "?", 0, "keep"));
  1345. // NOTE: I believe this is a bug in the YAML spec -
  1346. // it should be "# text\n\n"
  1347. EXPECT_CALL(handler, OnScalar(_, "!", 0, "# text\n"));
  1348. EXPECT_CALL(handler, OnMapEnd());
  1349. EXPECT_CALL(handler, OnDocumentEnd());
  1350. Parse(ex8_5);
  1351. }
  1352. TEST_F(HandlerSpecTest, Ex8_6_EmptyScalarChomping) {
  1353. EXPECT_CALL(handler, OnDocumentStart(_));
  1354. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1355. EXPECT_CALL(handler, OnScalar(_, "?", 0, "strip"));
  1356. EXPECT_CALL(handler, OnScalar(_, "!", 0, ""));
  1357. EXPECT_CALL(handler, OnScalar(_, "?", 0, "clip"));
  1358. EXPECT_CALL(handler, OnScalar(_, "!", 0, ""));
  1359. EXPECT_CALL(handler, OnScalar(_, "?", 0, "keep"));
  1360. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\n"));
  1361. EXPECT_CALL(handler, OnMapEnd());
  1362. EXPECT_CALL(handler, OnDocumentEnd());
  1363. Parse(ex8_6);
  1364. }
  1365. TEST_F(HandlerSpecTest, Ex8_7_LiteralScalar) {
  1366. EXPECT_CALL(handler, OnDocumentStart(_));
  1367. EXPECT_CALL(handler, OnScalar(_, "!", 0, "literal\n\ttext\n"));
  1368. EXPECT_CALL(handler, OnDocumentEnd());
  1369. Parse(ex8_7);
  1370. }
  1371. TEST_F(HandlerSpecTest, Ex8_8_LiteralContent) {
  1372. EXPECT_CALL(handler, OnDocumentStart(_));
  1373. EXPECT_CALL(handler, OnScalar(_, "!", 0, "\n\nliteral\n \n\ntext\n"));
  1374. EXPECT_CALL(handler, OnDocumentEnd());
  1375. Parse(ex8_8);
  1376. }
  1377. TEST_F(HandlerSpecTest, Ex8_9_FoldedScalar) {
  1378. EXPECT_CALL(handler, OnDocumentStart(_));
  1379. EXPECT_CALL(handler, OnScalar(_, "!", 0, "folded text\n"));
  1380. EXPECT_CALL(handler, OnDocumentEnd());
  1381. Parse(ex8_9);
  1382. }
  1383. TEST_F(HandlerSpecTest, Ex8_10_FoldedLines) {
  1384. EXPECT_CALL(handler, OnDocumentStart(_));
  1385. EXPECT_CALL(handler,
  1386. OnScalar(_, "!", 0,
  1387. "\nfolded line\nnext line\n * bullet\n\n * list\n * "
  1388. "lines\n\nlast line\n"));
  1389. EXPECT_CALL(handler, OnDocumentEnd());
  1390. Parse(ex8_10);
  1391. }
  1392. TEST_F(HandlerSpecTest, Ex8_11_MoreIndentedLines) {
  1393. EXPECT_CALL(handler, OnDocumentStart(_));
  1394. EXPECT_CALL(handler,
  1395. OnScalar(_, "!", 0,
  1396. "\nfolded line\nnext line\n * bullet\n\n * list\n * "
  1397. "lines\n\nlast line\n"));
  1398. EXPECT_CALL(handler, OnDocumentEnd());
  1399. Parse(ex8_11);
  1400. }
  1401. TEST_F(HandlerSpecTest, Ex8_12_EmptySeparationLines) {
  1402. EXPECT_CALL(handler, OnDocumentStart(_));
  1403. EXPECT_CALL(handler,
  1404. OnScalar(_, "!", 0,
  1405. "\nfolded line\nnext line\n * bullet\n\n * list\n * "
  1406. "lines\n\nlast line\n"));
  1407. EXPECT_CALL(handler, OnDocumentEnd());
  1408. Parse(ex8_12);
  1409. }
  1410. TEST_F(HandlerSpecTest, Ex8_13_FinalEmptyLines) {
  1411. EXPECT_CALL(handler, OnDocumentStart(_));
  1412. EXPECT_CALL(handler,
  1413. OnScalar(_, "!", 0,
  1414. "\nfolded line\nnext line\n * bullet\n\n * list\n * "
  1415. "lines\n\nlast line\n"));
  1416. EXPECT_CALL(handler, OnDocumentEnd());
  1417. Parse(ex8_13);
  1418. }
  1419. TEST_F(HandlerSpecTest, Ex8_14_BlockSequence) {
  1420. EXPECT_CALL(handler, OnDocumentStart(_));
  1421. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1422. EXPECT_CALL(handler, OnScalar(_, "?", 0, "block sequence"));
  1423. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1424. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1425. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1426. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1427. EXPECT_CALL(handler, OnScalar(_, "?", 0, "three"));
  1428. EXPECT_CALL(handler, OnMapEnd());
  1429. EXPECT_CALL(handler, OnSequenceEnd());
  1430. EXPECT_CALL(handler, OnMapEnd());
  1431. EXPECT_CALL(handler, OnDocumentEnd());
  1432. Parse(ex8_14);
  1433. }
  1434. TEST_F(HandlerSpecTest, Ex8_15_BlockSequenceEntryTypes) {
  1435. EXPECT_CALL(handler, OnDocumentStart(_));
  1436. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1437. EXPECT_CALL(handler, OnNull(_, 0));
  1438. EXPECT_CALL(handler, OnScalar(_, "!", 0, "block node\n"));
  1439. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1440. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1441. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1442. EXPECT_CALL(handler, OnSequenceEnd());
  1443. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1444. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1445. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1446. EXPECT_CALL(handler, OnMapEnd());
  1447. EXPECT_CALL(handler, OnSequenceEnd());
  1448. EXPECT_CALL(handler, OnDocumentEnd());
  1449. Parse(ex8_15);
  1450. }
  1451. TEST_F(HandlerSpecTest, Ex8_16_BlockMappings) {
  1452. EXPECT_CALL(handler, OnDocumentStart(_));
  1453. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1454. EXPECT_CALL(handler, OnScalar(_, "?", 0, "block mapping"));
  1455. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1456. EXPECT_CALL(handler, OnScalar(_, "?", 0, "key"));
  1457. EXPECT_CALL(handler, OnScalar(_, "?", 0, "value"));
  1458. EXPECT_CALL(handler, OnMapEnd());
  1459. EXPECT_CALL(handler, OnMapEnd());
  1460. EXPECT_CALL(handler, OnDocumentEnd());
  1461. Parse(ex8_16);
  1462. }
  1463. TEST_F(HandlerSpecTest, Ex8_17_ExplicitBlockMappingEntries) {
  1464. EXPECT_CALL(handler, OnDocumentStart(_));
  1465. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1466. EXPECT_CALL(handler, OnScalar(_, "?", 0, "explicit key"));
  1467. EXPECT_CALL(handler, OnNull(_, 0));
  1468. EXPECT_CALL(handler, OnScalar(_, "!", 0, "block key\n"));
  1469. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1470. EXPECT_CALL(handler, OnScalar(_, "?", 0, "one"));
  1471. EXPECT_CALL(handler, OnScalar(_, "?", 0, "two"));
  1472. EXPECT_CALL(handler, OnSequenceEnd());
  1473. EXPECT_CALL(handler, OnMapEnd());
  1474. EXPECT_CALL(handler, OnDocumentEnd());
  1475. Parse(ex8_17);
  1476. }
  1477. TEST_F(HandlerSpecTest, Ex8_18_ImplicitBlockMappingEntries) {
  1478. EXPECT_CALL(handler, OnDocumentStart(_));
  1479. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1480. EXPECT_CALL(handler, OnScalar(_, "?", 0, "plain key"));
  1481. EXPECT_CALL(handler, OnScalar(_, "?", 0, "in-line value"));
  1482. EXPECT_CALL(handler, OnNull(_, 0));
  1483. EXPECT_CALL(handler, OnNull(_, 0));
  1484. EXPECT_CALL(handler, OnScalar(_, "!", 0, "quoted key"));
  1485. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1486. EXPECT_CALL(handler, OnScalar(_, "?", 0, "entry"));
  1487. EXPECT_CALL(handler, OnSequenceEnd());
  1488. EXPECT_CALL(handler, OnMapEnd());
  1489. EXPECT_CALL(handler, OnDocumentEnd());
  1490. Parse(ex8_18);
  1491. }
  1492. TEST_F(HandlerSpecTest, Ex8_19_CompactBlockMappings) {
  1493. EXPECT_CALL(handler, OnDocumentStart(_));
  1494. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1495. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1496. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sun"));
  1497. EXPECT_CALL(handler, OnScalar(_, "?", 0, "yellow"));
  1498. EXPECT_CALL(handler, OnMapEnd());
  1499. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1500. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1501. EXPECT_CALL(handler, OnScalar(_, "?", 0, "earth"));
  1502. EXPECT_CALL(handler, OnScalar(_, "?", 0, "blue"));
  1503. EXPECT_CALL(handler, OnMapEnd());
  1504. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1505. EXPECT_CALL(handler, OnScalar(_, "?", 0, "moon"));
  1506. EXPECT_CALL(handler, OnScalar(_, "?", 0, "white"));
  1507. EXPECT_CALL(handler, OnMapEnd());
  1508. EXPECT_CALL(handler, OnMapEnd());
  1509. EXPECT_CALL(handler, OnSequenceEnd());
  1510. EXPECT_CALL(handler, OnDocumentEnd());
  1511. Parse(ex8_19);
  1512. }
  1513. TEST_F(HandlerSpecTest, Ex8_20_BlockNodeTypes) {
  1514. EXPECT_CALL(handler, OnDocumentStart(_));
  1515. EXPECT_CALL(handler, OnSequenceStart(_, "?", 0, EmitterStyle::Block));
  1516. EXPECT_CALL(handler, OnScalar(_, "!", 0, "flow in block"));
  1517. EXPECT_CALL(handler, OnScalar(_, "!", 0, "Block scalar\n"));
  1518. EXPECT_CALL(handler,
  1519. OnMapStart(_, "tag:yaml.org,2002:map", 0, EmitterStyle::Block));
  1520. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  1521. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  1522. EXPECT_CALL(handler, OnMapEnd());
  1523. EXPECT_CALL(handler, OnSequenceEnd());
  1524. EXPECT_CALL(handler, OnDocumentEnd());
  1525. Parse(ex8_20);
  1526. }
  1527. TEST_F(HandlerSpecTest, DISABLED_Ex8_21_BlockScalarNodes) {
  1528. EXPECT_CALL(handler, OnDocumentStart(_));
  1529. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1530. EXPECT_CALL(handler, OnScalar(_, "?", 0, "literal"));
  1531. // NOTE: I believe this is a bug in the YAML spec
  1532. // - it should be "value\n"
  1533. EXPECT_CALL(handler, OnScalar(_, "!", 0, "value"));
  1534. EXPECT_CALL(handler, OnScalar(_, "?", 0, "folded"));
  1535. EXPECT_CALL(handler, OnScalar(_, "!foo", 0, "value"));
  1536. EXPECT_CALL(handler, OnMapEnd());
  1537. EXPECT_CALL(handler, OnDocumentEnd());
  1538. Parse(ex8_21);
  1539. }
  1540. TEST_F(HandlerSpecTest, Ex8_22_BlockCollectionNodes) {
  1541. EXPECT_CALL(handler, OnDocumentStart(_));
  1542. EXPECT_CALL(handler, OnMapStart(_, "?", 0, EmitterStyle::Block));
  1543. EXPECT_CALL(handler, OnScalar(_, "?", 0, "sequence"));
  1544. EXPECT_CALL(handler, OnSequenceStart(_, "tag:yaml.org,2002:seq", 0,
  1545. EmitterStyle::Block));
  1546. EXPECT_CALL(handler, OnScalar(_, "?", 0, "entry"));
  1547. EXPECT_CALL(handler, OnSequenceStart(_, "tag:yaml.org,2002:seq", 0,
  1548. EmitterStyle::Block));
  1549. EXPECT_CALL(handler, OnScalar(_, "?", 0, "nested"));
  1550. EXPECT_CALL(handler, OnSequenceEnd());
  1551. EXPECT_CALL(handler, OnSequenceEnd());
  1552. EXPECT_CALL(handler, OnScalar(_, "?", 0, "mapping"));
  1553. EXPECT_CALL(handler,
  1554. OnMapStart(_, "tag:yaml.org,2002:map", 0, EmitterStyle::Block));
  1555. EXPECT_CALL(handler, OnScalar(_, "?", 0, "foo"));
  1556. EXPECT_CALL(handler, OnScalar(_, "?", 0, "bar"));
  1557. EXPECT_CALL(handler, OnMapEnd());
  1558. EXPECT_CALL(handler, OnMapEnd());
  1559. EXPECT_CALL(handler, OnDocumentEnd());
  1560. Parse(ex8_22);
  1561. }
  1562. } // namespace
  1563. } // namespace YAML