Skip to content

Commit

Permalink
Returned an error if a line less than the document start is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
scohen committed May 18, 2023
1 parent 1371073 commit d6e2508
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/common/lib/lexical/document/lines.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Lexical.Document.Lines do
end

def fetch_line(%__MODULE__{lines: lines, starting_index: starting_index}, index)
when index - starting_index >= tuple_size(lines) do
when index - starting_index >= tuple_size(lines) or index < starting_index do
:error
end

Expand Down
13 changes: 13 additions & 0 deletions apps/server/test/document_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ defmodule Lexical.DocumentTest do
describe "new" do
setup [:with_a_simple_module]

test "it should handle out of bounds lines" do
doc = new(file_uri(), "hello", 1)

assert :error = fetch_line_at(doc, 0)
assert :error = fetch_text_at(doc, 0)

assert :error = fetch_line_at(doc, -1)
assert :error = fetch_text_at(doc, -1)

assert :error = fetch_line_at(doc, 2)
assert :error = fetch_text_at(doc, 2)
end

test "it should be able to parse a single line" do
assert parsed = new(file_uri(), "hello", 1)

Expand Down

0 comments on commit d6e2508

Please sign in to comment.