In SpyReader, store entire strings read, not individual chunks
Makes assertions easier to write. We don't need to assert that the strings were read chunk by chunk.
This commit is contained in:
parent
fbb9b24d7b
commit
a3a7546450
3 changed files with 5 additions and 8 deletions
|
|
@ -8,7 +8,7 @@ static const char * spy_read(void *data, size_t *bytes_read) {
|
|||
size_t size = std::min(reader->chunk_size,
|
||||
reader->content.length() - reader->position);
|
||||
const char *result = reader->content.data() + reader->position;
|
||||
reader->chunks_read.push_back(string(result, size));
|
||||
reader->strings_read.back() += string(result, size);
|
||||
reader->position += size;
|
||||
*bytes_read = size;
|
||||
return result;
|
||||
|
|
@ -16,6 +16,7 @@ static const char * spy_read(void *data, size_t *bytes_read) {
|
|||
|
||||
static int spy_seek(void *data, size_t position) {
|
||||
SpyReader *reader = static_cast<SpyReader *>(data);
|
||||
reader->strings_read.push_back("");
|
||||
reader->position = position;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public:
|
|||
size_t position;
|
||||
size_t chunk_size;
|
||||
ts_input input;
|
||||
std::vector<std::string> chunks_read;
|
||||
std::vector<std::string> strings_read;
|
||||
};
|
||||
|
||||
#endif // HELPERS_SPY_READER_H_
|
||||
|
|
|
|||
|
|
@ -33,12 +33,8 @@ describe("parsing", [&]() {
|
|||
});
|
||||
|
||||
it("reads the entire input", [&]() {
|
||||
AssertThat(reader->chunks_read, Equals(vector<string>({
|
||||
"{ \"ke",
|
||||
"y\": [",
|
||||
"1, 2]",
|
||||
" }",
|
||||
""
|
||||
AssertThat(reader->strings_read, Equals(vector<string>({
|
||||
"{ \"key\": [1, 2] }"
|
||||
})));
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue