2 open Reordered_argument_collections
4 module DS
= Diagnostic_subscription
6 let errors_to_string buf x
=
7 List.iter x ~f
: begin fun error
->
8 Printf.bprintf buf
"%s\n" (Errors.to_string error
)
11 let diagnostics_to_string x
=
12 let buf = Buffer.create
1024 in
13 SMap.iter x ~f
:begin fun path errors
->
14 Printf.bprintf
buf "%s:\n" path
;
15 errors_to_string buf errors
;
19 let error_list_to_string_buffer buf x
=
20 List.iter x ~f
: begin fun error
->
21 Printf.bprintf
buf "%s\n" Errors.(error
|> to_absolute
|> to_string
)
24 let error_list_to_string errors
=
25 let buf = Buffer.create
1024 in
26 error_list_to_string_buffer buf errors
;
29 let create_path x
= Relative_path.(create Root
("/" ^ x
))
31 let error_in path message
= Errors.parsing_error
((Pos.make_from path
), message
)
34 let a_path = create_path "A" in
35 let b_path = create_path "B" in
38 Errors.do_with_context
a_path Errors.Parsing
begin fun () ->
39 error_in a_path "foo";
43 Errors.do_with_context
a_path Errors.Parsing
begin fun () ->
44 error_in a_path "bar";
47 let bar_error_a = Errors.incremental_update_set
50 ~rechecked
:(Relative_path.Set.singleton
a_path)
55 Errors.do_with_context
b_path Errors.Parsing
begin fun () ->
56 error_in b_path "baz";
59 let baz_error_b = Errors.incremental_update_set
62 ~rechecked
:(Relative_path.Set.singleton
b_path)
66 let bar_error_cleared_a = Errors.incremental_update_set
69 ~rechecked
:(Relative_path.Set.singleton
a_path)
72 let ds = DS.of_id ~id
:1 ~init
:Errors.empty
in
74 let priority_files = Relative_path.Set.empty
in
75 let reparsed = Relative_path.Set.empty
in
76 let rechecked_a = Relative_path.Map.singleton
a_path FileInfo.empty_names
in
77 let rechecked_b = Relative_path.Map.singleton
b_path FileInfo.empty_names
in
79 let ds, diagnostics
= DS.update
ds
82 ~rechecked
:rechecked_a
83 ~global_errors
:foo_error_a
85 |> DS.pop_errors ~global_errors
:foo_error_a in
87 "/A:\nFile \"/A\", line 0, characters 0-0:\nfoo (Parsing[1002])\n\n" in
88 Asserter.String_asserter.assert_equals
expected
89 (diagnostics_to_string diagnostics
)
90 "foo error in A should be pushed";
92 let ds, diagnostics
= DS.update
ds
95 ~rechecked
:rechecked_a
96 ~global_errors
:foo_error_a
97 ~full_check_done
:false
98 |> DS.pop_errors ~global_errors
:foo_error_a in
100 Asserter.Bool_asserter.assert_equals
true
101 (SMap.is_empty diagnostics
)
102 "Unchanged diagnostics in A should be not pushed again";
105 "/A:\nFile \"/A\", line 0, characters 0-0:\nbar (Parsing[1002])\n\n" in
106 let ds, diagnostics
= DS.update
ds
109 ~rechecked
:rechecked_a
110 ~global_errors
:bar_error_a
111 ~full_check_done
:false
112 |> DS.pop_errors ~global_errors
:bar_error_a in
113 Asserter.String_asserter.assert_equals
expected
114 (diagnostics_to_string diagnostics
)
115 "foo error in A should be replaced with bar";
117 let priority_files = Relative_path.Set.singleton
b_path in
120 "/B:\nFile \"/B\", line 0, characters 0-0:\nbaz (Parsing[1002])\n\n" in
121 let ds, diagnostics
= DS.update
ds
124 ~rechecked
:rechecked_b
125 ~global_errors
:baz_error_b
126 ~full_check_done
:false
127 |> DS.pop_errors ~global_errors
:baz_error_b in
128 Asserter.String_asserter.assert_equals
expected
129 (diagnostics_to_string diagnostics
)
130 "baz error in B should be added";
132 let ds, diagnostics
= DS.update
ds
135 ~rechecked
:rechecked_a
136 ~global_errors
:bar_error_cleared_a
137 ~full_check_done
:false
138 |> DS.pop_errors ~global_errors
:bar_error_cleared_a in
139 let expected = "/A:\n" in
140 Asserter.String_asserter.assert_equals
expected
141 (diagnostics_to_string diagnostics
)
142 "A diagnostics should be cleared";
147 let test_error_sources () =
148 let a_path = create_path "A" in
149 let b_path = create_path "B" in
152 Errors.do_
begin fun () ->
153 Errors.run_in_context
a_path Errors.Typing
begin fun () ->
154 error_in a_path "error from a";
156 Errors.run_in_context
b_path Errors.Typing
begin fun () ->
157 error_in a_path "error from b";
162 let ds = DS.of_id ~id
:1 ~init
:Errors.empty
in
164 let priority_files = Relative_path.Set.empty
in
165 let rechecked = Relative_path.Map.(
166 (singleton
a_path FileInfo.empty_names
) |> union
167 (singleton
b_path FileInfo.empty_names
)
170 let ds = DS.update
ds
172 ~
reparsed:Relative_path.Set.empty
174 ~global_errors
:errors
175 ~full_check_done
:true
178 Asserter.Bool_asserter.assert_equals
true
179 (Relative_path.Set.mem
(DS.error_sources
ds) a_path)
180 "error_sources should contain A";
182 Asserter.Bool_asserter.assert_equals
true
183 (Relative_path.Set.mem
(DS.error_sources
ds) b_path)
184 "error_sources should contain B";
188 "test_update", test_update;
189 "test_error_sources", test_error_sources;
193 Relative_path.(set_path_prefix Root
(Path.make
"/"));
194 Unit_test.run_all
tests