diff --git a/README.md b/README.md index 420408f..1dd746a 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,84 @@ Pattern Expander was intended as password recovery tool where the password follows a certain pattern. For example `p[a@][s$][s$]` will result in: -`pass, p@ss, pa$s, p@$s, pas$, p@s$, pa$$, p@$$` + +```sh +pass +p@ss +pa$s +p@$s +pas$ +p@s$ +pa$$ +p@$$ +``` + Characters between [ ] are a group. Every character in a group is substituted at the given position. +## Installation + +### Requirements +- gcc +- make +- gtest +- gcov + +On Debian, those can be installed via: +`sudo apt-get install build-essential libgtest-dev gcovr` + +### Build and install +```sh +make +sudo make install +``` + +You don't need to install patext, after building, you can run it from the the `./bin/` folder + +## Usage +``` +patexp [-h | --help] [] + commands: + run [ .. ] | : Generates strings from a list of patterns + validate [ .. ] | : Validates if the patterns provided are syntaxically correct + configure: Sets the various configuration options +``` + +### Examples + +Assuming you have compiled and running out of the local bin folder: + +```sh +$./bin/patexp run [a-c] [1-3] abc[1-3] +a +b +c +1 +2 +3 +abc1 +abc2 +abc3 + +``` + +We can load the patterns from a file via + +```sh +$cat patters.txt | ./bin/patexp run +a +b +c +1 +2 +3 +abc1 +abc2 +abc3 + +``` + ## Syntax @@ -62,24 +135,28 @@ All characters are case sensative. Result: 1a, 2a, 3a, 1b, 2b, 3b, 1c, 2c, 3c -## Building +## Development ### Targets: - release: default target. Builds the main executable -- test: Builds the main executable with debug info. Builds and runs the unit tests. -- report - creates a coverage report +- debug: Builds with debug information and test coverage enabled +- test: Builds with debug information and test coverage enabled. Builds and runs the unit tests. +- report: Creates a test coverage report -### Install build requirements: -`sudo apt-get install build-essential libgtest-dev gcovr` +### Testing +Some example patters are given in the `test_data` folder. Those can be used for system level testing. +For example: -### Compile: -`make` +```sh +cat test_data/valid_patterns.txt | patext run +``` + +```sh +cat test_data/valid_patterns.txt | xargs patext run +``` ### Run unit tests `make test` -## Usage -`patexp ` - diff --git a/src/Expander.cpp b/src/Expander.cpp index d633c07..5185244 100755 --- a/src/Expander.cpp +++ b/src/Expander.cpp @@ -6,16 +6,20 @@ using namespace std; using namespace PatternExpander; Expander::Expander(wchar_t esc, wchar_t range, wchar_t grpBegin, wchar_t grpEnd) : - escapeSymbol(esc), rangeSymbol(range), groupBegin(grpBegin), groupEnd(grpEnd) {} + escapeSymbol(esc), rangeSymbol(range), groupBegin(grpBegin), groupEnd( + grpEnd) +{ +} void Expander::generate(const wstring &pattern) -{ +{ vector results; //This will expand all range (a-b) expressions wstring expandedPattern = expand(pattern); size_t pLength = expandedPattern.length(); - if (pLength == 0) { + if (pLength == 0) + { return; } @@ -28,8 +32,8 @@ void Expander::generate(const wstring &pattern) bool isFirstInGroup = true; vector partials; - - for (uint i = 0; i < pLength; i++) { + for (uint i = 0; i < pLength; i++) + { if (expandedPattern[i] == escapeSymbol) //escape character reached { if (isEscSeq(expandedPattern, i)) //check if the next character is a valid escape sequence @@ -38,11 +42,15 @@ void Expander::generate(const wstring &pattern) continue; } - } else if (expandedPattern[i] == groupBegin && !escSeqReached) { + } + else if (expandedPattern[i] == groupBegin && !escSeqReached) + { isFirstInGroup = true; load++; continue; - } else if (expandedPattern[i] == groupEnd && !escSeqReached) { + } + else if (expandedPattern[i] == groupEnd && !escSeqReached) + { load--; continue; } @@ -52,9 +60,10 @@ void Expander::generate(const wstring &pattern) { if (currentItem == 0) //data array is empty { - results.push_back(wstring(1,expandedPattern[i])); + results.push_back(wstring(1, expandedPattern[i])); currentItem++; - } else //variations are present. + } + else //variations are present. { //add the constant character to all variations //Just appending the constant character to all patterns @@ -63,7 +72,8 @@ void Expander::generate(const wstring &pattern) results[j] = results[j] + pattern[i]; } } - } else if (load > 0) //wchar_tacter inside a variable block + } + else if (load > 0) //wchar_tacter inside a variable block { //when we first enter the variable block, we save the //existing patterns @@ -81,12 +91,14 @@ void Expander::generate(const wstring &pattern) //That means that the result set is empty //If that's the case, just add the first item from the varible block if (partials.empty()) - results.push_back(wstring(1,expandedPattern[i])); - else { + results.push_back(wstring(1, expandedPattern[i])); + else + { //The result set is not empty //Append the first item of the variable block to the existing patterns, //then add it the result set. - for (uint item = 0; item < partials.size(); item++) { + for (uint item = 0; item < partials.size(); item++) + { results.push_back(partials[item] + expandedPattern[i]); } } @@ -95,19 +107,19 @@ void Expander::generate(const wstring &pattern) escSeqReached = false; } //end for - data.insert(data.end(), results.begin(), results.end()); } -uint Expander::getBlockElements(const wstring& pattern, uint& start, - vector& items) +uint Expander::getBlockElements(const wstring &pattern, uint &start, + vector &items) { uint currentIndx = start; //remember we are going from right to left //Find the end of the block while (currentIndx >= 0) //we are going backwards { - if (pattern[currentIndx] == groupBegin || pattern[currentIndx] == groupEnd) + if (pattern[currentIndx] == groupBegin + || pattern[currentIndx] == groupEnd) break; //reached the end of the block currentIndx--; } @@ -134,9 +146,9 @@ uint Expander::getBlockElements(const wstring& pattern, uint& start, } } //end for //We should have the actual number of items - //*items = new wstring[itemCount]; + //*items = new wstring[itemCount]; - //Extract the items + //Extract the items uint i = 0; wstring temp; for (currentIndx = endIndx + 1; currentIndx <= start; currentIndx++) //now we move left to right @@ -160,7 +172,7 @@ uint Expander::getBlockElements(const wstring& pattern, uint& start, { //TODO: Check if we really need to have an exclude symbol // if (pattern[currentIndx] != excludeSymbol) - items[i] = pattern[currentIndx]; + items[i] = pattern[currentIndx]; // else // (*items)[i] = ""; // i++; @@ -176,23 +188,27 @@ uint Expander::getBlockElements(const wstring& pattern, uint& start, return itemCount; } -inline bool Expander::isEscSeq(const std::wstring& pattern, uint position) const +inline bool Expander::isEscSeq(const std::wstring &pattern, uint position) const { bool result = false; if (position + 1 <= pattern.length() && pattern[position] == escapeSymbol) //first char. in sequence is indeed escape char. { //check second char in sequence wchar_t second = pattern[position + 1]; - if (second == escapeSymbol || second == rangeSymbol || second == groupBegin || second == groupEnd) { + if (second == escapeSymbol || second == rangeSymbol + || second == groupBegin || second == groupEnd) + { result = true; - } else { - result = false; + } + else + { + result = false; } } return result; } -std::wstring Expander::expand(const std::wstring& pattern) +std::wstring Expander::expand(const std::wstring &pattern) { int size = pattern.length(); wstring result = pattern; @@ -217,12 +233,12 @@ std::wstring Expander::expand(const std::wstring& pattern) wchar_t startRange = pattern[i - 1]; wchar_t endRange = pattern[i + 1]; - + std::locale loc2("C.UTF8"); //if both are alphabetical chars if ((isalpha(startRange, loc2) && isalpha(endRange, loc2)) - || (isdigit(startRange, loc2) && isdigit(endRange, loc2))) + || (isdigit(startRange, loc2) && isdigit(endRange, loc2))) { if ((int) startRange < (int) endRange) //inorder { @@ -254,17 +270,17 @@ std::wstring Expander::expand(const std::wstring& pattern) return result; } - - -bool Expander::validate(const wstring& pattern) +bool Expander::validate(const wstring &pattern) { int loadBrackets = 0; uint loadQuotes = 0; for (uint i = 0; i < pattern.size(); i++) { - if (pattern[i] == escapeSymbol) { - if (!isEscSeq(pattern, i)) { + if (pattern[i] == escapeSymbol) + { + if (!isEscSeq(pattern, i)) + { output << "Error: Invalid escape sequence detected" << endl; output << pattern << endl; output << std::setw(i) << "^" << endl; @@ -295,10 +311,16 @@ bool Expander::validate(const wstring& pattern) } } + if (loadBrackets != 0) + { + output << "Error: Unclosed group bracket" << endl; + } + return ((loadQuotes % 2 == 0) && (loadBrackets % 2 == 0)); } -void Expander::getCombinations(vector& data, vector& newElements) +void Expander::getCombinations(vector &data, + vector &newElements) { vector original = data; vector temp = data; @@ -313,14 +335,14 @@ void Expander::getCombinations(vector& data, vector& newElemen } //If the initial list is empty, just add the first entity of the new list - if(numOrgElements == 0) + if (numOrgElements == 0) { data.push_back(newElements[0]); } else { - for (int i= 0; i < numOrgElements; i++) + for (int i = 0; i < numOrgElements; i++) { data[i] = data[i] + newElements[0]; } @@ -337,8 +359,7 @@ void Expander::getCombinations(vector& data, vector& newElemen } } -void Expander::processGroup(const wstring& pattern, uint& i, - uint& currentItem) +void Expander::processGroup(const wstring &pattern, uint &i, uint ¤tItem) { //wstring* newItems = NULL; vector newItems; @@ -382,6 +403,7 @@ void Expander::processGroup(const wstring& pattern, uint& i, //delete[] newItems; //clean up temporary resource } -std::vector Expander::getData() { +std::vector Expander::getData() +{ return data; } diff --git a/src/Expander.h b/src/Expander.h index 26713a5..3b08551 100755 --- a/src/Expander.h +++ b/src/Expander.h @@ -11,50 +11,75 @@ typedef unsigned int uint; namespace PatternExpander { - const wchar_t DEFAULT_ESC_SYM = '/'; - const wchar_t DEFAULT_RANGE_SYM = '-'; - const wchar_t GROUP_SYM_BEGIN = '['; - const wchar_t GROUP_SYM_END = ']'; - const wchar_t SINGLE_QUOTE = '\''; - const wchar_t DOUBLE_QUOTE = '"'; - +const wchar_t DEFAULT_ESC_SYM = '/'; +const wchar_t DEFAULT_RANGE_SYM = '-'; +const wchar_t GROUP_SYM_BEGIN = '['; +const wchar_t GROUP_SYM_END = ']'; +const wchar_t SINGLE_QUOTE = '\''; +const wchar_t DOUBLE_QUOTE = '"'; class Expander { public: - + ///Consructor - explicit Expander(wchar_t esc = PatternExpander::DEFAULT_ESC_SYM, wchar_t range = PatternExpander::DEFAULT_RANGE_SYM, - wchar_t grpBegin = PatternExpander::GROUP_SYM_BEGIN, wchar_t grpEnd = PatternExpander::GROUP_SYM_END); + explicit Expander(wchar_t esc = PatternExpander::DEFAULT_ESC_SYM, + wchar_t range = PatternExpander::DEFAULT_RANGE_SYM, + wchar_t grpBegin = PatternExpander::GROUP_SYM_BEGIN, + wchar_t grpEnd = PatternExpander::GROUP_SYM_END); ///The main function - it expands the pattern and generates are possible combinations - void generate(const std::wstring& pattern); + void generate(const std::wstring &pattern); ///Validate the pattern bool validate(const std::wstring &pattern); ///prints out all generated patterns - friend std::wostream& operator<<(std::wostream& os, const Expander& pg) + friend std::wostream& operator<<(std::wostream &os, const Expander &pg) { for (size_t i = 0; i < pg.data.size(); i++) { - os< getData(); @@ -68,38 +93,39 @@ class Expander wchar_t groupBegin; wchar_t groupEnd; - ///the main data storage std::vector data; - + ///Used to find all opening / closing brackets -// std::vector findAllInstances(const std::wstring& target, const std::wstring& item); + // std::vector findAllInstances(const std::wstring& target, const std::wstring& item); - ///Looks for any ranges and expands them - std::wstring expand(const std::wstring& pattern); + //Looks for any ranges and expands them + std::wstring expand(const std::wstring &pattern); ///Returns true if a valid escape sequence is present at the given position - bool isEscSeq(const std::wstring& pattern, uint position) const; - + bool isEscSeq(const std::wstring &pattern, uint position) const; + /**A character set is a group of characters surrounded by [] * Characters can be listed individually - [abc] * or as a range [a-c]. Special characters lose their meaning inside a set */ - std::vector handleCharacterSet(const std::wstring& pattern, uint); + std::vector handleCharacterSet(const std::wstring &pattern, + uint); /*** * */ - uint getBlockElements(const std::wstring& pattern, uint& start, std::vector& items); + uint getBlockElements(const std::wstring &pattern, uint &start, + std::vector &items); - void getCombinations(std::vector &data, std::vector &newElements); + void getCombinations(std::vector &data, + std::vector &newElements); void processGroup(const std::wstring &pattern, uint &i, uint ¤tItem); - bool getLoadBalance(const std::wstring& pattern); - + bool getLoadBalance(const std::wstring &pattern); }; -}//end namespace +} //end namespace #endif diff --git a/src/main.cpp b/src/main.cpp index 5603568..ebbe525 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,25 +2,38 @@ #include #include #include +#include #include "Expander.h" using namespace std; -int main(int argc, char *argv[]) +void run_command(int argc, char *argv[]) { wstring pattern; - PatternExpander::Expander exp; - - std::setlocale(LC_CTYPE, "C.UTF8"); - + PatternExpander::Expander exp; std::wstring_convert> wcu8; - if (argc > 1) + + string command(argv[1]); + std::transform(command.begin(), command.end(), command.begin(), ::tolower); + + if (argc > 2) { - for (int currentParam = 1; currentParam < argc; currentParam++) + for (int currentParam = 2; currentParam < argc; currentParam++) { pattern = wcu8.from_bytes(argv[currentParam]); - exp.generate(pattern); + if (command == "validate") + { + exp.validate(pattern); + wcerr << exp.output.str(); + } + else if (command == "run") + { + exp.generate(pattern); + } + } + // Validate will not produce any data output + wcout << exp; } else { @@ -28,15 +41,65 @@ int main(int argc, char *argv[]) while (cin >> temp) { pattern = wcu8.from_bytes(temp); - exp.generate(pattern); + if (command == "validate") + { + exp.validate(pattern); + wcerr << exp.output.str(); + } + else if (command == "run") + { + exp.generate(pattern); + } } + // Validate will not produce any data output + wcout << exp; + } +} + +int main(int argc, char *argv[]) +{ + + std::setlocale(LC_CTYPE, "C.UTF8"); + + wstring usage = LR"(usage: patexp [-h | --help] [] + commands: + run [ .. ] | : Generates strings from a list of patterns + validate [ .. ] | : Validates if the patterns provided are syntaxically correct + configure: Sets the various configuration options)"; + + if (argc > 1) + { + string command(argv[1]); + std::transform(command.begin(), command.end(), command.begin(), + ::tolower); + if (command == "-h" || command == "--help") + { + wcout << usage << endl; + exit(0); + } + else if (command == "run" || command == "validate") + { + run_command(argc, argv); + + } + else if (command == "config" || command == "configure") + { + wcout << "Configure is currently not implemented" << endl; + exit(1); + } + else + { + wcerr << "Error: unknown command" << endl; + wcout << usage << endl; + } + + } + else + { + // command not provided + wcerr << "Error: no command was provided" << endl; + wcout << usage << endl; } - - //Output the results - wcout<d"; bool result = altExpander.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_GroupBegin_alt) { +TEST_F(TestExpander, testValidation_validEscSeqs_GroupBegin_alt) +{ //A pattern with valid escape seq wstring pattern = L"abc#{d"; bool result = altExpander.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_GroupEnd_alt) { +TEST_F(TestExpander, testValidation_validEscSeqs_GroupEnd_alt) +{ //A pattern with valid escape seq wstring pattern = L"abc#}d"; bool result = altExpander.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_EscChar_alt) { +TEST_F(TestExpander, testValidation_validEscSeqs_EscChar_alt) +{ //A pattern with valid escape seq wstring pattern = L"abc##d"; bool result = altExpander.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_Quotes_alt) { +TEST_F(TestExpander, testValidation_validEscSeqs_Quotes_alt) +{ //A pattern with valid escape seq wstring pattern = L"abc\"de\""; bool result = altExpander.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_GroupBegin_alt) { +TEST_F(TestExpander, testValidation_invalidGroups_GroupBegin_alt) +{ //A pattern with invalid group wstring pattern = L"abc{d"; bool result = altExpander.validate(pattern); EXPECT_FALSE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_GroupEnd_alt) { +TEST_F(TestExpander, testValidation_invalidGroups_GroupEnd_alt) +{ //A pattern with invalid group wstring pattern = L"abc}d"; bool result = altExpander.validate(pattern); EXPECT_FALSE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_alt) { +TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_alt) +{ //A pattern with invalid group wstring pattern = L"abc{d{e}z"; @@ -301,7 +327,8 @@ TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_alt) { EXPECT_FALSE(result); } -TEST_F(TestExpander, testGenerate_StaticBlock_alt) { +TEST_F(TestExpander, testGenerate_StaticBlock_alt) +{ wstring pattern = L"abcd"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -309,7 +336,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_alt) { EXPECT_EQ(data[0], pattern); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_alt) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_alt) +{ wstring pattern = L"abc#{d"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -317,7 +345,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_alt) { EXPECT_EQ(data[0], L"abc{d"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_alt) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_alt) +{ wstring pattern = L"abc#}d"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -325,7 +354,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_alt) { EXPECT_EQ(data[0], L"abc}d"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_alt) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_alt) +{ wstring pattern = L"abc#>d"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -333,7 +363,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_alt) { EXPECT_EQ(data[0], L"abc>d"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_alt) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_alt) +{ wstring pattern = L"abc##d"; altExpander.generate(pattern); @@ -343,7 +374,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_alt) { } -TEST_F(TestExpander, testGenerate_VariableBlock_Range_alt) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range_alt) +{ wstring pattern = L"{a>c}"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -353,7 +385,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range_alt) { EXPECT_EQ(data[2], L"c"); } -TEST_F(TestExpander, testGenerate_VariableBlock_Range2_alt) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range2_alt) +{ wstring pattern = L"1{a>c}"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -362,7 +395,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range2_alt) { EXPECT_EQ(data[1], L"1b"); EXPECT_EQ(data[2], L"1c"); } -TEST_F(TestExpander, testGenerate_VariableBlock_Range3_alt) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range3_alt) +{ wstring pattern = L"{123}{a>c}"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -378,7 +412,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range3_alt) { EXPECT_EQ(data[8], L"3c"); } -TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_alt) { +TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_alt) +{ wstring pattern = L"{1>3}{a>c}"; altExpander.generate(pattern); auto data = altExpander.getData(); @@ -394,7 +429,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_alt) { EXPECT_EQ(data[8], L"3c"); } -TEST_F(TestExpander, testGenerate_VariableBlock_EmbededVarBlock_alt) { +TEST_F(TestExpander, testGenerate_VariableBlock_EmbededVarBlock_alt) +{ wstring pattern = L"{123{a>c}}"; altExpander.generate(pattern); @@ -419,56 +455,64 @@ TEST_F(TestExpander, testValidation_valid_Cyrilic) EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_Dash_Cyrilic) { +TEST_F(TestExpander, testValidation_validEscSeqs_Dash_Cyrilic) +{ //A pattern with valid escape seq wstring pattern = L"абв/-г"; bool result = underTest.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_GroupBegin_Cyrilic) { +TEST_F(TestExpander, testValidation_validEscSeqs_GroupBegin_Cyrilic) +{ //A pattern with valid escape seq wstring pattern = L"абв/[г"; bool result = underTest.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_GroupEnd_Cyrilic) { +TEST_F(TestExpander, testValidation_validEscSeqs_GroupEnd_Cyrilic) +{ //A pattern with valid escape seq wstring pattern = L"абв/]г"; bool result = underTest.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_EscChar_Cyrilic) { +TEST_F(TestExpander, testValidation_validEscSeqs_EscChar_Cyrilic) +{ //A pattern with valid escape seq wstring pattern = L"абв//г"; bool result = underTest.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_validEscSeqs_Quotes_Cyrilic) { +TEST_F(TestExpander, testValidation_validEscSeqs_Quotes_Cyrilic) +{ //A pattern with valid escape seq wstring pattern = L"абв\"гд\""; bool result = underTest.validate(pattern); EXPECT_TRUE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_GroupBegin_Cyrilic) { +TEST_F(TestExpander, testValidation_invalidGroups_GroupBegin_Cyrilic) +{ //A pattern with invalid group wstring pattern = L"абв[г"; bool result = underTest.validate(pattern); EXPECT_FALSE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_GroupEnd_Cyrilic) { +TEST_F(TestExpander, testValidation_invalidGroups_GroupEnd_Cyrilic) +{ //A pattern with invalid group wstring pattern = L"абв]г"; bool result = underTest.validate(pattern); EXPECT_FALSE(result); } -TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_Cyrilic) { +TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_Cyrilic) +{ //A pattern with invalid group wstring pattern = L"абв[г[д]е"; @@ -476,7 +520,8 @@ TEST_F(TestExpander, testValidation_invalidGroups_UnbalancedGroups_Cyrilic) { EXPECT_FALSE(result); } -TEST_F(TestExpander, testGenerate_StaticBlock_Cyrilic) { +TEST_F(TestExpander, testGenerate_StaticBlock_Cyrilic) +{ wstring pattern = L"абвг"; underTest.generate(pattern); auto data = underTest.getData(); @@ -484,7 +529,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_Cyrilic) { EXPECT_EQ(data[0], pattern); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_Cyrilic) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_Cyrilic) +{ wstring pattern = L"абв/[г"; underTest.generate(pattern); auto data = underTest.getData(); @@ -492,7 +538,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpBegin_Cyrilic) { EXPECT_EQ(data[0], L"абв[г"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_Cyrilic) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_Cyrilic) +{ wstring pattern = L"абв/]г"; underTest.generate(pattern); auto data = underTest.getData(); @@ -500,7 +547,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscGrpEnd_Cyrilic) { EXPECT_EQ(data[0], L"абв]г"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_Cyrilic) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_Cyrilic) +{ wstring pattern = L"абв/-г"; underTest.generate(pattern); auto data = underTest.getData(); @@ -508,7 +556,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscDash_Cyrilic) { EXPECT_EQ(data[0], L"абв-г"); } -TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_Cyrilic) { +TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_Cyrilic) +{ wstring pattern = L"абв//г"; underTest.generate(pattern); @@ -518,7 +567,8 @@ TEST_F(TestExpander, testGenerate_StaticBlock_EscEscChar_Cyrilic) { } -TEST_F(TestExpander, testGenerate_VariableBlock_Range_Cyrilic) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range_Cyrilic) +{ wstring pattern = L"[а-в]"; underTest.generate(pattern); auto data = underTest.getData(); @@ -528,7 +578,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range_Cyrilic) { EXPECT_EQ(data[2], L"в"); } -TEST_F(TestExpander, testGenerate_VariableBlock_Range2_Cyrilic) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range2_Cyrilic) +{ wstring pattern = L"1[а-в]"; underTest.generate(pattern); auto data = underTest.getData(); @@ -537,7 +588,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range2_Cyrilic) { EXPECT_EQ(data[1], L"1б"); EXPECT_EQ(data[2], L"1в"); } -TEST_F(TestExpander, testGenerate_VariableBlock_Range3_Cyrilic) { +TEST_F(TestExpander, testGenerate_VariableBlock_Range3_Cyrilic) +{ wstring pattern = L"[123][а-в]"; underTest.generate(pattern); auto data = underTest.getData(); @@ -553,7 +605,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_Range3_Cyrilic) { EXPECT_EQ(data[8], L"3в"); } -TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_Cyrilic) { +TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_Cyrilic) +{ wstring pattern = L"[1-3][а-в]"; underTest.generate(pattern); auto data = underTest.getData(); @@ -569,7 +622,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_2Ranges_Cyrilic) { EXPECT_EQ(data[8], L"3в"); } -TEST_F(TestExpander, testGenerate_VariableBlock_EmbededVarBlock_Cyrilic) { +TEST_F(TestExpander, testGenerate_VariableBlock_EmbededVarBlock_Cyrilic) +{ wstring pattern = L"[123[а-в]]"; underTest.generate(pattern); @@ -586,9 +640,8 @@ TEST_F(TestExpander, testGenerate_VariableBlock_EmbededVarBlock_Cyrilic) { EXPECT_EQ(data[8], L"3в"); } - - -int main(int argc, char** argv) { +int main(int argc, char **argv) +{ ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test_data/valid_patterns.txt b/test_data/valid_patterns.txt new file mode 100644 index 0000000..818f1a3 --- /dev/null +++ b/test_data/valid_patterns.txt @@ -0,0 +1,3 @@ +[a-c] +Hello +abc[1-4] diff --git a/test_data/valid_patterns_cyrillic.txt b/test_data/valid_patterns_cyrillic.txt new file mode 100644 index 0000000..319ed68 --- /dev/null +++ b/test_data/valid_patterns_cyrillic.txt @@ -0,0 +1,3 @@ +[а-в] +Здравей +абв[1-4]