mirror of
https://gitlab.com/manzerbredes/chess-move-interface.git
synced 2025-05-01 09:27:44 +00:00
Improve tests
This commit is contained in:
parent
55b2c72108
commit
e6e2c5a8bf
3 changed files with 77 additions and 3 deletions
14
src/pgnp.cpp
14
src/pgnp.cpp
|
@ -239,7 +239,12 @@ int PGN::ParseNextTag(int start_loc) {
|
|||
tags[key] = value;
|
||||
tagkeys.push_back(key);
|
||||
|
||||
// TODO: Check that caracters if a ]
|
||||
EOF_CHECK(valueloc + 1);
|
||||
c = pgn_content[valueloc + 1];
|
||||
if (c != ']') {
|
||||
throw UnexpectedCharacter(c, ']', valueloc + 1);
|
||||
}
|
||||
|
||||
return (valueloc + 1); // +1 For the last char of the tag which is ']'
|
||||
}
|
||||
|
||||
|
@ -247,7 +252,12 @@ HalfMove *PGN::GetMoves() { return (moves); }
|
|||
|
||||
std::vector<std::string> PGN::GetTagList() { return tagkeys; }
|
||||
|
||||
std::string PGN::GetTagValue(std::string key) { return tags[key]; }
|
||||
std::string PGN::GetTagValue(std::string key) {
|
||||
if (tags.find(key) == tags.end()) {
|
||||
throw InvalidTagName();
|
||||
}
|
||||
return tags[key];
|
||||
}
|
||||
|
||||
void PGN::Dump() {
|
||||
std::cout << "---------- PGN DUMP ----------" << std::endl;
|
||||
|
|
17
src/pgnp.hpp
17
src/pgnp.hpp
|
@ -2,6 +2,7 @@
|
|||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
@ -24,6 +25,7 @@ public:
|
|||
|
||||
HalfMove();
|
||||
~HalfMove();
|
||||
/// @brief Get number of HalfMove in the MailLine
|
||||
int GetLength();
|
||||
/// @brief Dump move and all its variations
|
||||
void Dump();
|
||||
|
@ -66,6 +68,21 @@ struct UnexpectedEOF : public std::exception {
|
|||
const char *what() const throw() { return "Unexpected end of pgn file"; }
|
||||
};
|
||||
|
||||
struct InvalidTagName : public std::exception {
|
||||
const char *what() const throw() { return "Invalid tag name"; }
|
||||
};
|
||||
|
||||
struct UnexpectedCharacter : public std::exception {
|
||||
std::string msg;
|
||||
UnexpectedCharacter(char actual, char required, int loc) {
|
||||
std::stringstream ss;
|
||||
ss << "Expected \'" << required << "\' at location " << loc
|
||||
<< " but read \'" << actual << "\'";
|
||||
msg = ss.str();
|
||||
}
|
||||
const char *what() const throw() { return msg.c_str(); }
|
||||
};
|
||||
|
||||
struct STRCheckFailed : public std::exception {
|
||||
const char *what() const throw() {
|
||||
return "Seven Tag Roster compliance check failed";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue