remove button colors from quarks gui (cocoa + swing)
[supercollider.git] / external_libraries / yaml-cpp-0.2.6 / test / parsertests.cpp
blob7b4174e7eace355772845345a9a716d656cf5d31
1 #include "tests.h"
2 #include "yaml-cpp/yaml.h"
3 #include <sstream>
4 #include <algorithm>
6 namespace Test
8 namespace Parser {
9 void SimpleScalar(std::string& inputScalar, std::string& desiredOutput)
11 inputScalar = "Hello, World!";
12 desiredOutput = "Hello, World!";
15 void MultiLineScalar(std::string& inputScalar, std::string& desiredOutput)
17 inputScalar =
18 "normal scalar, but\n"
19 "over several lines";
20 desiredOutput = "normal scalar, but over several lines";
23 void LiteralScalar(std::string& inputScalar, std::string& desiredOutput)
25 inputScalar =
26 "|\n"
27 " literal scalar - so we can draw ASCII:\n"
28 " \n"
29 " - -\n"
30 " | - |\n"
31 " -----\n";
32 desiredOutput =
33 "literal scalar - so we can draw ASCII:\n"
34 "\n"
35 " - -\n"
36 " | - |\n"
37 " -----\n";
40 void FoldedScalar(std::string& inputScalar, std::string& desiredOutput)
42 inputScalar =
43 ">\n"
44 " and a folded scalar... so we\n"
45 " can just keep writing various\n"
46 " things. And if we want to keep indentation:\n"
47 " \n"
48 " we just indent a little\n"
49 " see, this stays indented";
50 desiredOutput =
51 "and a folded scalar... so we"
52 " can just keep writing various"
53 " things. And if we want to keep indentation:\n"
54 "\n"
55 " we just indent a little\n"
56 " see, this stays indented";
59 void ChompedFoldedScalar(std::string& inputScalar, std::string& desiredOutput)
61 inputScalar =
62 ">-\n"
63 " Here's a folded scalar\n"
64 " that gets chomped.";
65 desiredOutput =
66 "Here's a folded scalar"
67 " that gets chomped.";
70 void ChompedLiteralScalar(std::string& inputScalar, std::string& desiredOutput)
72 inputScalar =
73 "|-\n"
74 " Here's a literal scalar\n"
75 " that gets chomped.";
76 desiredOutput =
77 "Here's a literal scalar\n"
78 "that gets chomped.";
81 void FoldedScalarWithIndent(std::string& inputScalar, std::string& desiredOutput)
83 inputScalar =
84 ">2\n"
85 " Here's a folded scalar\n"
86 " that starts with some indentation.";
87 desiredOutput =
88 " Here's a folded scalar\n"
89 "that starts with some indentation.";
92 void ColonScalar(std::string& inputScalar, std::string& desiredOutput)
94 inputScalar = "::vector";
95 desiredOutput = "::vector";
98 void QuotedScalar(std::string& inputScalar, std::string& desiredOutput)
100 inputScalar = "\": - ()\"";
101 desiredOutput = ": - ()";
104 void CommaScalar(std::string& inputScalar, std::string& desiredOutput)
106 inputScalar = "Up, up, and away!";
107 desiredOutput = "Up, up, and away!";
110 void DashScalar(std::string& inputScalar, std::string& desiredOutput)
112 inputScalar = "-123";
113 desiredOutput = "-123";
116 void URLScalar(std::string& inputScalar, std::string& desiredOutput)
118 inputScalar = "http://example.com/foo#bar";
119 desiredOutput = "http://example.com/foo#bar";
122 bool SimpleSeq()
124 std::string input =
125 "- eggs\n"
126 "- bread\n"
127 "- milk";
129 std::stringstream stream(input);
130 YAML::Parser parser(stream);
131 YAML::Node doc;
132 parser.GetNextDocument(doc);
134 std::string output;
135 if(doc[0].to<std::string>() != "eggs")
136 return false;
137 if(doc[1].to<std::string>() != "bread")
138 return false;
139 if(doc[2].to<std::string>() != "milk")
140 return false;
142 return true;
145 bool SimpleMap()
147 std::string input =
148 "name: Prince Fielder\n"
149 "position: 1B\n"
150 "bats: L";
152 std::stringstream stream(input);
153 YAML::Parser parser(stream);
154 YAML::Node doc;
155 parser.GetNextDocument(doc);
157 std::string output;
158 doc["name"] >> output;
159 if(output != "Prince Fielder")
160 return false;
161 doc["position"] >> output;
162 if(output != "1B")
163 return false;
164 doc["bats"] >> output;
165 if(output != "L")
166 return false;
168 return true;
171 bool FlowSeq()
173 std::string input = "[ 2 , 3, 5 , 7, 11]";
175 std::stringstream stream(input);
176 YAML::Parser parser(stream);
177 YAML::Node doc;
178 parser.GetNextDocument(doc);
180 int output;
181 doc[0] >> output;
182 if(output != 2)
183 return false;
184 doc[1] >> output;
185 if(output != 3)
186 return false;
187 doc[2] >> output;
188 if(output != 5)
189 return false;
190 doc[3] >> output;
191 if(output != 7)
192 return false;
193 doc[4] >> output;
194 if(output != 11)
195 return false;
197 return true;
200 bool FlowMap()
202 std::string input = "{hr: 65, avg: 0.278}";
204 std::stringstream stream(input);
205 YAML::Parser parser(stream);
206 YAML::Node doc;
207 parser.GetNextDocument(doc);
209 std::string output;
210 doc["hr"] >> output;
211 if(output != "65")
212 return false;
213 doc["avg"] >> output;
214 if(output != "0.278")
215 return false;
217 return true;
220 bool FlowMapWithOmittedKey()
222 std::string input = "{: omitted key}";
223 std::stringstream stream(input);
224 YAML::Parser parser(stream);
225 YAML::Node doc;
226 parser.GetNextDocument(doc);
228 std::string output;
229 doc[YAML::Null] >> output;
230 if(output != "omitted key")
231 return false;
233 return true;
236 bool FlowMapWithOmittedValue()
238 std::string input = "{a: b, c:, d:}";
239 std::stringstream stream(input);
240 YAML::Parser parser(stream);
241 YAML::Node doc;
242 parser.GetNextDocument(doc);
244 std::string output;
245 doc["a"] >> output;
246 if(output != "b")
247 return false;
248 if(!IsNull(doc["c"]))
249 return false;
250 if(!IsNull(doc["d"]))
251 return false;
253 return true;
256 bool FlowMapWithSoloEntry()
258 std::string input = "{a: b, c, d: e}";
259 std::stringstream stream(input);
260 YAML::Parser parser(stream);
261 YAML::Node doc;
262 parser.GetNextDocument(doc);
264 std::string output;
265 doc["a"] >> output;
266 if(output != "b")
267 return false;
268 if(!IsNull(doc["c"]))
269 return false;
270 doc["d"] >> output;
271 if(output != "e")
272 return false;
274 return true;
277 bool FlowMapEndingWithSoloEntry()
279 std::string input = "{a: b, c}";
280 std::stringstream stream(input);
281 YAML::Parser parser(stream);
282 YAML::Node doc;
283 parser.GetNextDocument(doc);
285 std::string output;
286 doc["a"] >> output;
287 if(output != "b")
288 return false;
289 if(!IsNull(doc["c"]))
290 return false;
292 return true;
295 bool QuotedSimpleKeys()
297 std::string KeyValue[3] = { "\"double\": double\n", "'single': single\n", "plain: plain\n" };
299 int perm[3] = { 0, 1, 2 };
300 do {
301 std::string input = KeyValue[perm[0]] + KeyValue[perm[1]] + KeyValue[perm[2]];
303 std::stringstream stream(input);
304 YAML::Parser parser(stream);
305 YAML::Node doc;
306 parser.GetNextDocument(doc);
308 std::string output;
309 doc["double"] >> output;
310 if(output != "double")
311 return false;
312 doc["single"] >> output;
313 if(output != "single")
314 return false;
315 doc["plain"] >> output;
316 if(output != "plain")
317 return false;
318 } while(std::next_permutation(perm, perm + 3));
320 return true;
323 bool CompressedMapAndSeq()
325 std::string input = "key:\n- one\n- two";
327 std::stringstream stream(input);
328 YAML::Parser parser(stream);
329 YAML::Node doc;
330 parser.GetNextDocument(doc);
332 const YAML::Node& seq = doc["key"];
333 if(seq.size() != 2)
334 return false;
336 std::string output;
337 seq[0] >> output;
338 if(output != "one")
339 return false;
340 seq[1] >> output;
341 if(output != "two")
342 return false;
344 return true;
347 bool NullBlockSeqEntry()
349 std::string input = "- hello\n-\n- world";
351 std::stringstream stream(input);
352 YAML::Parser parser(stream);
353 YAML::Node doc;
354 parser.GetNextDocument(doc);
356 std::string output;
357 doc[0] >> output;
358 if(output != "hello")
359 return false;
360 if(!IsNull(doc[1]))
361 return false;
362 doc[2] >> output;
363 if(output != "world")
364 return false;
366 return true;
369 bool NullBlockMapKey()
371 std::string input = ": empty key";
373 std::stringstream stream(input);
374 YAML::Parser parser(stream);
375 YAML::Node doc;
376 parser.GetNextDocument(doc);
378 std::string output;
379 doc[YAML::Null] >> output;
380 if(output != "empty key")
381 return false;
383 return true;
386 bool NullBlockMapValue()
388 std::string input = "empty value:";
390 std::stringstream stream(input);
391 YAML::Parser parser(stream);
392 YAML::Node doc;
393 parser.GetNextDocument(doc);
395 if(!IsNull(doc["empty value"]))
396 return false;
398 return true;
401 bool SimpleAlias()
403 std::string input = "- &alias test\n- *alias";
405 std::stringstream stream(input);
406 YAML::Parser parser(stream);
407 YAML::Node doc;
408 parser.GetNextDocument(doc);
410 std::string output;
411 doc[0] >> output;
412 if(output != "test")
413 return false;
415 doc[1] >> output;
416 if(output != "test")
417 return false;
419 if(doc.size() != 2)
420 return false;
422 return true;
425 bool AliasWithNull()
427 std::string input = "- &alias\n- *alias";
429 std::stringstream stream(input);
430 YAML::Parser parser(stream);
431 YAML::Node doc;
432 parser.GetNextDocument(doc);
434 if(!IsNull(doc[0]))
435 return false;
437 if(!IsNull(doc[1]))
438 return false;
440 if(doc.size() != 2)
441 return false;
443 return true;
446 bool AnchorInSimpleKey()
448 std::string input = "- &a b: c\n- *a";
450 std::stringstream stream(input);
451 YAML::Parser parser(stream);
452 YAML::Node doc;
453 parser.GetNextDocument(doc);
455 if(doc.size() != 2)
456 return false;
458 std::string output;
459 doc[0]["b"] >> output;
460 if(output != "c")
461 return false;
463 doc[1] >> output;
464 if(output != "b")
465 return false;
467 return true;
470 bool AliasAsSimpleKey()
472 std::string input = "- &a b\n- *a : c";
474 std::stringstream stream(input);
475 YAML::Parser parser(stream);
476 YAML::Node doc;
477 parser.GetNextDocument(doc);
479 if(doc.size() != 2)
480 return false;
482 std::string output;
483 doc[0] >> output;
484 if(output != "b")
485 return false;
487 doc[1]["b"] >> output;
488 if(output != "c")
489 return false;
491 return true;
494 bool ExplicitDoc()
496 std::string input = "---\n- one\n- two";
498 std::stringstream stream(input);
499 YAML::Parser parser(stream);
500 YAML::Node doc;
501 parser.GetNextDocument(doc);
503 if(doc.size() != 2)
504 return false;
506 std::string output;
507 doc[0] >> output;
508 if(output != "one")
509 return false;
510 doc[1] >> output;
511 if(output != "two")
512 return false;
514 return true;
517 bool MultipleDocs()
519 std::string input = "---\nname: doc1\n---\nname: doc2";
521 std::stringstream stream(input);
522 YAML::Parser parser(stream);
523 YAML::Node doc;
524 parser.GetNextDocument(doc);
526 std::string output;
527 doc["name"] >> output;
528 if(output != "doc1")
529 return false;
531 if(!parser)
532 return false;
534 parser.GetNextDocument(doc);
535 doc["name"] >> output;
536 if(output != "doc2")
537 return false;
539 return true;
542 bool ExplicitEndDoc()
544 std::string input = "- one\n- two\n...\n...";
546 std::stringstream stream(input);
547 YAML::Parser parser(stream);
548 YAML::Node doc;
549 parser.GetNextDocument(doc);
551 if(doc.size() != 2)
552 return false;
554 std::string output;
555 doc[0] >> output;
556 if(output != "one")
557 return false;
558 doc[1] >> output;
559 if(output != "two")
560 return false;
562 return true;
565 bool MultipleDocsWithSomeExplicitIndicators()
567 std::string input =
568 "- one\n- two\n...\n"
569 "---\nkey: value\n...\n...\n"
570 "- three\n- four\n"
571 "---\nkey: value";
573 std::stringstream stream(input);
574 YAML::Parser parser(stream);
575 YAML::Node doc;
576 std::string output;
578 parser.GetNextDocument(doc);
579 if(doc.size() != 2)
580 return false;
581 doc[0] >> output;
582 if(output != "one")
583 return false;
584 doc[1] >> output;
585 if(output != "two")
586 return false;
588 parser.GetNextDocument(doc);
589 doc["key"] >> output;
590 if(output != "value")
591 return false;
593 parser.GetNextDocument(doc);
594 if(doc.size() != 2)
595 return false;
596 doc[0] >> output;
597 if(output != "three")
598 return false;
599 doc[1] >> output;
600 if(output != "four")
601 return false;
603 parser.GetNextDocument(doc);
604 doc["key"] >> output;
605 if(output != "value")
606 return false;
608 return true;
611 bool BlockKeyWithNullValue()
613 std::string input =
614 "key:\n"
615 "just a key: value";
617 std::stringstream stream(input);
618 YAML::Parser parser(stream);
619 YAML::Node doc;
621 parser.GetNextDocument(doc);
622 if(doc.size() != 2)
623 return false;
624 if(!IsNull(doc["key"]))
625 return false;
626 if(doc["just a key"].to<std::string>() != "value")
627 return false;
629 return true;
632 bool Bases()
634 std::string input =
635 "- 15\n"
636 "- 0x10\n"
637 "- 030\n"
638 "- 0xffffffff\n";
640 std::stringstream stream(input);
641 YAML::Parser parser(stream);
642 YAML::Node doc;
644 parser.GetNextDocument(doc);
645 if(doc.size() != 4)
646 return false;
647 if(doc[0].to<int>() != 15)
648 return false;
649 if(doc[1].to<int>() != 0x10)
650 return false;
651 if(doc[2].to<int>() != 030)
652 return false;
653 if(doc[3].to<unsigned>() != 0xffffffff)
654 return false;
655 return true;
658 bool KeyNotFound()
660 std::string input = "key: value";
661 std::stringstream stream(input);
662 YAML::Parser parser(stream);
663 YAML::Node doc;
664 parser.GetNextDocument(doc);
666 try {
667 doc["bad key"];
668 } catch(const YAML::Exception& e) {
669 if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": bad key")
670 throw;
673 try {
674 doc[5];
675 } catch(const YAML::Exception& e) {
676 if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": 5")
677 throw;
680 try {
681 doc[2.5];
682 } catch(const YAML::Exception& e) {
683 if(e.msg != std::string(YAML::ErrorMsg::KEY_NOT_FOUND) + ": 2.5")
684 throw;
687 return true;
690 bool DuplicateKey()
692 std::string input = "{a: 1, b: 2, c: 3, a: 4}";
693 std::stringstream stream(input);
694 YAML::Parser parser(stream);
695 YAML::Node doc;
696 parser.GetNextDocument(doc);
698 if(doc["a"].to<int>() != 4)
699 return false;
700 if(doc["b"].to<int>() != 2)
701 return false;
702 if(doc["c"].to<int>() != 3)
703 return false;
704 return true;
707 void PrepareNodeForTagExam(YAML::Node& doc, const std::string& input)
709 std::stringstream stream(input);
710 YAML::Parser parser(stream);
711 parser.GetNextDocument(doc);
714 struct TagMismatch: public std::exception {
715 TagMismatch(const std::string& actualTag, const std::string& expectedTag) {
716 std::stringstream output;
717 output << "Tag has value \"" << actualTag << "\" but \"" << expectedTag << "\" was expected";
718 what_ = output.str();
720 virtual ~TagMismatch() throw() {}
721 virtual const char *what() const throw() { return what_.c_str(); }
723 private:
724 std::string what_;
727 bool ExpectedTagValue(YAML::Node& node, const char* tag)
729 if(node.Tag() == tag)
730 return true;
732 throw TagMismatch(node.Tag(), tag);
735 bool DefaultPlainScalarTag()
737 YAML::Node node;
738 PrepareNodeForTagExam(node, "--- 12");
740 return ExpectedTagValue(node, "?");
743 bool DefaultSingleQuotedScalarTag()
745 YAML::Node node;
746 PrepareNodeForTagExam(node, "--- '12'");
748 return ExpectedTagValue(node, "!");
751 bool ExplicitNonSpecificPlainScalarTag()
753 YAML::Node node;
754 PrepareNodeForTagExam(node, "--- ! 12");
756 return ExpectedTagValue(node, "!");
759 bool BasicLocalTag()
761 YAML::Node node;
762 PrepareNodeForTagExam(node, "--- !foo 12");
764 return ExpectedTagValue(node, "!foo");
767 bool VerbatimLocalTag()
769 YAML::Node node;
770 PrepareNodeForTagExam(node, "--- !<!foo> 12");
772 return ExpectedTagValue(node, "!foo");
775 bool StandardShortcutTag()
777 YAML::Node node;
778 PrepareNodeForTagExam(node, "--- !!int 12");
780 return ExpectedTagValue(node, "tag:yaml.org,2002:int");
783 bool VerbatimURITag()
785 YAML::Node node;
786 PrepareNodeForTagExam(node, "--- !<tag:yaml.org,2002:int> 12");
788 return ExpectedTagValue(node, "tag:yaml.org,2002:int");
791 bool DefaultSequenceTag()
793 YAML::Node node;
794 PrepareNodeForTagExam(node, "--- [12]");
796 return ExpectedTagValue(node, "?");
799 bool ExplicitNonSpecificSequenceTag()
801 YAML::Node node;
802 PrepareNodeForTagExam(node, "--- ! [12]");
804 return ExpectedTagValue(node, "!");
808 namespace {
809 void RunScalarParserTest(void (*test)(std::string&, std::string&), const std::string& name, int& passed, int& total) {
810 std::string error;
811 std::string inputScalar, desiredOutput;
812 std::string output;
813 bool ok = true;
814 try {
815 test(inputScalar, desiredOutput);
816 std::stringstream stream(inputScalar);
817 YAML::Parser parser(stream);
818 YAML::Node doc;
819 parser.GetNextDocument(doc);
820 doc >> output;
821 } catch(const YAML::Exception& e) {
822 ok = false;
823 error = e.what();
825 if(ok && output == desiredOutput) {
826 passed++;
827 } else {
828 std::cout << "Parser test failed: " << name << "\n";
829 if(error != "")
830 std::cout << "Caught exception: " << error << "\n";
831 else {
832 std::cout << "Output:\n" << output << "<<<\n";
833 std::cout << "Desired output:\n" << desiredOutput << "<<<\n";
836 total++;
839 void RunParserTest(bool (*test)(), const std::string& name, int& passed, int& total) {
840 std::string error;
841 bool ok = true;
842 try {
843 ok = test();
844 } catch(const YAML::Exception& e) {
845 ok = false;
846 error = e.what();
847 } catch(const Parser::TagMismatch& e) {
848 ok = false;
849 error = e.what();
851 if(ok) {
852 passed++;
853 } else {
854 std::cout << "Parser test failed: " << name << "\n";
855 if(error != "")
856 std::cout << "Caught exception: " << error << "\n";
858 total++;
861 typedef void (*EncodingFn)(std::ostream&, int);
863 inline char Byte(int ch)
865 return static_cast<char>(static_cast<unsigned char>(static_cast<unsigned int>(ch)));
868 void EncodeToUtf8(std::ostream& stream, int ch)
870 if (ch <= 0x7F)
872 stream << Byte(ch);
874 else if (ch <= 0x7FF)
876 stream << Byte(0xC0 | (ch >> 6));
877 stream << Byte(0x80 | (ch & 0x3F));
879 else if (ch <= 0xFFFF)
881 stream << Byte(0xE0 | (ch >> 12));
882 stream << Byte(0x80 | ((ch >> 6) & 0x3F));
883 stream << Byte(0x80 | (ch & 0x3F));
885 else if (ch <= 0x1FFFFF)
887 stream << Byte(0xF0 | (ch >> 18));
888 stream << Byte(0x80 | ((ch >> 12) & 0x3F));
889 stream << Byte(0x80 | ((ch >> 6) & 0x3F));
890 stream << Byte(0x80 | (ch & 0x3F));
894 bool SplitUtf16HighChar(std::ostream& stream, EncodingFn encoding, int ch)
896 int biasedValue = ch - 0x10000;
897 if (biasedValue < 0)
899 return false;
901 int high = 0xD800 | (biasedValue >> 10);
902 int low = 0xDC00 | (biasedValue & 0x3FF);
903 encoding(stream, high);
904 encoding(stream, low);
905 return true;
908 void EncodeToUtf16LE(std::ostream& stream, int ch)
910 if (!SplitUtf16HighChar(stream, &EncodeToUtf16LE, ch))
912 stream << Byte(ch & 0xFF) << Byte(ch >> 8);
916 void EncodeToUtf16BE(std::ostream& stream, int ch)
918 if (!SplitUtf16HighChar(stream, &EncodeToUtf16BE, ch))
920 stream << Byte(ch >> 8) << Byte(ch & 0xFF);
924 void EncodeToUtf32LE(std::ostream& stream, int ch)
926 stream << Byte(ch & 0xFF) << Byte((ch >> 8) & 0xFF)
927 << Byte((ch >> 16) & 0xFF) << Byte((ch >> 24) & 0xFF);
930 void EncodeToUtf32BE(std::ostream& stream, int ch)
932 stream << Byte((ch >> 24) & 0xFF) << Byte((ch >> 16) & 0xFF)
933 << Byte((ch >> 8) & 0xFF) << Byte(ch & 0xFF);
936 class EncodingTester
938 public:
939 EncodingTester(EncodingFn encoding, bool declareEncoding)
941 if (declareEncoding)
943 encoding(m_yaml, 0xFEFF);
946 AddEntry(encoding, 0x0021, 0x007E); // Basic Latin
947 AddEntry(encoding, 0x00A1, 0x00FF); // Latin-1 Supplement
948 AddEntry(encoding, 0x0660, 0x06FF); // Arabic (largest contiguous block)
950 // CJK unified ideographs (multiple lines)
951 AddEntry(encoding, 0x4E00, 0x4EFF);
952 AddEntry(encoding, 0x4F00, 0x4FFF);
953 AddEntry(encoding, 0x5000, 0x51FF); // 512 character line
954 AddEntry(encoding, 0x5200, 0x54FF); // 768 character line
955 AddEntry(encoding, 0x5500, 0x58FF); // 1024 character line
957 AddEntry(encoding, 0x103A0, 0x103C3); // Old Persian
959 m_yaml.seekg(0, std::ios::beg);
962 std::istream& stream() {return m_yaml;}
963 const std::vector<std::string>& entries() {return m_entries;}
965 private:
966 std::stringstream m_yaml;
967 std::vector<std::string> m_entries;
969 void AddEntry(EncodingFn encoding, int startCh, int endCh)
971 encoding(m_yaml, '-');
972 encoding(m_yaml, ' ');
973 encoding(m_yaml, '|');
974 encoding(m_yaml, '\n');
975 encoding(m_yaml, ' ');
976 encoding(m_yaml, ' ');
978 std::stringstream entry;
979 for (int ch = startCh; ch <= endCh; ++ch)
981 encoding(m_yaml, ch);
982 EncodeToUtf8(entry, ch);
984 encoding(m_yaml, '\n');
986 m_entries.push_back(entry.str());
990 void RunEncodingTest(EncodingFn encoding, bool declareEncoding, const std::string& name, int& passed, int& total)
992 EncodingTester tester(encoding, declareEncoding);
993 std::string error;
994 bool ok = true;
995 try {
996 YAML::Parser parser(tester.stream());
997 YAML::Node doc;
998 parser.GetNextDocument(doc);
1000 YAML::Iterator itNode = doc.begin();
1001 std::vector<std::string>::const_iterator itEntry = tester.entries().begin();
1002 for (; (itNode != doc.end()) && (itEntry != tester.entries().end()); ++itNode, ++itEntry)
1004 std::string stScalarValue;
1005 if (!itNode->GetScalar(stScalarValue) && (stScalarValue == *itEntry))
1007 break;
1011 if ((itNode != doc.end()) || (itEntry != tester.entries().end()))
1013 ok = false;
1015 } catch(const YAML::Exception& e) {
1016 ok = false;
1017 error = e.msg;
1019 if(ok) {
1020 passed++;
1021 } else {
1022 std::cout << "Parser test failed: " << name << "\n";
1023 if(error != "")
1024 std::cout << "Caught exception: " << error << "\n";
1026 total++;
1030 bool RunParserTests()
1032 int passed = 0;
1033 int total = 0;
1034 RunScalarParserTest(&Parser::SimpleScalar, "simple scalar", passed, total);
1035 RunScalarParserTest(&Parser::MultiLineScalar, "multi-line scalar", passed, total);
1036 RunScalarParserTest(&Parser::LiteralScalar, "literal scalar", passed, total);
1037 RunScalarParserTest(&Parser::FoldedScalar, "folded scalar", passed, total);
1038 RunScalarParserTest(&Parser::ChompedFoldedScalar, "chomped folded scalar", passed, total);
1039 RunScalarParserTest(&Parser::ChompedLiteralScalar, "chomped literal scalar", passed, total);
1040 RunScalarParserTest(&Parser::FoldedScalarWithIndent, "folded scalar with indent", passed, total);
1041 RunScalarParserTest(&Parser::ColonScalar, "colon scalar", passed, total);
1042 RunScalarParserTest(&Parser::QuotedScalar, "quoted scalar", passed, total);
1043 RunScalarParserTest(&Parser::CommaScalar, "comma scalar", passed, total);
1044 RunScalarParserTest(&Parser::DashScalar, "dash scalar", passed, total);
1045 RunScalarParserTest(&Parser::URLScalar, "url scalar", passed, total);
1047 RunParserTest(&Parser::SimpleSeq, "simple seq", passed, total);
1048 RunParserTest(&Parser::SimpleMap, "simple map", passed, total);
1049 RunParserTest(&Parser::FlowSeq, "flow seq", passed, total);
1050 RunParserTest(&Parser::FlowMap, "flow map", passed, total);
1051 RunParserTest(&Parser::FlowMapWithOmittedKey, "flow map with omitted key", passed, total);
1052 RunParserTest(&Parser::FlowMapWithOmittedValue, "flow map with omitted value", passed, total);
1053 RunParserTest(&Parser::FlowMapWithSoloEntry, "flow map with solo entry", passed, total);
1054 RunParserTest(&Parser::FlowMapEndingWithSoloEntry, "flow map ending with solo entry", passed, total);
1055 RunParserTest(&Parser::QuotedSimpleKeys, "quoted simple keys", passed, total);
1056 RunParserTest(&Parser::CompressedMapAndSeq, "compressed map and seq", passed, total);
1057 RunParserTest(&Parser::NullBlockSeqEntry, "null block seq entry", passed, total);
1058 RunParserTest(&Parser::NullBlockMapKey, "null block map key", passed, total);
1059 RunParserTest(&Parser::NullBlockMapValue, "null block map value", passed, total);
1060 RunParserTest(&Parser::SimpleAlias, "simple alias", passed, total);
1061 RunParserTest(&Parser::AliasWithNull, "alias with null", passed, total);
1062 RunParserTest(&Parser::AnchorInSimpleKey, "anchor in simple key", passed, total);
1063 RunParserTest(&Parser::AliasAsSimpleKey, "alias as simple key", passed, total);
1064 RunParserTest(&Parser::ExplicitDoc, "explicit doc", passed, total);
1065 RunParserTest(&Parser::MultipleDocs, "multiple docs", passed, total);
1066 RunParserTest(&Parser::ExplicitEndDoc, "explicit end doc", passed, total);
1067 RunParserTest(&Parser::MultipleDocsWithSomeExplicitIndicators, "multiple docs with some explicit indicators", passed, total);
1068 RunParserTest(&Parser::BlockKeyWithNullValue, "block key with null value", passed, total);
1069 RunParserTest(&Parser::Bases, "bases", passed, total);
1070 RunParserTest(&Parser::KeyNotFound, "key not found", passed, total);
1071 RunParserTest(&Parser::DuplicateKey, "duplicate key", passed, total);
1072 RunParserTest(&Parser::DefaultPlainScalarTag, "default plain scalar tag", passed, total);
1073 RunParserTest(&Parser::DefaultSingleQuotedScalarTag, "default single-quoted scalar tag", passed, total);
1074 RunParserTest(&Parser::ExplicitNonSpecificPlainScalarTag, "explicit, non-specific plain scalar tag", passed, total);
1075 RunParserTest(&Parser::BasicLocalTag, "basic local tag", passed, total);
1076 RunParserTest(&Parser::VerbatimLocalTag, "verbatim local tag", passed, total);
1077 RunParserTest(&Parser::StandardShortcutTag, "standard shortcut tag", passed, total);
1078 RunParserTest(&Parser::VerbatimURITag, "verbatim URI tag", passed, total);
1079 RunParserTest(&Parser::DefaultPlainScalarTag, "default plain scalar tag", passed, total);
1080 RunParserTest(&Parser::DefaultSequenceTag, "default sequence tag", passed, total);
1081 RunParserTest(&Parser::ExplicitNonSpecificSequenceTag, "explicit, non-specific sequence tag", passed, total);
1083 RunEncodingTest(&EncodeToUtf8, false, "UTF-8, no BOM", passed, total);
1084 RunEncodingTest(&EncodeToUtf8, true, "UTF-8 with BOM", passed, total);
1085 RunEncodingTest(&EncodeToUtf16LE, false, "UTF-16LE, no BOM", passed, total);
1086 RunEncodingTest(&EncodeToUtf16LE, true, "UTF-16LE with BOM", passed, total);
1087 RunEncodingTest(&EncodeToUtf16BE, false, "UTF-16BE, no BOM", passed, total);
1088 RunEncodingTest(&EncodeToUtf16BE, true, "UTF-16BE with BOM", passed, total);
1089 RunEncodingTest(&EncodeToUtf32LE, false, "UTF-32LE, no BOM", passed, total);
1090 RunEncodingTest(&EncodeToUtf32LE, true, "UTF-32LE with BOM", passed, total);
1091 RunEncodingTest(&EncodeToUtf32BE, false, "UTF-32BE, no BOM", passed, total);
1092 RunEncodingTest(&EncodeToUtf32BE, true, "UTF-32BE with BOM", passed, total);
1094 std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
1095 return passed == total;