1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
require "helper"
module Neovim
RSpec.describe Buffer do
let(:client) { Support.persistent_client }
let(:buffer) { client.current.buffer }
before do
client.command("normal ione")
client.command("normal otwo")
client.command("normal gg")
end
describe "#lines" do
it "returns a LineRange" do
expect(buffer.lines).to be_a(LineRange)
end
end
describe "#lines=" do
it "updates the buffer's lines" do
expect do
buffer.lines = ["two", "three"]
end.to change { buffer.lines.to_a }.to(["two", "three"])
end
end
describe "#set_name", "#name" do
it "updates the buffer name" do
expect do
buffer.set_name("test_buf")
end.to change { buffer.name }.to(/test_buf$/)
end
end
describe "#number" do
it "returns the buffer number" do
expect do
client.command("new")
end.to change { client.get_current_buf.number }
end
end
describe "#count" do
it "returns the number of lines" do
expect do
buffer.append(0, "zero")
end.to change { buffer.count }.from(2).to(3)
end
end
describe "#length" do
it "returns the number of lines" do
expect do
buffer.append(0, "zero")
end.to change { buffer.length }.from(2).to(3)
end
end
describe "#[]" do
it "returns the line at the line number" do
expect(buffer[1]).to eq("one")
end
it "raises on out of bounds" do
expect do
buffer[-1]
end.to raise_error(/out of bounds/)
expect do
buffer[4]
end.to raise_error(/out of bounds/)
end
end
describe "#[]=" do
it "sets the line at the line number" do
expect do
buffer[1] = "first"
end.to change { buffer[1] }.from("one").to("first")
end
it "raises on out of bounds" do
expect do
buffer[4] = "line"
end.to raise_error(/out of bounds/)
expect do
buffer[-1] = "line"
end.to raise_error(/out of bounds/)
end
end
describe "#delete" do
it "deletes at the line number" do
expect do
buffer.delete(2)
end.to change { buffer.lines.to_a }.to(["one"])
end
it "raises on out of bounds" do
expect do
buffer.delete(-1)
end.to raise_error(/out of bounds/)
expect do
buffer.delete(4)
end.to raise_error(/out of bounds/)
end
end
describe "#append" do
it "appends after the line" do
expect do
buffer.append(2, "last")
end.to change { buffer.lines.to_a }.to(["one", "two", "last"])
end
it "inserts before the first line" do
expect do
buffer.append(0, "first")
end.to change { buffer.lines.to_a }.to(["first", "one", "two"])
end
it "allows newlines" do
expect do
buffer.append(0, "first\nsecond")
end.to change { buffer.lines.to_a }.to(["first", "second", "one", "two"])
end
it "doesn't move the cursor" do
expect do
buffer.append(0, "first")
end.not_to change { client.get_current_win.cursor }
end
it "raises on out of bounds" do
expect do
buffer.append(-1, "line")
end.to raise_error(/out of bounds/)
expect do
buffer.append(4, "line")
end.to raise_error(/out of bounds/)
end
end
describe "#line_number" do
it "returns the current line number" do
expect do
client.command("normal j")
end.to change { buffer.line_number }.from(1).to(2)
end
it "returns nil on inactive buffers" do
expect do
client.command("new")
end.to change { buffer.line_number }.from(1).to(nil)
end
end
describe "#line" do
before { buffer.lines = ["one", "two"] }
it "returns the current line" do
expect do
client.command("normal j")
end.to change { buffer.line }.from("one").to("two")
end
it "returns nil for inactive buffers" do
client.command("new")
expect(buffer.line).to eq(nil)
end
end
describe "#line=" do
it "updates the current line" do
expect do
buffer.line = "first"
end.to change { buffer.line }.to("first")
end
end
end
end
|