Toying with event recording to see if it can be used for testing
This commit is contained in:
@@ -227,6 +227,9 @@ void MergeSort(int64_t Count, Edit *First, Edit *Temp) {
|
||||
|
||||
void ApplyEdits(Buffer *buffer, Array<Edit> edits) {
|
||||
Scratch scratch((Arena *)buffer->allocator.object);
|
||||
Assert(buffer->data[0]);
|
||||
Assert(buffer->allocator.proc);
|
||||
Assert(buffer->lines.len);
|
||||
|
||||
// Figure out how much we insert and how much we delete so
|
||||
// we can resize buffers properly if necessary
|
||||
@@ -356,13 +359,22 @@ void ApplyEdits(Buffer *buffer, Array<Edit> edits) {
|
||||
}
|
||||
buffer->lines.add({base_index, base_index + string.len});
|
||||
}
|
||||
|
||||
Assert(buffer->data[0]);
|
||||
Assert(buffer->allocator.proc);
|
||||
Assert(buffer->lines.len);
|
||||
}
|
||||
|
||||
void InitBuffer(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
Array<Edit> edits = {};
|
||||
AddEdit(&edits, {}, "");
|
||||
ApplyEdits(buffer, edits);
|
||||
void InitBuffer(Allocator allocator, Buffer *buffer, int64_t _size = 4096) {
|
||||
int64_t size = AlignUp(_size, 4096);
|
||||
buffer->allocator = allocator;
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
buffer->data[i] = AllocArray(allocator, char, size);
|
||||
Assert(buffer->data[i]);
|
||||
}
|
||||
buffer->cap = size;
|
||||
buffer->lines.allocator = allocator;
|
||||
buffer->lines.add({});
|
||||
}
|
||||
|
||||
String CopyNullTerminated(Allocator allocator, Buffer &buffer, Range range) {
|
||||
@@ -569,3 +581,29 @@ int64_t Seek(Buffer &buffer, int64_t pos, int64_t direction = ITERATE_FORWARD) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t MoveRight(Buffer &buffer, int64_t pos) {
|
||||
pos = pos + 1;
|
||||
pos = AdjustUTF8Pos(buffer, pos);
|
||||
Assert(pos >= 0 && pos <= buffer.len);
|
||||
return pos;
|
||||
}
|
||||
|
||||
int64_t MoveLeft(Buffer &buffer, int64_t pos) {
|
||||
pos = pos - 1;
|
||||
pos = AdjustUTF8Pos(buffer, pos, -1);
|
||||
Assert(pos >= 0 && pos <= buffer.len);
|
||||
return pos;
|
||||
}
|
||||
|
||||
int64_t MoveDown(Buffer &buffer, int64_t pos) {
|
||||
LineAndColumn info = FindLineAndColumn(buffer, pos);
|
||||
int64_t new_pos = FindPos(buffer, info.line.number + 1, info.column);
|
||||
return new_pos;
|
||||
}
|
||||
|
||||
int64_t MoveUp(Buffer &buffer, int64_t pos) {
|
||||
LineAndColumn info = FindLineAndColumn(buffer, pos);
|
||||
int64_t new_pos = FindPos(buffer, info.line.number - 1, info.column);
|
||||
return new_pos;
|
||||
}
|
||||
Reference in New Issue
Block a user