Add C++ implementation

This commit is contained in:
Clare Macrae
2019-08-13 09:44:16 +01:00
parent 4b9521d849
commit 7c3a7d4220
10 changed files with 31411 additions and 0 deletions

15
cpp/tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,15 @@
project(tests)
add_executable(${PROJECT_NAME}
../statement.cpp
../statement.h
test_statement.cpp
main.cpp)
target_include_directories(
${PROJECT_NAME}
PUBLIC
../third_party ..)
enable_testing()
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME})

2
cpp/tests/main.cpp Normal file
View File

@@ -0,0 +1,2 @@
#define APPROVALS_DOCTEST
#include "ApprovalTests.hpp"

View File

@@ -0,0 +1,43 @@
#include "statement.h"
#include "json.hpp"
#include "doctest.h"
#include "ApprovalTests.hpp"
#include <iostream>
namespace
{
std::string get_adjacent_file(const std::string& filename)
{
return ApprovalTestNamer().getDirectory() + filename;
}
nlohmann::json read_json_file(const std::string& filename)
{
std::ifstream invoice_stream(filename);
if ( ! invoice_stream.is_open())
{
std::cout << "Error opening file:" << filename << '\n';
std::cout << "Error: " << strerror(errno) << '\n';
}
nlohmann::json result;
invoice_stream >> result;
return result;
}
}
TEST_CASE("test_example_statement")
{
auto invoice = read_json_file(get_adjacent_file("invoice.json"));
auto plays = read_json_file(get_adjacent_file("plays.json"));
Approvals::verify(statement(invoice, plays));
}
TEST_CASE("test_statement_with_new_play_types")
{
auto invoice = read_json_file(get_adjacent_file("invoice_new_plays.json"));
auto plays = read_json_file(get_adjacent_file("new_plays.json"));
CHECK_THROWS_AS(statement(invoice, plays), std::domain_error);
}