From 1011655d2ef76a0c0aa29dbbff091dab139198e3 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 24 Oct 2020 16:32:18 +0200 Subject: Add FlowGraph --- tests/test-cpp.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/test-cpp.cpp (limited to 'tests/test-cpp.cpp') diff --git a/tests/test-cpp.cpp b/tests/test-cpp.cpp new file mode 100644 index 0000000..513a3a5 --- /dev/null +++ b/tests/test-cpp.cpp @@ -0,0 +1,78 @@ +#include "bnf.h" +#include "cpp.h" +#include "cppbnf.h" +#include "lexer.h" +#include "grammer.h" +#include "minicc.h" +#include "debug.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +class CppTest: public ::testing::Test +{ +protected: + CppTest() { + debug = true; + } + ~CppTest() { + } +}; + +TEST_F(CppTest, preprocessing_tokenize) { + CPP cpp; + auto pp_tokens = cpp.preprocessing_tokenize("int main() { return 1; }"); + + ASSERT_EQ(pp_tokens.size(), 9); + + auto tokens = cpp.tokens_from_pptokens(pp_tokens); + + ASSERT_EQ(tokens.size(), 9); + + auto nodes = cpp.analysis(tokens); + + ASSERT_EQ(nodes.size(), 60/*44*/); +} + +TEST_F(CppTest, preprocessing_tokenize_compile_error) { + CPP cpp; + auto ppTree = cpp.preprocessing_tokenize("in ma"); + + auto tokens = cpp.tokens_from_pptokens(ppTree); + + ASSERT_EQ(tokens.size(), 2); + + try { + auto nodes = cpp.analysis(tokens); + } catch (const std::exception& ex) { + EXPECT_EQ(ex.what(), "Compile error"s); + return; + } + + FAIL() << "Exception expected"; +} + +TEST(Cpp, compile) { + CPP cpp; + + cpp.compile("int main() { return 1 + 1; }"); +} + +TEST(Cpp, compile_2_times) { + CPP cpp; + + cpp.compile("int main() { return (1 + 2) * 2; }"); + cpp.compile("int main() { return 1 + 2 * 2; }"); +} + -- cgit v1.2.3