From 08e654dcda7fa6d764558ea184fe1a47bc4001c8 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 21 Nov 2014 11:10:31 +0100 Subject: Finished last commits moving action by also moving the tests and correcting all references and namespaces in the code. --- test/core/utils/BufferedCharReaderTest.cpp | 203 -------------------------- test/core/utils/CSSParserTest.cpp | 116 --------------- test/core/utils/CodeTokenizerTest.cpp | 102 ------------- test/core/utils/RangeSetTest.cpp | 222 ----------------------------- test/core/utils/TokenizerTest.cpp | 125 ---------------- test/core/utils/UtilsTest.cpp | 35 ----- 6 files changed, 803 deletions(-) delete mode 100644 test/core/utils/BufferedCharReaderTest.cpp delete mode 100644 test/core/utils/CSSParserTest.cpp delete mode 100644 test/core/utils/CodeTokenizerTest.cpp delete mode 100644 test/core/utils/RangeSetTest.cpp delete mode 100644 test/core/utils/TokenizerTest.cpp delete mode 100644 test/core/utils/UtilsTest.cpp (limited to 'test/core/utils') diff --git a/test/core/utils/BufferedCharReaderTest.cpp b/test/core/utils/BufferedCharReaderTest.cpp deleted file mode 100644 index 69c0974..0000000 --- a/test/core/utils/BufferedCharReaderTest.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - SCAENEA IDL Compiler (scidlc) - Copyright (C) 2014 Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include - -#include "gtest/gtest.h" - -#include - -namespace ousia{ -namespace utils{ - -TEST(BufferedCharReaderTest, SimpleReadTest) -{ - const std::string testStr("this is a test"); - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - reader.feed(testStr); - reader.close(); - - // Try to read the test string - std::string res; - while (!reader.atEnd()) { - ASSERT_TRUE(reader.read(&c)); - res.append(&c, 1); - } - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()) ; - - // We must now be at line 1, column 15 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, SimplePeekTest) -{ - const std::string testStr("this is a test"); - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - reader.feed(testStr); - reader.close(); - - // Try to read the test string - std::string res; - while (reader.peek(&c)) { - res.append(&c, 1); - } - - // Peeking does not trigger the "atEnd" flag - ASSERT_FALSE(reader.atEnd()); - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()); - - // We must now be at line 1, column 1 and NOT at the end of the stream - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - ASSERT_FALSE(reader.atEnd()); - - // If we consume the peek, we must be at line 1, column 15 and we should be - // at the end of the stream - reader.consumePeek(); - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - ASSERT_TRUE(reader.atEnd()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, SplittedPeakTest) -{ - const std::string testStr("this is a test"); - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - - // Try to peek the test string, feed char after char into the reader - std::string res; - for (unsigned int i = 0; i < testStr.length(); i++) { - reader.feed(std::string(&testStr[i], 1)); - while (reader.peek(&c)) { - res.append(&c, 1); - } - } - reader.close(); - - // Consume the peeked data - ASSERT_FALSE(reader.atEnd()); - reader.consumePeek(); - ASSERT_TRUE(reader.atEnd()); - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()) ; - - // We must now be at line 1, column 15 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, RowColumnCounterTest) -{ - const std::string testStr("1\n\r2\n3\r\n\n4"); - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - reader.feed(testStr); - reader.close(); - - // We should currently be in line 1, column 1 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read two characters - for (int i = 0; i < 2; i++) reader.read(&c); - ASSERT_EQ(2, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read two characters - for (int i = 0; i < 2; i++) reader.read(&c); - ASSERT_EQ(3, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read three characters - for (int i = 0; i < 3; i++) reader.read(&c); - ASSERT_EQ(5, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); -} - -TEST(BufferedCharReaderTest, LinebreakSubstitutionTest) -{ - const std::string testStr("this\n\ris\n\rjust\na test\r\n\rtest\n\r"); - const std::string expStr("this\nis\njust\na test\n\ntest\n"); - - // Feed a test string into the reader - BufferedCharReader reader; - reader.feed(testStr); - - // Read all characters from the test string - std::string res; - char c; - while (reader.read(&c)) { - res.append(&c, 1); - } - - // Test for equality - ASSERT_STREQ(expStr.c_str(), res.c_str()); -} - -TEST(BufferedCharReaderTest, RowColumnCounterUTF8Test) -{ - // Create a test string with some umlauts - const std::string testStr("\x61\xc3\x96\xc3\x84\xc3\x9c\xc3\x9f"); - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - reader.feed(testStr); - reader.close(); - - // Read all bytes - while (reader.read(&c)); - - // The sequence above equals 5 UTF-8 characters (so after reading all the - // cursor is at position 6) - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(6, reader.getColumn()); -} - -} -} diff --git a/test/core/utils/CSSParserTest.cpp b/test/core/utils/CSSParserTest.cpp deleted file mode 100644 index 920752b..0000000 --- a/test/core/utils/CSSParserTest.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { -namespace utils { -TEST(Specificity, testOperators) -{ - Specificity s1{0,0,1}; - Specificity s2{0,1,1}; - Specificity s3{1,1,1}; - Specificity s4{0,0,2}; - Specificity s5{1,0,2}; - - //This should be s1 < s4 < s2 < s5 < s3 - - ASSERT_TRUE(s1 == s1); - ASSERT_FALSE(s1 < s1); - ASSERT_FALSE(s1 > s1); - ASSERT_FALSE(s1 == s2); - ASSERT_TRUE(s1 < s2); - ASSERT_FALSE(s1 > s2); - ASSERT_FALSE(s1 == s3); - ASSERT_TRUE(s1 < s3); - ASSERT_FALSE(s1 > s3); - ASSERT_FALSE(s1 == s4); - ASSERT_TRUE(s1 < s4); - ASSERT_FALSE(s1 > s4); - ASSERT_FALSE(s1 == s5); - ASSERT_TRUE(s1 < s5); - ASSERT_FALSE(s1 > s5); - - ASSERT_FALSE(s2 == s1); - ASSERT_FALSE(s2 < s1); - ASSERT_TRUE(s2 > s1); - ASSERT_TRUE(s2 == s2); - ASSERT_FALSE(s2 < s2); - ASSERT_FALSE(s2 > s2); - ASSERT_FALSE(s2 == s3); - ASSERT_TRUE(s2 < s3); - ASSERT_FALSE(s2 > s3); - ASSERT_FALSE(s2 == s4); - ASSERT_FALSE(s2 < s4); - ASSERT_TRUE(s2 > s4); - ASSERT_FALSE(s2 == s5); - ASSERT_TRUE(s2 < s5); - ASSERT_FALSE(s2 > s5); - - ASSERT_FALSE(s3 == s1); - ASSERT_FALSE(s3 < s1); - ASSERT_TRUE(s3 > s1); - ASSERT_FALSE(s3 == s2); - ASSERT_FALSE(s3 < s2); - ASSERT_TRUE(s3 > s2); - ASSERT_TRUE(s3 == s3); - ASSERT_FALSE(s3 < s3); - ASSERT_FALSE(s3 > s3); - ASSERT_FALSE(s3 == s4); - ASSERT_FALSE(s3 < s4); - ASSERT_TRUE(s3 > s4); - ASSERT_FALSE(s3 == s5); - ASSERT_FALSE(s3 < s5); - ASSERT_TRUE(s3 > s5); - - ASSERT_FALSE(s4 == s1); - ASSERT_FALSE(s4 < s1); - ASSERT_TRUE(s4 > s1); - ASSERT_FALSE(s4 == s2); - ASSERT_TRUE(s4 < s2); - ASSERT_FALSE(s4 > s2); - ASSERT_FALSE(s4 == s3); - ASSERT_TRUE(s4 < s3); - ASSERT_FALSE(s4 > s3); - ASSERT_TRUE(s4 == s4); - ASSERT_FALSE(s4 < s4); - ASSERT_FALSE(s4 > s4); - ASSERT_FALSE(s4 == s5); - ASSERT_TRUE(s4 < s5); - ASSERT_FALSE(s4 > s5); - - ASSERT_FALSE(s5 == s1); - ASSERT_FALSE(s5 < s1); - ASSERT_TRUE(s5 > s1); - ASSERT_FALSE(s5 == s2); - ASSERT_FALSE(s5 < s2); - ASSERT_TRUE(s5 > s2); - ASSERT_FALSE(s5 == s3); - ASSERT_TRUE(s5 < s3); - ASSERT_FALSE(s5 > s3); - ASSERT_FALSE(s5 == s4); - ASSERT_FALSE(s5 < s4); - ASSERT_TRUE(s5 > s4); - ASSERT_TRUE(s5 == s5); - ASSERT_FALSE(s5 < s5); - ASSERT_FALSE(s5 > s5); -} -} -} diff --git a/test/core/utils/CodeTokenizerTest.cpp b/test/core/utils/CodeTokenizerTest.cpp deleted file mode 100644 index 0b9d7b3..0000000 --- a/test/core/utils/CodeTokenizerTest.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { -namespace utils { - -static const int BLOCK_COMMENT = 30; -static const int LINE_COMMENT = 31; -static const int STRING = 20; -static const int ESCAPE = 21; -static const int LINEBREAK = 21; -static const int CURLY_OPEN = 40; -static const int CURLY_CLOSE = 41; - -TEST(CodeTokenizer, testTokenizer) -{ - BufferedCharReader reader; - reader.feed("/**\n"); // 1 - reader.feed(" * Some Block Comment\n"); // 2 - reader.feed(" */\n"); // 3 - reader.feed("var my_string = 'My \\'String\\'';\n"); // 4 - reader.feed("// and a line comment\n"); // 5 - reader.feed("var my_obj = { a = 4;}"); // 6 - // 123456789012345678901234567890123456789012345678901234567890123456789 - // 0 1 2 3 4 5 6 - TokenTreeNode root{{{"/*", 1}, - {"*/", 2}, - {"//", 3}, - {"'", 4}, - {"\\", 5}, - {"{", CURLY_OPEN}, - {"}", CURLY_CLOSE}, - {"\n", 6}}}; - std::map descriptors{ - // the block comment start Token has the id 1 and if the Tokenizer - // returns a Block Comment Token that should have the id 10. - {1, {CodeTokenMode::BLOCK_COMMENT_START, BLOCK_COMMENT}}, - {2, {CodeTokenMode::BLOCK_COMMENT_END, BLOCK_COMMENT}}, - {3, {CodeTokenMode::LINE_COMMENT, LINE_COMMENT}}, - {4, {CodeTokenMode::STRING_START_END, STRING}}, - {5, {CodeTokenMode::ESCAPE, ESCAPE}}, - {6, {CodeTokenMode::LINEBREAK, LINEBREAK}}}; - - std::vector expected = { - {BLOCK_COMMENT, "*\n * Some Block Comment\n ", 1, 1, 4, 3}, - {LINEBREAK, "\n", 4, 3, 1, 4}, - {TOKEN_TEXT, "var", 1, 4, 4, 4}, - {TOKEN_TEXT, "my_string", 5, 4, 14, 4}, - {TOKEN_TEXT, "=", 15, 4, 16, 4}, - {STRING, "My 'String'", 17, 4, 32, 4}, - {TOKEN_TEXT, ";", 32, 4, 33, 4}, - {LINEBREAK, "\n", 33, 4, 1, 5}, - //this is slightly counter-intuitive but makes sense if you think about - //it: As a line comment is ended by a line break the line break is - //technically still a part of the line comment and thus the ending - //is in the next line. - {LINE_COMMENT, " and a line comment", 1, 5, 1, 6}, - {TOKEN_TEXT, "var", 1, 6, 4, 6}, - {TOKEN_TEXT, "my_obj", 5, 6, 11, 6}, - {TOKEN_TEXT, "=", 12, 6, 13, 6}, - {CURLY_OPEN, "{", 14, 6, 15, 6}, - {TOKEN_TEXT, "a", 16, 6, 17, 6}, - {TOKEN_TEXT, "=", 18, 6, 19, 6}, - {TOKEN_TEXT, "4;", 20, 6, 22, 6}, - {CURLY_CLOSE, "}", 22, 6, 23, 6}, - }; - - CodeTokenizer tokenizer{reader, root, descriptors}; - - Token t; - for (auto &te : expected) { - ASSERT_TRUE(tokenizer.next(t)); - ASSERT_EQ(te.tokenId, t.tokenId); - ASSERT_EQ(te.content, t.content); - ASSERT_EQ(te.startColumn, t.startColumn); - ASSERT_EQ(te.startLine, t.startLine); - ASSERT_EQ(te.endColumn, t.endColumn); - ASSERT_EQ(te.endLine, t.endLine); - } - ASSERT_FALSE(tokenizer.next(t)); -} -} -} diff --git a/test/core/utils/RangeSetTest.cpp b/test/core/utils/RangeSetTest.cpp deleted file mode 100644 index 9be4c17..0000000 --- a/test/core/utils/RangeSetTest.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - Ousía - Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { -namespace model { - -TEST(Range, IsValid) -{ - ASSERT_FALSE(Range().isValid()); - ASSERT_TRUE(Range(10).isValid()); - ASSERT_TRUE(Range(10, 20).isValid()); - ASSERT_FALSE(Range(20, 10).isValid()); -} - -TEST(Range, InRange) -{ - Range r(10, 20); - ASSERT_FALSE(r.inRange(0)); - ASSERT_FALSE(r.inRange(21)); - ASSERT_TRUE(r.inRange(10)); - ASSERT_TRUE(r.inRange(20)); - ASSERT_TRUE(r.inRange(15)); -} - -TEST(Range, overlaps) -{ - ASSERT_FALSE(Range(10, 20).overlaps(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).overlaps(Range(21, 30))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(0, 10))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(20, 30))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(5, 15))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 25))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 19))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(10, 20))); - ASSERT_TRUE(Range(10, 20).overlaps(Range(0, 30))); -} - -TEST(Range, CoveredBy) -{ - ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(21, 30))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 10))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(20, 30))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(5, 15))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 25))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 19))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).coveredBy(Range(10, 20))); - ASSERT_TRUE(Range(10, 20).coveredBy(Range(0, 30))); -} - -TEST(Range, Covers) -{ - ASSERT_FALSE(Range(10, 20).covers(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).covers(Range(21, 30))); - ASSERT_FALSE(Range(10, 20).covers(Range(0, 10))); - ASSERT_FALSE(Range(10, 20).covers(Range(20, 30))); - ASSERT_FALSE(Range(10, 20).covers(Range(5, 15))); - ASSERT_FALSE(Range(10, 20).covers(Range(15, 25))); - ASSERT_TRUE(Range(10, 20).covers(Range(15, 19))); - ASSERT_TRUE(Range(10, 20).covers(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).covers(Range(10, 20))); - ASSERT_FALSE(Range(10, 20).covers(Range(0, 30))); -} - -TEST(RangeSet, Neighbours) -{ - ASSERT_TRUE(Range(10, 19).neighbours(Range(20, 30))); - ASSERT_TRUE(Range(20, 29).neighbours(Range(10, 19))); -} - -TEST(Range, Merge) -{ - Range r1(10, 20); - Range r2(15, 25); - Range r3(5, 15); - Range rM = r1.merge(r2).merge(r3); - ASSERT_EQ(rM.start, 5); - ASSERT_EQ(rM.end, 25); -} - -TEST(RangeSet, Merge) -{ - RangeSet s; - auto &ranges = s.getRanges(); - - // Insert some non-overlapping elements into the range. We expect these to - // be just inserted into the ranges. - s.merge(Range( 0, 10)); - s.merge(Range(20, 30)); - s.merge(Range(40, 50)); - s.merge(Range(60, 70)); - { - ASSERT_EQ(ranges.size(), 4); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, 0); - ASSERT_EQ((*it).end, 10); - - it++; - ASSERT_EQ((*it).start, 20); - ASSERT_EQ((*it).end, 30); - - it++; - ASSERT_EQ((*it).start, 40); - ASSERT_EQ((*it).end, 50); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which spans the second and third element - s.merge(Range(15, 55)); - { - ASSERT_EQ(ranges.size(), 3); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, 0); - ASSERT_EQ((*it).end, 10); - - it++; - ASSERT_EQ((*it).start, 15); - ASSERT_EQ((*it).end, 55); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which expands the first element - s.merge(Range(-10, 11)); - { - ASSERT_EQ(ranges.size(), 3); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 11); - - it++; - ASSERT_EQ((*it).start, 15); - ASSERT_EQ((*it).end, 55); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which merges the last two elements - s.merge(Range(13, 70)); - { - ASSERT_EQ(ranges.size(), 2); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 11); - - it++; - ASSERT_EQ((*it).start, 13); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which merges the remaining elements - s.merge(Range(-9, 12)); - { - ASSERT_EQ(ranges.size(), 1); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 70); - } - -} - -TEST(RangeSet, Contains) -{ - RangeSet s; - - // Insert some non-overlapping elements into the range. We expect these to - // be just inserted into the ranges. - s.merge(Range( 0, 10)); - s.merge(Range(20, 30)); - s.merge(Range(40, 50)); - s.merge(Range(60, 70)); - s.merge(Range(71)); - s.merge(Range(72)); - s.merge(Range(73)); - s.merge(Range(74)); - - ASSERT_TRUE(s.contains(60)); - ASSERT_TRUE(s.contains(0)); - ASSERT_TRUE(s.contains(25)); - ASSERT_TRUE(s.contains(73)); - ASSERT_TRUE(s.contains(Range(25, 30))); - ASSERT_FALSE(s.contains(Range(25, 35))); - ASSERT_TRUE(s.contains(Range(0, 10))); - ASSERT_TRUE(s.contains(Range(70, 74))); -} - -} -} - diff --git a/test/core/utils/TokenizerTest.cpp b/test/core/utils/TokenizerTest.cpp deleted file mode 100644 index 79cc01d..0000000 --- a/test/core/utils/TokenizerTest.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -#include - -namespace ousia { -namespace utils { -TEST(TokenTreeNode, testConstructor) -{ - TokenTreeNode root{{{"a", 1}, {"aab", 2}, {"aac", 3}, {"abd", 4}}}; - - ASSERT_EQ(-1, root.tokenId); - ASSERT_EQ(1, root.children.size()); - ASSERT_TRUE(root.children.find('a') != root.children.end()); - - const TokenTreeNode &a = root.children.at('a'); - ASSERT_EQ(1, a.tokenId); - ASSERT_EQ(2, a.children.size()); - ASSERT_TRUE(a.children.find('a') != a.children.end()); - ASSERT_TRUE(a.children.find('b') != a.children.end()); - - const TokenTreeNode &aa = a.children.at('a'); - ASSERT_EQ(-1, aa.tokenId); - ASSERT_EQ(2, aa.children.size()); - ASSERT_TRUE(aa.children.find('b') != aa.children.end()); - ASSERT_TRUE(aa.children.find('c') != aa.children.end()); - - const TokenTreeNode &aab = aa.children.at('b'); - ASSERT_EQ(2, aab.tokenId); - ASSERT_EQ(0, aab.children.size()); - - const TokenTreeNode &aac = aa.children.at('c'); - ASSERT_EQ(3, aac.tokenId); - ASSERT_EQ(0, aac.children.size()); - - const TokenTreeNode &ab = a.children.at('b'); - ASSERT_EQ(-1, ab.tokenId); - ASSERT_EQ(1, ab.children.size()); - ASSERT_TRUE(ab.children.find('d') != ab.children.end()); - - const TokenTreeNode &abd = ab.children.at('d'); - ASSERT_EQ(4, abd.tokenId); - ASSERT_EQ(0, abd.children.size()); -} - -TEST(Tokenizer, testTokenization) -{ - TokenTreeNode root{{{"/", 1}, {"/*", 2}, {"*/", 3}}}; - - BufferedCharReader reader; - reader.feed("Test/Test /* Block Comment */"); - // 12345678901234567890123456789 - // 0 1 2 - - std::vector expected = { - {TOKEN_TEXT, "Test", 1, 1, 5, 1}, - {1, "/", 5, 1, 6, 1}, - {TOKEN_TEXT, "Test ", 6, 1, 11, 1}, - {2, "/*", 11, 1, 13, 1}, - {TOKEN_TEXT, " Block Comment ", 13, 1, 28, 1}, - {3, "*/", 28, 1, 30, 1}}; - - Tokenizer tokenizer{reader, root}; - - Token t; - for (auto &te : expected) { - ASSERT_TRUE(tokenizer.next(t)); - ASSERT_EQ(te.tokenId, t.tokenId); - ASSERT_EQ(te.content, t.content); - ASSERT_EQ(te.startColumn, t.startColumn); - ASSERT_EQ(te.startLine, t.startLine); - ASSERT_EQ(te.endColumn, t.endColumn); - ASSERT_EQ(te.endLine, t.endLine); - } - ASSERT_FALSE(tokenizer.next(t)); -} - -TEST(Tokenizer, testIncompleteTokens) -{ - TokenTreeNode root{{{"ab", 1}, {"c", 2}}}; - - BufferedCharReader reader; - reader.feed("ac"); - // 1234567890 - // 0 1 - - std::vector expected = { - {TOKEN_TEXT, "a", 1, 1, 2, 1}, - {2, "c", 2, 1, 3, 1}}; - - Tokenizer tokenizer{reader, root}; - - Token t; - for (auto &te : expected) { - ASSERT_TRUE(tokenizer.next(t)); - ASSERT_EQ(te.tokenId, t.tokenId); - ASSERT_EQ(te.content, t.content); - ASSERT_EQ(te.startColumn, t.startColumn); - ASSERT_EQ(te.startLine, t.startLine); - ASSERT_EQ(te.endColumn, t.endColumn); - ASSERT_EQ(te.endLine, t.endLine); - } - ASSERT_FALSE(tokenizer.next(t)); -} -} -} diff --git a/test/core/utils/UtilsTest.cpp b/test/core/utils/UtilsTest.cpp deleted file mode 100644 index d349c6f..0000000 --- a/test/core/utils/UtilsTest.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - Ousía - Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { - -TEST(Utils, isIdentifier) -{ - ASSERT_TRUE(Utils::isIdentifier("test")); - ASSERT_TRUE(Utils::isIdentifier("t0-_est")); - ASSERT_TRUE(Utils::isIdentifier("_t0-_EST")); - ASSERT_FALSE(Utils::isIdentifier("-t0-_EST")); - ASSERT_FALSE(Utils::isIdentifier("0t-_EST")); -} - -} - -- cgit v1.2.3