aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/Tests/LexerTest
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
commitfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (patch)
tree1e50f5f666f419143f510d5ded00fe2006b7bd85 /SQLiteStudio3/Tests/LexerTest
parentd9aa870e5d509cc7309ab82dd102a937ab58613a (diff)
New upstream version 3.2.1+dfsg1upstream/3.2.1+dfsg1
Diffstat (limited to 'SQLiteStudio3/Tests/LexerTest')
-rw-r--r--SQLiteStudio3/Tests/LexerTest/LexerTest.pro32
-rw-r--r--SQLiteStudio3/Tests/LexerTest/tst_lexertest.cpp66
2 files changed, 98 insertions, 0 deletions
diff --git a/SQLiteStudio3/Tests/LexerTest/LexerTest.pro b/SQLiteStudio3/Tests/LexerTest/LexerTest.pro
new file mode 100644
index 0000000..a4f2630
--- /dev/null
+++ b/SQLiteStudio3/Tests/LexerTest/LexerTest.pro
@@ -0,0 +1,32 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2018-07-15T23:45:16
+#
+#-------------------------------------------------
+
+include($$PWD/../TestUtils/test_common.pri)
+
+QT += testlib
+
+QT -= gui
+
+TARGET = tst_lexertest
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += \
+ tst_lexertest.cpp
diff --git a/SQLiteStudio3/Tests/LexerTest/tst_lexertest.cpp b/SQLiteStudio3/Tests/LexerTest/tst_lexertest.cpp
new file mode 100644
index 0000000..deac898
--- /dev/null
+++ b/SQLiteStudio3/Tests/LexerTest/tst_lexertest.cpp
@@ -0,0 +1,66 @@
+#include "parser/lexer.h"
+#include <QString>
+#include <QtTest>
+
+class LexerTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+ LexerTest();
+
+ private Q_SLOTS:
+ void testStringCase1();
+ void testFloat();
+ void testHex1();
+ void testHex2();
+};
+
+LexerTest::LexerTest()
+{
+}
+
+void LexerTest::testStringCase1()
+{
+ QString sql = "INSERT INTO tab VALUES (1, 2, :val); /* test";
+
+ Lexer lex(Dialect::Sqlite3);
+ TokenList tokens = lex.tokenize(sql);
+ QVERIFY(tokens.size() == 20);
+}
+
+void LexerTest::testFloat()
+{
+ QString sql = "SELECT .2";
+
+ Lexer lex(Dialect::Sqlite3);
+ TokenList tokens = lex.tokenize(sql);
+ QVERIFY(tokens.size() == 3);
+ QVERIFY(tokens[2]->type == Token::FLOAT);
+}
+
+void LexerTest::testHex1()
+{
+ QString sql = "SELECT 0x";
+
+ Lexer lex(Dialect::Sqlite3);
+ TokenList tokens = lex.tokenize(sql);
+ QVERIFY(tokens.size() == 3);
+ QVERIFY(tokens[2]->type == Token::INVALID);
+}
+
+void LexerTest::testHex2()
+{
+ QString sql = "SELECT 0x5zzz";
+
+ Lexer lex(Dialect::Sqlite3);
+ TokenList tokens = lex.tokenize(sql);
+ QVERIFY(tokens.size() == 4);
+ QVERIFY(tokens[2]->type == Token::INTEGER);
+ QVERIFY(tokens[3]->type == Token::OTHER);
+ QVERIFY(tokens[3]->value == "zzz");
+}
+
+QTEST_APPLESS_MAIN(LexerTest)
+
+#include "tst_lexertest.moc"