This function will generate all permutations of tokens to test that the parsing and formatting is correct (position of tokens should be irrelevant). Note that separators are also combined with EACH token permutation to get the widest coverage on formats. This forces out the parsing and format logic edge cases.
| 169 | // are also combined with EACH token permutation to get the widest coverage on formats. |
| 170 | // This forces out the parsing and format logic edge cases. |
| 171 | void TestDateTokenPermutations(vector<DateToken>* toks, int year, int month, int day) { |
| 172 | sort(toks->begin(), toks->end()); |
| 173 | |
| 174 | const char* SEPARATORS = " ~!@%^&*_+-:;|\\,./"; |
| 175 | do { |
| 176 | // Validate we can parse date raw tokens (no separators) |
| 177 | TestDateTokens(*toks, year, month, day, nullptr); |
| 178 | |
| 179 | // Validate we can parse date with separators |
| 180 | for (const char* separator = SEPARATORS; *separator != 0; ++separator) { |
| 181 | TestDateTokens(*toks, year, month, day, separator); |
| 182 | } |
| 183 | } while (next_permutation(toks->begin(), toks->end())); |
| 184 | } |
| 185 | |
| 186 | TEST(DateTest, ParseFormatCustomFormats) { |
| 187 | // Test custom formats by generating all permutations of tokens to check parsing and |
no test coverage detected