From 32e79700bf9dbd2d71d6570c65cd323273518c2e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 16 Jul 2015 17:32:19 -0700 Subject: [PATCH] Rename SpyReader -> SpyInput --- .../helpers/{spy_reader.cc => spy_input.cc} | 22 +++++++-------- .../helpers/{spy_reader.h => spy_input.h} | 12 ++++---- spec/runtime/languages/language_specs.cc | 6 ++-- spec/runtime/parser_spec.cc | 28 +++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) rename spec/runtime/helpers/{spy_reader.cc => spy_input.cc} (82%) rename spec/runtime/helpers/{spy_reader.h => spy_input.h} (69%) diff --git a/spec/runtime/helpers/spy_reader.cc b/spec/runtime/helpers/spy_input.cc similarity index 82% rename from spec/runtime/helpers/spy_reader.cc rename to spec/runtime/helpers/spy_input.cc index f1255d69..bd95345b 100644 --- a/spec/runtime/helpers/spy_reader.cc +++ b/spec/runtime/helpers/spy_input.cc @@ -1,4 +1,4 @@ -#include "runtime/helpers/spy_reader.h" +#include "runtime/helpers/spy_input.h" #include #include #include "utf8proc.h" @@ -23,16 +23,16 @@ static long byte_for_character(const char *str, size_t len, size_t goal_characte } static const char * spy_read(void *data, size_t *bytes_read) { - SpyReader *reader = static_cast(data); + SpyInput *reader = static_cast(data); return reader->read(bytes_read); } static int spy_seek(void *data, TSLength byte_offset) { - SpyReader *reader = static_cast(data); + SpyInput *reader = static_cast(data); return reader->seek(byte_offset.bytes); } -SpyReader::SpyReader(string content, size_t chars_per_chunk) : +SpyInput::SpyInput(string content, size_t chars_per_chunk) : content(content), chars_per_chunk(chars_per_chunk), buffer_size(4 * chars_per_chunk), @@ -40,11 +40,11 @@ SpyReader::SpyReader(string content, size_t chars_per_chunk) : byte_offset(0), strings_read({ "" }) {} -SpyReader::~SpyReader() { +SpyInput::~SpyInput() { delete buffer; } -const char * SpyReader::read(size_t *bytes_read) { +const char * SpyInput::read(size_t *bytes_read) { if (byte_offset > content.size()) { *bytes_read = 0; return ""; @@ -72,13 +72,13 @@ const char * SpyReader::read(size_t *bytes_read) { return buffer; } -int SpyReader::seek(size_t pos) { +int SpyInput::seek(size_t pos) { strings_read.push_back(""); byte_offset = pos; return 0; } -TSInput SpyReader::input() { +TSInput SpyInput::input() { TSInput result; result.data = this; result.seek_fn = spy_seek; @@ -87,20 +87,20 @@ TSInput SpyReader::input() { return result; } -bool SpyReader::insert(size_t char_index, string text) { +bool SpyInput::insert(size_t char_index, string text) { long pos = byte_for_character(content.data(), content.size(), char_index); if (pos < 0) return false; content.insert(pos, text); return true; } -bool SpyReader::erase(size_t char_index, size_t len) { +bool SpyInput::erase(size_t char_index, size_t len) { long pos = byte_for_character(content.data(), content.size(), char_index); if (pos < 0) return false; content.erase(pos, len); return true; } -void SpyReader::clear() { +void SpyInput::clear() { strings_read.clear(); } diff --git a/spec/runtime/helpers/spy_reader.h b/spec/runtime/helpers/spy_input.h similarity index 69% rename from spec/runtime/helpers/spy_reader.h rename to spec/runtime/helpers/spy_input.h index 44c18111..0959c073 100644 --- a/spec/runtime/helpers/spy_reader.h +++ b/spec/runtime/helpers/spy_input.h @@ -1,14 +1,14 @@ -#ifndef HELPERS_SPY_READER_H_ -#define HELPERS_SPY_READER_H_ +#ifndef HELPERS_spy_input_H_ +#define HELPERS_spy_input_H_ #include #include #include "tree_sitter/runtime.h" -class SpyReader { +class SpyInput { public: - SpyReader(std::string content, size_t chars_per_chunk); - ~SpyReader(); + SpyInput(std::string content, size_t chars_per_chunk); + ~SpyInput(); void clear(); TSInput input(); @@ -25,4 +25,4 @@ class SpyReader { std::vector strings_read; }; -#endif // HELPERS_SPY_READER_H_ +#endif // HELPERS_spy_input_H_ diff --git a/spec/runtime/languages/language_specs.cc b/spec/runtime/languages/language_specs.cc index aeac659c..e17b1bd2 100644 --- a/spec/runtime/languages/language_specs.cc +++ b/spec/runtime/languages/language_specs.cc @@ -1,6 +1,6 @@ #include "runtime/runtime_spec_helper.h" #include "runtime/helpers/read_test_entries.h" -#include "runtime/helpers/spy_reader.h" +#include "runtime/helpers/spy_input.h" #include "runtime/helpers/log_debugger.h" #include @@ -48,7 +48,7 @@ describe("Languages", [&]() { continue; it(("handles random insertions in " + entry.description).c_str(), [&]() { - SpyReader reader(entry.input, 3); + SpyInput reader(entry.input, 3); ts_document_set_input(doc, reader.input()); string garbage("%^&*"); @@ -64,7 +64,7 @@ describe("Languages", [&]() { }); it(("handles random deletions in " + entry.description).c_str(), [&]() { - SpyReader reader(entry.input, 3); + SpyInput reader(entry.input, 3); ts_document_set_input(doc, reader.input()); size_t position = entry.input.size() / 2; diff --git a/spec/runtime/parser_spec.cc b/spec/runtime/parser_spec.cc index d363d3a7..4263836c 100644 --- a/spec/runtime/parser_spec.cc +++ b/spec/runtime/parser_spec.cc @@ -1,5 +1,5 @@ #include "runtime/runtime_spec_helper.h" -#include "runtime/helpers/spy_reader.h" +#include "runtime/helpers/spy_input.h" #include "runtime/helpers/log_debugger.h" extern "C" const TSLanguage * ts_language_json(); @@ -10,33 +10,33 @@ START_TEST describe("Parser", [&]() { TSDocument *doc; - SpyReader *reader; + SpyInput *input; TSNode *root; size_t chunk_size; before_each([&]() { chunk_size = 3; - reader = nullptr; + input = nullptr; doc = ts_document_make(); }); after_each([&]() { ts_document_free(doc); - if (reader) - delete reader; + if (input) + delete input; }); auto set_text = [&](const char *text) { - reader = new SpyReader(text, chunk_size); - ts_document_set_input(doc, reader->input()); + input = new SpyInput(text, chunk_size); + ts_document_set_input(doc, input->input()); root = ts_document_root_node(doc); AssertThat(ts_node_size(root).bytes + ts_node_pos(root).bytes, Equals(strlen(text))); - reader->clear(); + input->clear(); }; auto insert_text = [&](size_t position, string text) { size_t prev_size = ts_node_size(root).bytes + ts_node_pos(root).bytes; - AssertThat(reader->insert(position, text), IsTrue()); + AssertThat(input->insert(position, text), IsTrue()); ts_document_edit(doc, { position, text.length(), 0 }); root = ts_document_root_node(doc); @@ -46,7 +46,7 @@ describe("Parser", [&]() { auto delete_text = [&](size_t position, size_t length) { size_t prev_size = ts_node_size(root).bytes + ts_node_pos(root).bytes; - AssertThat(reader->erase(position, length), IsTrue()); + AssertThat(input->erase(position, length), IsTrue()); ts_document_edit(doc, { position, 0, length }); root = ts_document_root_node(doc); @@ -56,8 +56,8 @@ describe("Parser", [&]() { auto replace_text = [&](size_t position, size_t length, string new_text) { size_t prev_size = ts_node_size(root).bytes + ts_node_pos(root).bytes; - AssertThat(reader->erase(position, length), IsTrue()); - AssertThat(reader->insert(position, new_text), IsTrue()); + AssertThat(input->erase(position, length), IsTrue()); + AssertThat(input->insert(position, new_text), IsTrue()); ts_document_edit(doc, { position, new_text.size(), length }); @@ -241,7 +241,7 @@ describe("Parser", [&]() { }); it("re-reads only the changed portion of the input", [&]() { - AssertThat(reader->strings_read, Equals(vector({ " abc * 5)" }))); + AssertThat(input->strings_read, Equals(vector({ " abc * 5)" }))); }); }); @@ -269,7 +269,7 @@ describe("Parser", [&]() { }); it("re-reads only the changed portion of the input", [&]() { - AssertThat(reader->strings_read, Equals(vector({ "123 + 5 ", " 4", " ^ (", "" }))); + AssertThat(input->strings_read, Equals(vector({ "123 + 5 ", " 4", " ^ (", "" }))); }); });