Skip to content

Commit

Permalink
test(Flattener): add more test cases for stable sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Oct 22, 2024
1 parent c131403 commit f473cd3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
8 changes: 4 additions & 4 deletions test/IntTag.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type t = int
let equal = Int.equal
let priority i = -i
let dump = Format.pp_print_int
type t = int * string
let equal = (=)
let priority (i, _) = -i
let dump fmt (i, s) = Format.fprintf fmt {|(%d, "%s")|} i (String.escaped s)
50 changes: 25 additions & 25 deletions test/TestExplicator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ let test_explication = Alcotest.of_pp (Explication.dump IntTag.dump)
let single_line mode eol () =
let source = `String {Range.title = None; content = "aaabbbcccdddeee" ^ eol} in
let begin_of_line1 : Range.position = {source; offset = 0; start_of_line = 0; line_num = 1} in
let range1 = 1, Range.make ({begin_of_line1 with offset = 3}, {begin_of_line1 with offset = 9}) in
let range2 = 2, Range.make ({begin_of_line1 with offset = 6}, {begin_of_line1 with offset = 12}) in
let range1 = (1, "1"), Range.make ({begin_of_line1 with offset = 3}, {begin_of_line1 with offset = 9}) in
let range2 = (2, "2"), Range.make ({begin_of_line1 with offset = 6}, {begin_of_line1 with offset = 12}) in
let expected : _ Explication.t =
[{source;
blocks =
[{begin_line_num = 1;
end_line_num = 1;
lines =
[{tags = [1; 2];
[{tags = [(1, "1"); (2, "2")];
segments =
[(None, "aaa");
(Some 1, "bbb");
(Some 2, "ccc");
(Some 2, "ddd");
(Some (1, "1"), "bbb");
(Some (2, "2"), "ccc");
(Some (2, "2"), "ddd");
(None, "eee");
]}]}
]}
Expand All @@ -32,7 +32,7 @@ let multi_lines_with_ls () =
let source = `String {Range.title = None; content = "aabbbbb\u{2028}bbbbccc"} in
let begin_of_line1 : Range.position = {source; offset = 0; start_of_line = 0; line_num = 1} in
let begin_of_line2 : Range.position = {source; offset = 10; start_of_line = 10; line_num = 2} in
let range = 1, Range.make ({begin_of_line1 with offset = 2}, {begin_of_line2 with offset = 14}) in
let range = (1, "1"), Range.make ({begin_of_line1 with offset = 2}, {begin_of_line2 with offset = 14}) in
let expected : _ Explication.t =
[{source;
blocks =
Expand All @@ -42,11 +42,11 @@ let multi_lines_with_ls () =
[{tags=[];
segments=
[(None, "aa");
(Some 1, "bbbbb");
(Some (1, "1"), "bbbbb");
]};
{tags=[1];
{tags=[(1, "1")];
segments=
[(Some 1, "bbbb");
[(Some (1, "1"), "bbbb");
(None, "ccc");
]}]}
]}
Expand Down Expand Up @@ -83,11 +83,11 @@ ggggghh
let begin_of_line15 : Range.position = {source; offset = 51; start_of_line = 51; line_num = 15} in
let ranges =
[
2, Range.make ({begin_of_line4 with offset = 17+1}, {begin_of_line4 with offset = 17+4});
1, Range.make ({begin_of_line2 with offset = 1+2}, {begin_of_line4 with offset = 17+4});
4, Range.make ({begin_of_line9 with offset = 33+2}, {begin_of_line9 with offset = 33+7});
8, Range.make ({begin_of_line9 with offset = 33+4}, {begin_of_line9 with offset = 33+7});
16, Range.make (begin_of_line15, {begin_of_line15 with offset = 51+5});
(2, "1"), Range.make ({begin_of_line4 with offset = 17+1}, {begin_of_line4 with offset = 17+4});
(1, "2"), Range.make ({begin_of_line2 with offset = 1+2}, {begin_of_line4 with offset = 17+4});
(4, "3"), Range.make ({begin_of_line9 with offset = 33+2}, {begin_of_line9 with offset = 33+7});
(8, "4"), Range.make ({begin_of_line9 with offset = 33+4}, {begin_of_line9 with offset = 33+7});
(16, "5"), Range.make (begin_of_line15, {begin_of_line15 with offset = 51+5});
]
in
let expected : _ Explication.t =
Expand All @@ -99,14 +99,14 @@ ggggghh
[{tags=[];
segments=
[(None, "aa");
(Some 1, "bbbbb")]};
(Some (1, "2"), "bbbbb")]};
{tags=[];
segments=
[(Some 1, "bbbbbbb")]};
{tags=[1;2];
[(Some (1, "2"), "bbbbbbb")]};
{tags=[(1, "2"); (2, "1")];
segments=
[(Some 1, "b");
(Some 2, "*cc");
[(Some (1, "2"), "b");
(Some (2, "1"), "*cc");
(None, "ddd")]};
{tags=[];
segments=
Expand All @@ -120,17 +120,17 @@ ggggghh
{tags=[];
segments=
[(None, "4")]};
{tags=[4; 8];
{tags=[(4, "3"); (8, "4")];
segments=
[(None, "ee");
(Some 4, "++");
(Some 8, "fff")]}]};
(Some (4, "3"), "++");
(Some (8, "4"), "fff")]}]};
{begin_line_num=15;
end_line_num=15;
lines=
[{tags=[16];
[{tags=[(16, "5")];
segments=
[(Some 16, "ggggg");
[(Some (16, "5"), "ggggg");
(None, "hh")]}]}]}]
in
let actual = E.explicate ~line_breaks:`Traditional ~block_splitting_threshold:5 ranges in
Expand Down
45 changes: 25 additions & 20 deletions test/TestFlattener.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ let single_line_flatten () =
{begin_of_line1 with offset = 9},
{begin_of_line1 with offset = 12}
in
let range1 = 1, Range.make (pt1, pt3) in
let range2 = 2, Range.make (pt2, pt4) in
let ranges =
[ (1, "1"), Range.make (pt1, pt3)
; (2, "2"), Range.make (pt1, pt3)
; (1, "3"), Range.make (pt1, pt3)
; (3, "4"), Range.make (pt2, pt4)
]
in
let expected : _ Flattener.t =
[(source,
[{begin_line_num=1;
end_line_num=1;
tagged_positions=[(Some 1, pt1);(Some 2, pt2);(Some 2, pt3);(None, pt4)];
tagged_lines=[(1,1);(2,1)]}])]
tagged_positions=[(Some (2, "2"), pt1);(Some (3, "4"), pt2);(Some (3, "4"), pt3);(None, pt4)];
tagged_lines=[((2, "2"), 1); ((1, "1"), 1); ((1, "3"), 1); ((3, "4"), 1)]}])]
in
let actual = F.flatten ~block_splitting_threshold:5 ~blend:(Explicator.default_blend ~priority:IntTag.priority) [range1; range2] in
let actual = F.flatten ~block_splitting_threshold:5 ~blend:(Explicator.default_blend ~priority:IntTag.priority) ranges in
Alcotest.(check test_flattened) "Flattener is correct" expected actual

let multi_lines () =
Expand Down Expand Up @@ -59,36 +64,36 @@ ggggghh
in
let ranges =
[
2, Range.make (pt18, pt21);
1, Range.make (pt3, pt21);
4, Range.make (pt35, pt40);
8, Range.make (pt37, pt40);
16, Range.make (begin_of_line15, pt56);
(2, "1"), Range.make (pt18, pt21);
(1, "2"), Range.make (pt3, pt21);
(4, "3"), Range.make (pt35, pt40);
(8, "4"), Range.make (pt37, pt40);
(16, "5"), Range.make (begin_of_line15, pt56);
]
in
let expected : _ Flattener.t =
[(source,
[{begin_line_num=2;
end_line_num=9;
tagged_positions=
[(Some 1, pt3);
(Some 2, pt18);
[(Some (1, "2"), pt3);
(Some (2, "1"), pt18);
(None, pt21);
(Some 4, pt35);
(Some 8, pt37);
(Some (4, "3"), pt35);
(Some (8, "4"), pt37);
(None, pt40)];
tagged_lines=
[(1, 4);
(2, 4);
(4, 9);
(8, 9)]};
[((1, "2"), 4);
((2, "1"), 4);
((4, "3"), 9);
((8, "4"), 9)]};
{begin_line_num=15;
end_line_num=15;
tagged_positions=
[(Some 16, begin_of_line15);
[(Some (16, "5"), begin_of_line15);
(None, pt56)];
tagged_lines=
[(16, 15)]}])]
[((16, "5"), 15)]}])]
in
let actual = F.flatten ~block_splitting_threshold:5 ~blend:(Explicator.default_blend ~priority:IntTag.priority) ranges in
Alcotest.(check test_flattened) "Flattener is correct" expected actual
Expand Down

0 comments on commit f473cd3

Please sign in to comment.