forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordWrapTests.re
91 lines (86 loc) · 2.28 KB
/
WordWrapTests.re
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
open EditorCoreTypes;
open Oni_Core;
open TestFramework;
let makeLine = BufferLine.make(~measure=_ => 1.0);
let makeLineWithWideTabs =
BufferLine.make(~measure=uchar =>
if (Uchar.equal(uchar, Uchar.of_char('\t'))) {
2.0;
} else {
1.0;
}
);
let characterWidth = {
let (_, width) =
makeLine("a")
|> BufferLine.getPixelPositionAndWidth(~index=CharacterIndex.zero);
width;
};
let threeCharacterWidth = 3. *. characterWidth;
describe("WordWrap", ({describe, _}) => {
describe("none", ({test, _}) => {
test("no wrap gets full pixel length of line", ({expect, _}) => {
let line = "abcdef" |> makeLine;
let wrap = WordWrap.none(line);
expect.equal(
wrap,
(
[|{byte: ByteIndex.zero, character: CharacterIndex.zero}|],
6. *. characterWidth,
),
);
})
});
describe("fixed", ({test, _}) => {
test("#3372 - handle tabs correctly", ({expect, _}) => {
let line = "\tabc" |> makeLineWithWideTabs;
let wrap = WordWrap.fixed(~pixels=threeCharacterWidth, line);
// This should end up with:
// [
// "\ta",
// "bc"
// ]
expect.equal(
wrap,
(
[|
{byte: ByteIndex.zero, character: CharacterIndex.zero},
{
byte: ByteIndex.(zero + 2),
character: CharacterIndex.(zero + 2),
},
|],
threeCharacterWidth,
),
);
});
test("ascii line within wrap point", ({expect, _}) => {
let line = "abc" |> makeLine;
let wrap = WordWrap.fixed(~pixels=threeCharacterWidth, line);
expect.equal(
wrap,
(
[|{byte: ByteIndex.zero, character: CharacterIndex.zero}|],
threeCharacterWidth,
),
);
});
test("ascii line exceeds wrap point", ({expect, _}) => {
let line = "abcdef" |> makeLine;
let wrap = WordWrap.fixed(~pixels=threeCharacterWidth, line);
expect.equal(
wrap,
(
[|
{byte: ByteIndex.zero, character: CharacterIndex.zero},
{
byte: ByteIndex.(zero + 3),
character: CharacterIndex.(zero + 3),
},
|],
threeCharacterWidth,
),
);
});
});
});