| 1 |
#ifndef MOCK_PARSE_TREE_INCLUDED |
| 2 |
#define MOCK_PARSE_TREE_INCLUDED |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "sql/parse_tree_items.h" |
| 33 |
#include "sql/sql_class.h" |
| 34 |
|
| 35 |
namespace my_testing { |
| 36 |
|
| 37 |
inline void fix(THD *thd, std::initializer_list<Item *> items) { |
| 38 |
Parse_context pc(thd, thd->lex->query_block); |
| 39 |
for (Item *item : items) { |
| 40 |
item->itemize(&pc, &item); |
| 41 |
item->fix_fields(thd, nullptr); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
class Mock_text_literal : public PTI_text_literal_text_string { |
| 46 |
public: |
| 47 |
Mock_text_literal(const char *s) |
| 48 |
: PTI_text_literal_text_string(POS(), false, |
| 49 |
{const_cast<char *>(s), strlen(s)}) {} |
| 50 |
}; |
| 51 |
|
| 52 |
inline Item *make_fixed_literal(THD *thd, const char *pattern) { |
| 53 |
if (pattern == nullptr) return new Item_null; |
| 54 |
auto item = new Mock_text_literal(pattern); |
| 55 |
fix(thd, {item}); |
| 56 |
return item; |
| 57 |
} |
| 58 |
|
| 59 |
class Mock_pt_item_list : public PT_item_list { |
| 60 |
public: |
| 61 |
Mock_pt_item_list(std::initializer_list<const char *> strings) { |
| 62 |
for (auto string : strings) push_back(new Mock_text_literal(string)); |
| 63 |
} |
| 64 |
|
| 65 |
template <typename T> |
| 66 |
Mock_pt_item_list(T t) { |
| 67 |
push_back(t); |
| 68 |
} |
| 69 |
|
| 70 |
template <typename T, typename... Ts> |
| 71 |
Mock_pt_item_list(T t, Ts... ts) : Mock_pt_item_list(ts...) { |
| 72 |
push_front(t); |
| 73 |
} |
| 74 |
}; |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
#endif |