@@ -55,11 +55,10 @@ TEST(test_lsp_workspace_configuration, empty_config_request) {
5555}
5656
5757TEST (test_lsp_workspace_configuration, config_request_with_three_items) {
58- std::string items[3 ];
5958 lsp_workspace_configuration config;
60- config.add_item (u8" first" sv, &items[ 0 ] );
61- config.add_item (u8" second" sv, &items[ 1 ] );
62- config.add_item (u8" third" sv, &items[ 2 ] );
59+ config.add_item (u8" first" sv, [](std::string_view) {} );
60+ config.add_item (u8" second" sv, [](std::string_view) {} );
61+ config.add_item (u8" third" sv, [](std::string_view) {} );
6362
6463 byte_buffer request_json;
6564 config.build_request (77 , request_json);
@@ -85,9 +84,15 @@ TEST(test_lsp_workspace_configuration, empty_config_response) {
8584TEST (test_lsp_workspace_configuration, config_response_with_strings) {
8685 std::string items[3 ];
8786 lsp_workspace_configuration config;
88- config.add_item (u8" first" sv, &items[0 ]);
89- config.add_item (u8" second" sv, &items[1 ]);
90- config.add_item (u8" third" sv, &items[2 ]);
87+ config.add_item (u8" first" sv, [&items](std::string_view new_value) {
88+ items[0 ] = new_value;
89+ });
90+ config.add_item (u8" second" sv, [&items](std::string_view new_value) {
91+ items[1 ] = new_value;
92+ });
93+ config.add_item (u8" third" sv, [&items](std::string_view new_value) {
94+ items[2 ] = new_value;
95+ });
9196
9297 easy_simdjson_parser result (
9398 R"( ["firstval", "secondval", "thirdval"])" _padded);
@@ -102,43 +107,56 @@ TEST(test_lsp_workspace_configuration, config_response_with_strings) {
102107
103108TEST (test_lsp_workspace_configuration,
104109 empty_config_response_with_added_items_fails) {
105- std::string myitem = " originalvalue" ;
106110 lsp_workspace_configuration config;
107- config.add_item (u8" myitem" sv, &myitem);
111+ bool myitem_callback_called = false ;
112+ config.add_item (u8" myitem" sv, [&myitem_callback_called](
113+ std::string_view new_value) {
114+ myitem_callback_called = true ;
115+ ADD_FAILURE () << " myitem callback should not have been called; new_value="
116+ << new_value;
117+ });
108118
109119 easy_simdjson_parser result (" []" _padded);
110120 ASSERT_EQ (result.error , ::simdjson::SUCCESS);
111121 bool ok = config.process_response (result.value );
112122 ASSERT_FALSE (ok);
113123
114- EXPECT_EQ (myitem, " originalvalue " ) << " item should not change value " ;
124+ EXPECT_FALSE (myitem_callback_called) ;
115125}
116126
117127TEST (test_lsp_workspace_configuration,
118- more_values_than_config_fails_but_sets_values_anyway) {
119- std::string myitem;
128+ more_values_than_config_fails_but_calls_callback_anyway) {
120129 lsp_workspace_configuration config;
121- config.add_item (u8" myitem" sv, &myitem);
130+ bool myitem_callback_called = false ;
131+ config.add_item (u8" myitem" sv,
132+ [&myitem_callback_called](std::string_view new_value) {
133+ myitem_callback_called = true ;
134+ EXPECT_EQ (new_value, " val" );
135+ });
122136
123137 easy_simdjson_parser result (R"( ["val", "otherval"])" _padded);
124138 ASSERT_EQ (result.error , ::simdjson::SUCCESS);
125139 bool ok = config.process_response (result.value );
126140 ASSERT_FALSE (ok);
127141
128- EXPECT_EQ (myitem, " val " );
142+ EXPECT_TRUE (myitem_callback_called );
129143}
130144
131- TEST (test_lsp_workspace_configuration, null_clears_string) {
132- std::string myitem = " hello" ;
145+ TEST (test_lsp_workspace_configuration, null_is_coerced_to_empty_string) {
133146 lsp_workspace_configuration config;
134- config.add_item (u8" myitem" sv, &myitem);
147+ bool myitem_callback_called = false ;
148+ config.add_item (u8" myitem" sv,
149+ [&myitem_callback_called](std::string_view new_value) {
150+ myitem_callback_called = true ;
151+ EXPECT_EQ (new_value, " " );
152+ });
135153
136154 easy_simdjson_parser result (R"( [null])" _padded);
137155 ASSERT_EQ (result.error , ::simdjson::SUCCESS);
138156 bool ok = config.process_response (result.value );
139157 EXPECT_TRUE (ok);
140158
141- EXPECT_EQ (myitem, " " );
159+ EXPECT_TRUE (myitem_callback_called );
142160}
143161
144162TEST (test_lsp_workspace_configuration, non_array_config_response_fails) {
0 commit comments