summaryrefslogtreecommitdiff
path: root/test/core/common
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-23 15:47:59 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-23 15:47:59 +0100
commit18d3637ca02ab69f1ee744fa94c43c243de0f571 (patch)
tree42c859f014ab7dbb7d31a747e0ef3839c77c60fa /test/core/common
parent85d72823ef18711fe7a29f5b23cc37b318766332 (diff)
parentaa817d3bfd90aa39b6fd8a915bc78a8bb210cd3d (diff)
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'test/core/common')
-rw-r--r--test/core/common/CharReaderTest.cpp109
-rw-r--r--test/core/common/LoggerTest.cpp52
-rw-r--r--test/core/common/UtilsTest.cpp19
3 files changed, 49 insertions, 131 deletions
diff --git a/test/core/common/CharReaderTest.cpp b/test/core/common/CharReaderTest.cpp
index 702d958..fba60f9 100644
--- a/test/core/common/CharReaderTest.cpp
+++ b/test/core/common/CharReaderTest.cpp
@@ -453,9 +453,8 @@ TEST(CharReader, simpleRead)
// The two strings must equal
ASSERT_EQ(testStr, res);
- // We must now be at line 1, column 15
- ASSERT_EQ(1, reader.getLine());
- ASSERT_EQ((int)(testStr.size() + 1), reader.getColumn());
+ // Check the char reader offset
+ ASSERT_EQ(testStr.size(), reader.getOffset());
// If we call either read or peek, false is returned
ASSERT_FALSE(reader.read(c));
@@ -483,15 +482,11 @@ TEST(CharReader, simplePeek)
ASSERT_EQ(testStr, res);
// 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_EQ(0, reader.getOffset());
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((int)(testStr.size() + 1), reader.getColumn());
+ ASSERT_EQ(testStr.size(), reader.getOffset());
ASSERT_TRUE(reader.atEnd());
// If we call either read or peek, false is returned
@@ -499,64 +494,6 @@ TEST(CharReader, simplePeek)
ASSERT_FALSE(reader.peek(c));
}
-TEST(CharReader, rowColumnCounter)
-{
- // Feed a test string into the reader
- CharReader reader{"1\n\r2\n3\r\n\n4"};
-
- // We should currently be in line 1, column 1
- ASSERT_EQ(1, reader.getLine());
- ASSERT_EQ(1, reader.getColumn());
-
- // Read two characters
- char c;
- 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(CharReader, rowColumnCounterTest)
-{
- // Feed a test string into the reader
- CharReader reader{"1\n\r2\n3\r\n\n4", 4, 10};
-
- // We should currently be in line 1, column 1
- ASSERT_EQ(4, reader.getLine());
- ASSERT_EQ(10, reader.getColumn());
-
- // Read two characters
- char c;
- for (int i = 0; i < 2; i++)
- reader.read(c);
- ASSERT_EQ(5, reader.getLine());
- ASSERT_EQ(1, reader.getColumn());
-
- // Read two characters
- for (int i = 0; i < 2; i++)
- reader.read(c);
- ASSERT_EQ(6, reader.getLine());
- ASSERT_EQ(1, reader.getColumn());
-
- // Read three characters
- for (int i = 0; i < 3; i++)
- reader.read(c);
- ASSERT_EQ(8, reader.getLine());
- ASSERT_EQ(1, reader.getColumn());
-}
-
TEST(CharReader, linebreakSubstitution)
{
// Feed a test string into the reader and read all characters back
@@ -571,23 +508,6 @@ TEST(CharReader, linebreakSubstitution)
ASSERT_EQ("this\nis\njust\na test\n\ntest\n", res);
}
-TEST(CharReader, rowColumnCounterUTF8)
-{
- // Feed a test string with some umlauts into the reader
- CharReader reader{"\x61\xc3\x96\xc3\x84\xc3\x9c\xc3\x9f"};
-
- // Read all bytes
- char c;
- while (reader.read(c)) {
- // Do nothing
- }
-
- // 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());
-}
-
TEST(CharReader, stream)
{
// Copy the test data to a string stream
@@ -608,8 +528,8 @@ TEST(CharReader, stream)
TEST(CharReader, fork)
{
std::string testStr{"first line\n\n\rsecond line\n\rlast line"};
- // 0123456789 0 123456789012 3456789012
- // 0 1 2 3
+ // 0123456789 0 1 234567890123 4 5678901234
+ // 0 1 2 3
char c;
CharReader reader{testStr};
@@ -626,8 +546,7 @@ TEST(CharReader, fork)
{
CharReaderFork fork = reader.fork();
- ASSERT_EQ(1, fork.getLine());
- ASSERT_EQ(5, fork.getColumn());
+ ASSERT_EQ(4, fork.getOffset());
fork.peek(c);
ASSERT_EQ('i', c);
@@ -635,11 +554,7 @@ TEST(CharReader, fork)
fork.read(c);
ASSERT_EQ('t', c);
- ASSERT_EQ(1, fork.getLine());
- ASSERT_EQ(6, fork.getColumn());
-
- ASSERT_EQ(1, reader.getLine());
- ASSERT_EQ(5, reader.getColumn());
+ ASSERT_EQ(5, fork.getOffset());
reader.read(c);
reader.read(c);
@@ -647,11 +562,10 @@ TEST(CharReader, fork)
fork.commit();
}
- ASSERT_EQ(1, reader.getLine());
- ASSERT_EQ(6, reader.getColumn());
+ ASSERT_EQ(5, reader.getOffset());
}
-TEST(CharReaderTest, context)
+/*TEST(CharReader, context)
{
std::string testStr{"first line\n\n\rsecond line\n\rlast line"};
// 0123456789 0 123456789012 3456789012
@@ -816,6 +730,7 @@ TEST(CharReaderTest, context)
ASSERT_TRUE(ctx.truncatedStart);
ASSERT_FALSE(ctx.truncatedEnd);
}
-}
+}*/
+
}
diff --git a/test/core/common/LoggerTest.cpp b/test/core/common/LoggerTest.cpp
index 66e49cd..9b20cc6 100644
--- a/test/core/common/LoggerTest.cpp
+++ b/test/core/common/LoggerTest.cpp
@@ -33,32 +33,30 @@ struct Pos {
SourceLocation getLocation() { return pos; }
};
-static SourceContext contextCallback(const SourceLocation &location,
- void *)
+static SourceContext contextCallback(const SourceLocation &location)
{
- return SourceContext{"int bla = blub;", 10, true, false};
+ SourceContext ctx;
+ ctx.filename = "testfile.test";
+ ctx.startLine = 10;
+ ctx.endLine = 10;
+ ctx.startColumn = 20;
+ ctx.endColumn = 20;
+ return ctx;
}
TEST(TerminalLogger, log)
{
// Test for manual visual expection only -- no assertions
TerminalLogger logger{std::cerr, true};
- logger.pushFile("test.odp");
+ logger.setSourceContextCallback(contextCallback);
- logger.debug("This is a test debug message", SourceLocation{10, 20});
- logger.debug("This is a test debug message with no column",
- SourceLocation{10});
- logger.debug("This is a test debug message with no line");
- logger.note("This is a test note", SourceLocation{10, 20});
- logger.warning("This is a test warning", SourceLocation{10, 20});
- logger.error("This is a test error", SourceLocation{10, 20});
- logger.fatalError("This is a test fatal error!", SourceLocation{10, 20});
+ logger.debug("This is a test debug message");
+ logger.note("This is a test note");
+ logger.warning("This is a test warning");
+ logger.error("This is a test error");
+ logger.fatalError("This is a test fatal error!");
- logger.pushFile("test2.odp", SourceLocation{}, contextCallback);
- logger.error("This is a test error with context", SourceLocation{10, 20});
- logger.popFile();
-
- Pos pos(SourceLocation{10, 20});
+ logger.error("This is a test error with context");
try {
throw LoggableException{"An exception"};
@@ -66,15 +64,6 @@ TEST(TerminalLogger, log)
catch (const LoggableException &ex) {
logger.log(ex);
}
-
- try {
- throw LoggableException{"An exception at position", pos};
- }
- catch (const LoggableException &ex) {
- logger.log(ex);
- }
-
- logger.log(Severity::ERROR, "This is a positioned log message", pos);
}
TEST(TerminalLogger, fork)
@@ -82,16 +71,11 @@ TEST(TerminalLogger, fork)
// Test for manual visual expection only -- no assertions
TerminalLogger logger{std::cerr, true};
+ logger.setSourceContextCallback(contextCallback);
+
LoggerFork fork = logger.fork();
- fork.pushFile("test.odp", SourceLocation{}, contextCallback);
- fork.error("This is a test error with context", SourceLocation{10, 20});
- fork.pushFile("test2.odp");
- fork.error("This is a test error without context");
- fork.popFile();
- fork.error("Another error");
- fork.popFile();
- fork.error("Another error");
+ fork.error("This is a test error with context");
// Print all error messages
fork.commit();
diff --git a/test/core/common/UtilsTest.cpp b/test/core/common/UtilsTest.cpp
index 53beb79..c8f6922 100644
--- a/test/core/common/UtilsTest.cpp
+++ b/test/core/common/UtilsTest.cpp
@@ -54,5 +54,24 @@ TEST(Utils, split)
ASSERT_EQ(std::vector<std::string>({"", "a", "be", "c", ""}),
Utils::split(".a.be.c.", '.'));
}
+
+TEST(Utils, toLower)
+{
+ ASSERT_EQ("", Utils::toLower(""));
+ ASSERT_EQ("foo00", Utils::toLower("foo00"));
+ ASSERT_EQ("foo00", Utils::toLower("fOO00"));
+}
+
+TEST(Utils, extractFileExtension)
+{
+ ASSERT_EQ("", Utils::extractFileExtension(""));
+ ASSERT_EQ("", Utils::extractFileExtension("test"));
+ ASSERT_EQ("ext", Utils::extractFileExtension("test.ext"));
+ ASSERT_EQ("", Utils::extractFileExtension("foo.bar/test"));
+ ASSERT_EQ("", Utils::extractFileExtension("foo.bar\\test"));
+ ASSERT_EQ("ext", Utils::extractFileExtension("foo.bar/test.ext"));
+ ASSERT_EQ("ext", Utils::extractFileExtension("foo.bar/test.EXT"));
+}
+
}