main.cpp 999 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#include "yaml.h"
#include "tests.h"
#include <fstream>
#include <iostream>

void run()
{
	std::ifstream fin("tests/test.yaml");

	try {
		YAML::Parser parser(fin);
12
13
		YAML::Node doc;
		parser.GetNextDocument(doc);
14
15
16
17
18
19
20

		std::cout << "name: " << doc["name"] << "\n";
		std::cout << "age: " << doc["age"] << "\n";
	} catch(YAML::TypedKeyNotFound <std::string>& e) {
		std::cout << "Key '" << e.key << "' not found at line " << e.line+1 << ", col " << e.column+1 << "\n";
	} catch(YAML::KeyNotFound& e) {
		std::cout << "Key not found at line " << e.line+1 << ", col " << e.column+1 << "\n";
21
22
	} catch(YAML::Exception& e) {
		std::cout << "Error at line " << e.line+1 << ", col " << e.column+1 << ": " << e.msg << "\n";
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	}
}

int main(int argc, char **argv)
{
	bool verbose = false;
	for(int i=1;i<argc;i++) {
		if(strcmp(argv[i], "-v") == 0)
			verbose = true;
	}

#ifdef WINDOWS
	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
#endif // WINDOWS
	Test::RunAll(verbose);
	run();

	return 0;
}