|
| 1 | + |
| 2 | +#include "wsjcpp_validators.h" |
| 3 | + |
| 4 | +#include <algorithm> |
| 5 | +#include <iostream> |
| 6 | +#include <vector> |
| 7 | + |
| 8 | +int main() { |
| 9 | + int found_errors = 0; |
| 10 | + |
| 11 | + struct local { |
| 12 | + local(const std::string &value, bool expected) |
| 13 | + : value(value), expected(expected) { |
| 14 | + |
| 15 | + }; |
| 16 | + std::string value; |
| 17 | + bool expected; |
| 18 | + }; |
| 19 | + std::vector<local> tests; |
| 20 | + tests.push_back(local("some", false)); |
| 21 | + tests.push_back(local("2020-01-01", true)); |
| 22 | + tests.push_back(local("2020-12-00", false)); |
| 23 | + tests.push_back(local("0000-00-00", false)); |
| 24 | + tests.push_back(local("0000-01-01", true)); |
| 25 | + tests.push_back(local("2020-12-31", true)); |
| 26 | + tests.push_back(local("2020-02-29", true)); |
| 27 | + tests.push_back(local("2021-02-29", false)); |
| 28 | + tests.push_back(local("1898-01-01", true)); |
| 29 | + tests.push_back(local("1898-15-01", false)); |
| 30 | + tests.push_back(local("1898-01-32", false)); |
| 31 | + |
| 32 | + WsjcppValidatorDate *pValidator = new WsjcppValidatorDate(); |
| 33 | + |
| 34 | + for (int i = 0; i < tests.size(); i++) { |
| 35 | + local t = tests[i]; |
| 36 | + std::string error; |
| 37 | + bool got = pValidator->isValid(t.value, error); |
| 38 | + if (got != t.expected) { |
| 39 | + found_errors++; |
| 40 | + std::cerr << "Expected " << (t.expected ? "true" : "false") << ", but got " << (got ? "true" : "false") << " for " |
| 41 | + << t.value << "error: " << error << std::endl; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + if (found_errors > 0) { |
| 46 | + std::cerr << "FAILED" << std::endl; |
| 47 | + return 1; |
| 48 | + } |
| 49 | + |
| 50 | + std::cout << "OK" << std::endl; |
| 51 | + return 0; |
| 52 | +} |
0 commit comments