Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
396 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
std="vim" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
local highlight = require("baleia.highlight") | ||
local text = require("baleia.text") | ||
|
||
describe("[all]", function() | ||
it("", function() | ||
local lines = { "; first line\x1b[32m ", "; \x1b[31msecond line" } | ||
it("", function() | ||
local lines = { "; first line\x1b[32m ", "; \x1b[31msecond line" } | ||
|
||
assert.combinators.match({ | ||
highlights = { | ||
{ line = 1, firstcolumn = 18, name = "B_0_2_none_none" }, | ||
{ line = 2, firstcolumn = 8, name = "B_0_1_none_none" } }, | ||
definitions = { | ||
B_0_1_none_none = { foreground = "#800000", ctermfg = 1 }, | ||
B_0_2_none_none = { foreground = "#008000", ctermfg = 2 }, | ||
}, | ||
}, | ||
highlight.all({ name = 'B', line_starts_at = 3, colors = { cterm = { }, gui = { } } }, | ||
{ global = { column = 0, line = 0 } }, | ||
lines)) | ||
end) | ||
local marks, highlights = text.colors( | ||
{ strip_ansi_codes = true, name = "B", line_starts_at = 3, colors = { cterm = {}, gui = {} } }, | ||
lines, | ||
{ global = { column = 1, line = 0 } } | ||
) | ||
|
||
assert.combinators.match({ | ||
{ line = 1, firstcolumn = 14, highlight = "B_0_2_none_none" }, | ||
{ line = 2, firstcolumn = 4, highlight = "B_0_1_none_none" }, | ||
}, marks) | ||
|
||
assert.combinators.match({ | ||
B_0_1_none_none = { foreground = "#800000", ctermfg = 1 }, | ||
B_0_2_none_none = { foreground = "#008000", ctermfg = 2 }, | ||
}, highlights) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,135 @@ | ||
local locations = require("baleia.locations") | ||
|
||
describe("[merge_neighbours]", function() | ||
it("Two codes,in the **same** line, without text between them", function() | ||
local locs = locations.extract({ "\x1b[0m\x1b[31mfirst line" }) | ||
assert.combinators.match({ | ||
{ | ||
style = { offset = 9 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 1 } | ||
} | ||
}, locations.merge_neighbours(locs)) | ||
end) | ||
|
||
it("Two codes,in **different** line, without text between them", function() | ||
local locs = locations.extract({ "first line\x1b[1m", "\x1b[31msecond line" }) | ||
assert.combinators.match({ | ||
{ | ||
style = { offset = 5 }, | ||
from = { line = 1, column = 11 }, | ||
to = { line = 2 } | ||
}, | ||
}, locations.merge_neighbours(locs)) | ||
end) | ||
|
||
it("Two codes,in the **same** line, without text between them", function() | ||
local locs = locations.extract({ strip_ansi_codes = true }, {}, { "\x1b[0m\x1b[31mfirst line" }) | ||
assert.combinators.match({ | ||
{ | ||
style = { offset = 9 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 1 }, | ||
}, | ||
}, locs) | ||
end) | ||
|
||
it("Two codes,in **different** line, without text between them", function() | ||
local locs = locations.extract({ strip_ansi_codes = true }, {}, { "first line\x1b[1m", "\x1b[31msecond line" }) | ||
assert.combinators.match({ | ||
{ | ||
style = { offset = 5 }, | ||
from = { line = 1, column = 11 }, | ||
to = { line = 2 }, | ||
}, | ||
}, locs) | ||
end) | ||
end) | ||
|
||
describe("[extract]", function() | ||
it("with no sequences", function() | ||
assert.combinators.match({}, locations.extract({ "no sequences" })) | ||
end) | ||
|
||
it("with sequence at the beginning of the line", function() | ||
local lines = { "\x1b[0mfirst line" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 1 }, to = { line = 1 } } | ||
}, locations.extract(lines)) | ||
end) | ||
|
||
it("with sequence at the end of the line", function() | ||
local lines = { "first line\x1b[0m" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 1 } } | ||
}, locations.extract(lines)) | ||
end) | ||
|
||
it("with sequence at the beginning and end of the line", function() | ||
local lines = { "first line\x1b[0m", "\x1b[0msecond line" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 1 } }, | ||
{ from = { line = 2, column = 1 }, to = { line = 2 } }, | ||
}, locations.extract(lines)) | ||
end) | ||
|
||
it("with blank line between", function() | ||
local lines = { "first line\x1b[0m", "second line", "third \x1b[0mline" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 3 } }, | ||
{ from = { line = 3, column = 7 }, to = { line = 3 } }, | ||
}, locations.extract(lines)) | ||
end) | ||
|
||
it("with blank lines at the end", function() | ||
local lines = { "first \x1b[31mline", "second \x1b[32mline\x1b[0m", "third line" } | ||
|
||
assert.combinators.match({ | ||
{ from = { line = 1, column = 7 }, to = { line = 2, column = 7 } }, | ||
{ from = { line = 2, column = 8 }, to = { line = 2, column = 16 } }, | ||
{ from = { line = 2, column = 17 }, to = { line = 3 } }, | ||
}, locations.extract(lines)) | ||
end) | ||
it("with no sequences", function() | ||
assert.combinators.match({}, locations.extract({ strip_ansi_codes = true }, {}, { "no sequences" })) | ||
end) | ||
|
||
it("with sequence at the beginning of the line", function() | ||
local lines = { "\x1b[0mfirst line" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 1 }, to = { line = 1 } }, | ||
}, locations.extract({ strip_ansi_codes = true }, {}, lines)) | ||
end) | ||
|
||
it("with sequence at the end of the line", function() | ||
local lines = { "first line\x1b[0m" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 1 } }, | ||
}, locations.extract({ strip_ansi_codes = true }, {}, lines)) | ||
end) | ||
|
||
it("with sequence at the beginning and end of the line", function() | ||
local lines = { "first line\x1b[0m", "\x1b[0msecond line" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 2 } }, | ||
}, locations.extract({ strip_ansi_codes = true }, {}, lines)) | ||
end) | ||
|
||
it("with blank line between", function() | ||
local lines = { "first line\x1b[0m", "second line", "third \x1b[0mline" } | ||
assert.combinators.match({ | ||
{ from = { line = 1, column = 11 }, to = { line = 3 } }, | ||
{ from = { line = 3, column = 7 }, to = { line = 3 } }, | ||
}, locations.extract({ strip_ansi_codes = true }, {}, lines)) | ||
end) | ||
|
||
it("with blank lines at the end", function() | ||
local lines = { "first \x1b[31mline", "second \x1b[32mline\x1b[0m", "third line" } | ||
|
||
assert.combinators.match({ | ||
{ from = { line = 1, column = 7 }, to = { line = 2, column = 7 } }, | ||
{ from = { line = 2, column = 8 }, to = { line = 2, column = 11 } }, | ||
{ from = { line = 2, column = 12 }, to = { line = 3 } }, | ||
}, locations.extract({ strip_ansi_codes = true }, {}, lines)) | ||
end) | ||
end) | ||
|
||
local offsets = require("baleia.locations.offsets") | ||
describe("[with_offset]", function() | ||
it("considers global offsets", function() | ||
local offset = { global = { line = 100, column = 10 } } | ||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 101, column = 11 }, | ||
to = { line = 102, column = 11 }, | ||
}, | ||
}, locations.with_offset(offset, location)) | ||
end) | ||
|
||
it("considers line offsets", function() | ||
local offset = { | ||
global = { line = 0, column = 0 }, | ||
line = { [1] = { column = 5 } } | ||
} | ||
|
||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 1, column = 6 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
}, locations.with_offset(offset, location)) | ||
end) | ||
|
||
it("considers both global and line offsets", function() | ||
local offset = { | ||
global = { line = 100, column = 10 }, | ||
line = { [1] = { column = 5 } } | ||
} | ||
|
||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 101, column = 16 }, | ||
to = { line = 102, column = 11 }, | ||
}, | ||
}, locations.with_offset(offset, location)) | ||
end) | ||
end) | ||
|
||
describe("[strip_ansi_codes]", function() | ||
it("", function() | ||
local locs = { | ||
{ style = { offset = 5 }, from = { line = 1, column = 7 }, to = { line = 2, column = 7 } }, | ||
{ style = { offset = 5 }, from = { line = 2, column = 8 }, to = { line = 2, column = 16 } }, | ||
{ style = { offset = 4 }, from = { line = 2, column = 17 }, to = { line = 3 } }, | ||
} | ||
assert.combinators.match({ | ||
{ from = { column = 7 }, to = { column = 7 } }, | ||
{ from = { column = 8 }, to = { column = 11 } }, | ||
{ from = { column = 12 } }, | ||
}, locations.strip_ansi_codes(locs)) | ||
end) | ||
end) | ||
|
||
describe("[ignore_ansi_codes]", function() | ||
it("", function() | ||
local locs = { | ||
{ style = { offset = 5 }, from = { line = 1, column = 7 }, to = { line = 2, column = 7 } }, | ||
{ style = { offset = 5 }, from = { line = 2, column = 8 }, to = { line = 2, column = 16 } }, | ||
{ style = { offset = 4 }, from = { line = 2, column = 17 }, to = { line = 3 } }, | ||
} | ||
assert.combinators.match({ | ||
{ from = { column = 12 }, to = { column = 7 } }, | ||
{ from = { column = 13 }, to = { column = 16 } }, | ||
{ from = { column = 21 } }, | ||
}, locations.ignore_ansi_codes(locs)) | ||
end) | ||
it("considers global offsets", function() | ||
local offset = { global = { line = 100, column = 10 } } | ||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 101, column = 11 }, | ||
to = { line = 102, column = 11 }, | ||
}, | ||
}, offsets.apply(offset, location)) | ||
end) | ||
|
||
it("considers line offsets", function() | ||
local offset = { | ||
global = { line = 0, column = 0 }, | ||
lines = { [1] = { column = 5 } }, | ||
} | ||
|
||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 1, column = 6 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
}, offsets.apply(offset, location)) | ||
end) | ||
|
||
it("considers both global and line offsets", function() | ||
local offset = { | ||
global = { line = 100, column = 10 }, | ||
lines = { [1] = { column = 5 } }, | ||
} | ||
|
||
local location = { | ||
{ | ||
style = { offset = 0 }, | ||
from = { line = 1, column = 1 }, | ||
to = { line = 2, column = 1 }, | ||
}, | ||
} | ||
|
||
assert.combinators.match({ | ||
{ | ||
from = { line = 1, column = 6 }, | ||
to = { line = 102, column = 11 }, | ||
}, | ||
}, offsets.apply(offset, location)) | ||
end) | ||
end) |
Oops, something went wrong.