diff --git a/spec/runtime/helpers/spy_input.cc b/spec/runtime/helpers/spy_input.cc index 8d7ebdaf..4e1020b6 100644 --- a/spec/runtime/helpers/spy_input.cc +++ b/spec/runtime/helpers/spy_input.cc @@ -8,7 +8,7 @@ using std::string; static const size_t UTF8_MAX_CHAR_SIZE = 4; -static size_t string_char_count(const string &text) { +size_t SpyInput::char_count(const string &text) { const char *bytes = text.data(); size_t len = text.size(); size_t character = 0, byte = 0; @@ -102,7 +102,7 @@ TSInput SpyInput::input() { TSInputEdit SpyInput::replace(size_t start_char, size_t chars_removed, string text) { string text_removed = swap_substr(start_char, chars_removed, text); - size_t chars_inserted = string_char_count(text); + size_t chars_inserted = SpyInput::char_count(text); undo_stack.push_back(SpyInputEdit{start_char, chars_inserted, text_removed}); return {start_char, chars_inserted, chars_removed}; } @@ -111,7 +111,7 @@ TSInputEdit SpyInput::undo() { SpyInputEdit entry = undo_stack.back(); undo_stack.pop_back(); swap_substr(entry.position, entry.chars_removed, entry.text_inserted); - size_t chars_inserted = string_char_count(entry.text_inserted); + size_t chars_inserted = SpyInput::char_count(entry.text_inserted); return TSInputEdit{entry.position, chars_inserted, entry.chars_removed}; } diff --git a/spec/runtime/helpers/spy_input.h b/spec/runtime/helpers/spy_input.h index b2a0249c..a0b268b6 100644 --- a/spec/runtime/helpers/spy_input.h +++ b/spec/runtime/helpers/spy_input.h @@ -31,6 +31,8 @@ class SpyInput { TSInputEdit replace(size_t start_char, size_t chars_removed, std::string text); TSInputEdit undo(); + static size_t char_count(const std::string &); + std::string content; std::vector strings_read; }; diff --git a/spec/runtime/language_specs.cc b/spec/runtime/language_specs.cc index aa48b212..7967d5b7 100644 --- a/spec/runtime/language_specs.cc +++ b/spec/runtime/language_specs.cc @@ -145,8 +145,8 @@ describe("Languages", [&]() { std::set> insertions; for (size_t i = 0; i < 50; i++) { - size_t edit_position = random() % entry.input.size(); - size_t deletion_size = random() % (entry.input.size() - edit_position); + size_t edit_position = random() % SpyInput::char_count(entry.input); + size_t deletion_size = random() % (SpyInput::char_count(entry.input) - edit_position); string inserted_text = random_words(random() % 4 + 1); if (insertions.insert({edit_position, inserted_text}).second) {