| 138 | }; |
| 139 | |
| 140 | void TestDateTokens(const vector<DateToken>& toks, int year, int month, int day, |
| 141 | const char* separator) { |
| 142 | string fmt, val; |
| 143 | for (int i = 0; i < toks.size(); ++i) { |
| 144 | fmt.append(toks[i].fmt); |
| 145 | if (separator != nullptr && i + 1 < toks.size()) fmt.push_back(*separator); |
| 146 | |
| 147 | if (toks[i].month_name != nullptr) { |
| 148 | val.append(string(toks[i].month_name)); |
| 149 | } else { |
| 150 | val.append(lexical_cast<string>(toks[i].val)); |
| 151 | } |
| 152 | if (separator != nullptr && i + 1 < toks.size()) val.push_back(*separator); |
| 153 | } |
| 154 | |
| 155 | string fmt_val = "Format: " + fmt + ", Val: " + val; |
| 156 | DateTimeFormatContext dt_ctx(fmt.c_str()); |
| 157 | ASSERT_TRUE(SimpleDateFormatTokenizer::Tokenize(&dt_ctx, PARSE, false)) << fmt_val; |
| 158 | DateValue dv = DateValue::ParseSimpleDateFormat(val.c_str(), val.length(), dt_ctx); |
| 159 | ValidateDate(dv, year, month, day, fmt_val); |
| 160 | |
| 161 | string buff = dv.Format(dt_ctx); |
| 162 | EXPECT_TRUE(!buff.empty()) << fmt_val; |
| 163 | EXPECT_LE(buff.length(), dt_ctx.fmt_len) << fmt_val; |
| 164 | EXPECT_EQ(buff, val) << fmt_val << " " << buff; |
| 165 | } |
| 166 | |
| 167 | // This function will generate all permutations of tokens to test that the parsing and |
| 168 | // formatting is correct (position of tokens should be irrelevant). Note that separators |
no test coverage detected