diff --git a/spec/helpers/random_helpers.cc b/spec/helpers/random_helpers.cc new file mode 100644 index 00000000..1ce26400 --- /dev/null +++ b/spec/helpers/random_helpers.cc @@ -0,0 +1,35 @@ +#include +#include + +using std::string; + +static string random_string(char min, char max) { + string result; + size_t length = random() % 12; + for (size_t i = 0; i < length; i++) { + char inserted_char = min + (random() % (max - min)); + result += inserted_char; + } + return result; +} + +static string random_char(string characters) { + size_t index = random() % characters.size(); + return string() + characters[index]; +} + +string random_words(size_t count) { + string result; + bool just_inserted_word = false; + for (size_t i = 0; i < count; i++) { + if (random() % 10 < 6) { + result += random_char("!(){}[]<>+-="); + } else { + if (just_inserted_word) + result += " "; + result += random_string('a', 'z'); + just_inserted_word = true; + } + } + return result; +} diff --git a/spec/helpers/random_helpers.h b/spec/helpers/random_helpers.h new file mode 100644 index 00000000..84aa1a23 --- /dev/null +++ b/spec/helpers/random_helpers.h @@ -0,0 +1,8 @@ +#ifndef HELPERS_RANDOM_HELPERS_H_ +#define HELPERS_RANDOM_HELPERS_H_ + +#include + +std::string random_words(size_t count); + +#endif // HELPERS_RANDOM_HELPERS_H_ diff --git a/spec/integration/corpus_specs.cc b/spec/integration/corpus_specs.cc index 96f399b8..c701e2e0 100644 --- a/spec/integration/corpus_specs.cc +++ b/spec/integration/corpus_specs.cc @@ -7,6 +7,7 @@ #include "helpers/point_helpers.h" #include "helpers/encoding_helpers.h" #include "helpers/record_alloc.h" +#include "helpers/random_helpers.h" #include static void expect_the_correct_tree(TSNode node, TSDocument *document, string tree_string) { @@ -60,37 +61,6 @@ static void expect_a_consistent_tree(TSNode node, TSDocument *document) { AssertThat(has_changes, Equals(some_child_has_changes)); } -static string random_string(char min, char max) { - string result; - size_t length = random() % 12; - for (size_t i = 0; i < length; i++) { - char inserted_char = min + (random() % (max - min)); - result += inserted_char; - } - return result; -} - -static string random_char(string characters) { - size_t index = random() % characters.size(); - return string() + characters[index]; -} - -static string random_words(size_t count) { - string result; - bool just_inserted_word = false; - for (size_t i = 0; i < count; i++) { - if (random() % 10 < 6) { - result += random_char("!(){}[]<>+-="); - } else { - if (just_inserted_word) - result += " "; - result += random_string('a', 'z'); - just_inserted_word = true; - } - } - return result; -} - START_TEST describe("The Corpus", []() {