tree-sitter/test/helpers/spy_input.h

41 lines
967 B
C
Raw Normal View History

#ifndef HELPERS_SPY_INPUT_H_
#define HELPERS_SPY_INPUT_H_
#include <string>
#include <vector>
#include "tree_sitter/runtime.h"
2015-09-19 14:46:14 -07:00
struct SpyInputEdit {
2016-09-13 13:08:52 -07:00
size_t start_byte;
size_t bytes_removed;
2015-09-19 14:46:14 -07:00
std::string text_inserted;
};
2015-07-16 17:32:19 -07:00
class SpyInput {
uint32_t chars_per_chunk;
uint32_t buffer_size;
char *buffer;
uint32_t byte_offset;
2015-09-19 14:46:14 -07:00
std::vector<SpyInputEdit> undo_stack;
static const char * read(void *, uint32_t *);
static int seek(void *, uint32_t, uint32_t);
2016-09-13 13:08:52 -07:00
std::pair<std::string, TSPoint> swap_substr(size_t, size_t, std::string);
2015-09-19 13:29:30 -07:00
2014-08-06 13:00:35 -07:00
public:
2015-07-16 17:32:19 -07:00
SpyInput(std::string content, size_t chars_per_chunk);
~SpyInput();
TSInput input();
2015-09-19 13:29:30 -07:00
void clear();
2015-09-19 14:46:14 -07:00
TSInputEdit replace(size_t start_char, size_t chars_removed, std::string text);
TSInputEdit undo();
std::vector<std::string> strings_read() const;
2014-08-06 13:00:35 -07:00
std::string content;
TSInputEncoding encoding;
std::vector<std::pair<uint32_t, uint32_t>> ranges_read;
};
#endif // HELPERS_SPY_INPUT_H_