diff --git a/main.cpp b/main.cpp index ef99a1d..6588557 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include "parser.h" +#include "tests.h" #include #include @@ -64,21 +65,23 @@ void operator >> (const YAML::Node& node, Level& level) int main() { - std::ifstream fin("test.yaml"); + YAML::Test::RunAll(); - try { - YAML::Parser parser(fin); - if(!parser) - return 0; + //std::ifstream fin("test.yaml"); - YAML::Node doc; - parser.GetNextDocument(doc); - std::cout << doc; - } catch(YAML::Exception&) { - std::cout << "Error parsing the yaml!\n"; - } + //try { + // YAML::Parser parser(fin); + // if(!parser) + // return 0; + + // YAML::Node doc; + // parser.GetNextDocument(doc); + // std::cout << doc; + //} catch(YAML::Exception&) { + // std::cout << "Error parsing the yaml!\n"; + //} getchar(); return 0; -} \ No newline at end of file +} diff --git a/parser.cpp b/parser.cpp index decb663..46c92b8 100644 --- a/parser.cpp +++ b/parser.cpp @@ -8,8 +8,7 @@ namespace YAML { Parser::Parser(std::istream& in): m_pScanner(0) { - m_pScanner = new Scanner(in); - m_state.Reset(); + Load(in); } Parser::~Parser() @@ -22,6 +21,13 @@ namespace YAML return m_pScanner->PeekNextToken() != 0; } + void Parser::Load(std::istream& in) + { + delete m_pScanner; + m_pScanner = new Scanner(in); + m_state.Reset(); + } + // GetNextDocument // . Reads the next document in the queue (of tokens). // . Throws (ScannerException|ParserException)s on errors. diff --git a/parser.h b/parser.h index a26446f..33c24c1 100644 --- a/parser.h +++ b/parser.h @@ -20,6 +20,7 @@ namespace YAML operator bool() const; + void Load(std::istream& in); void GetNextDocument(Node& document); void PrintTokens(std::ostream& out); diff --git a/tests.cpp b/tests.cpp new file mode 100644 index 0000000..2d9b476 --- /dev/null +++ b/tests.cpp @@ -0,0 +1,80 @@ +#include "tests.h" +#include "parser.h" +#include +#include +#include +#include + +namespace YAML +{ + namespace Test + { + // runs all the tests on all data we have + void RunAll() + { + std::vector files; + files.push_back("tests/simple.yaml"); + files.push_back("tests/mixed.yaml"); + + bool passed = true; + for(unsigned i=0;i + +namespace YAML +{ + namespace Test { + void RunAll(); + + bool Inout(const std::string& file); + } +} \ No newline at end of file diff --git a/tests/mixed.yaml b/tests/mixed.yaml new file mode 100644 index 0000000..88da1e7 --- /dev/null +++ b/tests/mixed.yaml @@ -0,0 +1,32 @@ +- the main thing is a sequence +- here's a key: value + and another: value +- let's inline: [1, 2, 3] + and an inline map: {key: value, 243: 101} +- and multiple indents: + - here's + - a + - list + and another: + - list + - of + - things +- maybe now: + let's: get + pretty: + deep: here + in: + the: nesting + just: to + confuse: + the: heck + out: + - of + - the: parser + if: + - we + - can + - do: that + what: do + you: think? + \ No newline at end of file diff --git a/tests/simple.yaml b/tests/simple.yaml new file mode 100644 index 0000000..55b2d21 --- /dev/null +++ b/tests/simple.yaml @@ -0,0 +1,13 @@ +--- +just a scalar +--- +and another scalar +--- +now an end document +... +--- +and now two +... +... +--- +and that's it \ No newline at end of file diff --git a/yaml-reader.vcproj b/yaml-reader.vcproj index 455b71d..0d77cd1 100644 --- a/yaml-reader.vcproj +++ b/yaml-reader.vcproj @@ -165,6 +165,10 @@ RelativePath=".\main.cpp" > + + @@ -247,6 +251,10 @@ RelativePath=".\exceptions.h" > + +