main.cpp 1023 Bytes
Newer Older
1
2
3
4
#include "yaml.h"
#include "tests.h"
#include <fstream>
#include <iostream>
Jesse Beder's avatar
Jesse Beder committed
5
#include <cstring>
6
7
8
9
10
11
12

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

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

		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";
22
23
	} catch(YAML::Exception& e) {
		std::cout << "Error at line " << e.line+1 << ", col " << e.column+1 << ": " << e.msg << "\n";
24
25
26
27
28
29
30
	}
}

int main(int argc, char **argv)
{
	bool verbose = false;
	for(int i=1;i<argc;i++) {
Jesse Beder's avatar
Jesse Beder committed
31
		if(std::strcmp(argv[i], "-v") == 0)
32
33
34
35
36
37
38
39
40
41
42
			verbose = true;
	}

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

	return 0;
}