From f473cd382c1c118f21eb4cb9eb6ba5a8d871b3e4 Mon Sep 17 00:00:00 2001 From: favonia Date: Tue, 22 Oct 2024 09:13:20 -0500 Subject: [PATCH] test(Flattener): add more test cases for stable sorting --- test/IntTag.ml | 8 +++---- test/TestExplicator.ml | 50 +++++++++++++++++++++--------------------- test/TestFlattener.ml | 45 ++++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/test/IntTag.ml b/test/IntTag.ml index 0af093f5..f21a71c4 100644 --- a/test/IntTag.ml +++ b/test/IntTag.ml @@ -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) diff --git a/test/TestExplicator.ml b/test/TestExplicator.ml index 9d1c9c47..34b4d41a 100644 --- a/test/TestExplicator.ml +++ b/test/TestExplicator.ml @@ -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"); ]}]} ]} @@ -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 = @@ -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"); ]}]} ]} @@ -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 = @@ -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= @@ -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 diff --git a/test/TestFlattener.ml b/test/TestFlattener.ml index 918a572b..68f96257 100644 --- a/test/TestFlattener.ml +++ b/test/TestFlattener.ml @@ -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 () = @@ -59,11 +64,11 @@ 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 = @@ -71,24 +76,24 @@ ggggghh [{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