|
@@ -1,6 +1,7 @@
|
|
|
#include <iostream>
|
|
|
#include "data/UnsortedArrayList.h"
|
|
|
#include "data/HashMap.h"
|
|
|
+#include "server/CommandUtils.h"
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
@@ -46,7 +47,19 @@ void checkEqual(int a, int b, string text)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- notifyFail(text + " - expected " + std::to_string(a) + " got " + std::to_string(b));
|
|
|
+ notifyFail(text + " - expected '" + std::to_string(a) + "' got '" + std::to_string(b) + "'");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void checkEqual(string a, string b, string text)
|
|
|
+{
|
|
|
+ if(a == b)
|
|
|
+ {
|
|
|
+ notifySuccess(text);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ notifyFail(text + " - expected '" + a + "' got '" + b + "'");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -58,7 +71,7 @@ void checkBool(bool a, bool b, string text)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- notifyFail(text + " - expected " + std::to_string(a) + " got " + std::to_string(b));
|
|
|
+ notifyFail(text + " - expected '" + std::to_string(a) + "' got '" + std::to_string(b) + "'");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -378,6 +391,73 @@ void testHashMap()
|
|
|
finalizeTest();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void checkCommandParser(string rawCommand, string command, vector<string>& args, string text)
|
|
|
+{
|
|
|
+ string parsedCommand;
|
|
|
+ vector<string> parsedArgs;
|
|
|
+
|
|
|
+ CommandUtils::splitString(rawCommand, parsedCommand, parsedArgs);
|
|
|
+
|
|
|
+ checkEqual(command, parsedCommand, text);
|
|
|
+ checkEqual(args.size(), parsedArgs.size(), text);
|
|
|
+
|
|
|
+ for(int i = 0; i < args.size() && i < parsedArgs.size(); i++)
|
|
|
+ {
|
|
|
+ checkEqual(args[i], parsedArgs[i], text);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void testCommandParser()
|
|
|
+{
|
|
|
+ vector<string> args;
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test", "test", args, "command without arguments");
|
|
|
+
|
|
|
+ args = {"aaa"};
|
|
|
+ checkCommandParser("test aaa", "test", args, "command with one argument");
|
|
|
+
|
|
|
+ args = {"aaa", "bbbb"};
|
|
|
+ checkCommandParser("test aaa bbbb", "test", args, "command with two arguments");
|
|
|
+
|
|
|
+ args = {"aaa", "bbbb", "ccccc"};
|
|
|
+ checkCommandParser("test aaa bbbb ccccc", "test", args, "command with three arguments");
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test ", "test", args, "command with spaces");
|
|
|
+
|
|
|
+ args = {"aaa", "bbbb"};
|
|
|
+ checkCommandParser("test aaa bbbb", "test", args, "command with arguments and spaces");
|
|
|
+
|
|
|
+ args = {"aaa", "bbbb"};
|
|
|
+ checkCommandParser("test aaa bbbb", "test", args, "command with arguments and spaces");
|
|
|
+
|
|
|
+ args = {"aaa bbbb"};
|
|
|
+ checkCommandParser("test \"aaa bbbb\"", "test", args, "command with one argument and quotation marks");
|
|
|
+
|
|
|
+ args = {"aaa bbbb", "ccc"};
|
|
|
+ checkCommandParser("test \"aaa bbbb\" ccc", "test", args, "command with two arguments and quotation marks");
|
|
|
+
|
|
|
+ args = {"ddd", "aaa bbbb", "ccc"};
|
|
|
+ checkCommandParser("test ddd \"aaa bbbb\" ccc", "test", args, "command with tree arguments and quotation marks");
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test \"", "", args, "command syntax exception 1");
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test aaa\"", "", args, "command syntax exception 2");
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test aaa\"bbb\"", "", args, "command syntax exception 3");
|
|
|
+
|
|
|
+ args = {};
|
|
|
+ checkCommandParser("test aaa \"bbb\"ccc", "", args, "command syntax exception 4");
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -386,6 +466,7 @@ int main(int argc, char** argv)
|
|
|
{
|
|
|
testUnsortedArrayList();
|
|
|
testHashMap();
|
|
|
+ testCommandParser();
|
|
|
return 0;
|
|
|
}
|
|
|
|