forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MooseServerTest.C
1472 lines (1120 loc) · 57.7 KB
/
MooseServerTest.C
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "gtest_include.h"
#include "MooseServer.h"
#include "MooseApp.h"
#include "Moose.h"
#include "AppFactory.h"
#include "waspcore/Object.h"
#include "wasplsp/LSP.h"
#include "wasplsp/SymbolIterator.h"
#include <string>
#include <sstream>
#include <memory>
#include <vector>
class MooseServerTest : public ::testing::Test
{
protected:
// traverse diagnostics and make formatted list for easy testing and viewing
void format_diagnostics(const wasp::DataArray & diagnostics_array,
std::ostringstream & diagnostics_stream) const
{
std::size_t diagnostics_size = diagnostics_array.size();
for (std::size_t i = 0; i < diagnostics_size; i++)
{
std::stringstream diagnostic_errors;
int diagnostic_start_line;
int diagnostic_start_character;
int diagnostic_end_line;
int diagnostic_end_character;
int diagnostic_severity;
std::string diagnostic_code;
std::string diagnostic_source;
std::string diagnostic_message;
EXPECT_TRUE(wasp::lsp::dissectDiagnosticObject(*(diagnostics_array.at(i).to_object()),
diagnostic_errors,
diagnostic_start_line,
diagnostic_start_character,
diagnostic_end_line,
diagnostic_end_character,
diagnostic_severity,
diagnostic_code,
diagnostic_source,
diagnostic_message));
diagnostics_stream << "line:" << diagnostic_start_line
<< " column:" << diagnostic_start_character << " - " << diagnostic_message
<< "\n";
}
}
// traverse symbolpaths and make formatted list for easy testing and viewing
void format_symbolpaths(const wasp::DataObject & symbols_response,
std::ostringstream & paths_stream) const
{
EXPECT_TRUE(wasp::lsp::verifySymbolsResponse(symbols_response));
wasp::lsp::SymbolIterator si(std::make_shared<wasp::DataObject>(symbols_response));
for (std::vector<int> indices{0}; indices.back() < (int)si.getChildSize(); indices.back()++)
{
si.moveToChildAt(indices.back());
indices.push_back(-1);
paths_stream << si.getPath() << "\n";
if (si.getChildSize() == 0)
{
while (indices.back() + 1 == (int)si.getChildSize() && si.moveToParent())
{
indices.pop_back();
}
}
}
}
// traverse completions and make formatted list for easy testing and viewing
void format_completions(const wasp::DataArray & completions_array,
std::ostringstream & completions_stream) const
{
struct CompletionInfo
{
std::string label;
std::string new_text;
std::string documentation;
int start_line;
int start_character;
int end_line;
int end_character;
};
std::vector<CompletionInfo> completions;
std::size_t max_label = 0;
std::size_t max_new_text = 0;
std::size_t max_doc = 0;
std::size_t completions_size = completions_array.size();
for (std::size_t i = 0; i < completions_size; i++)
{
std::stringstream completion_errors;
std::string completion_label;
int completion_start_line;
int completion_start_character;
int completion_end_line;
int completion_end_character;
std::string completion_new_text;
int completion_kind;
std::string completion_detail;
std::string completion_documentation;
bool completion_deprecated;
bool completion_preselect;
EXPECT_TRUE(wasp::lsp::dissectCompletionObject(*(completions_array.at(i).to_object()),
completion_errors,
completion_label,
completion_start_line,
completion_start_character,
completion_end_line,
completion_end_character,
completion_new_text,
completion_kind,
completion_detail,
completion_documentation,
completion_deprecated,
completion_preselect));
// truncate long descriptions and escape text newlines for easy viewing
if (completion_documentation.length() > 50)
{
completion_documentation.resize(47);
completion_documentation += "...";
}
MooseUtils::escape(completion_new_text);
if (completion_label.size() > max_label)
max_label = completion_label.size();
if (completion_new_text.size() > max_new_text)
max_new_text = completion_new_text.size();
if (completion_documentation.size() > max_doc)
max_doc = completion_documentation.size();
completions.push_back({completion_label,
completion_new_text,
completion_documentation,
completion_start_line,
completion_start_character,
completion_end_line,
completion_end_character});
}
for (const auto & completion : completions)
{
completions_stream << "label: " << std::setw(max_label) << std::left << completion.label
<< " text: " << std::setw(max_new_text) << std::left << completion.new_text
<< " desc: " << std::setw(max_doc) << std::left << completion.documentation
<< " pos: [" << completion.start_line << "." << completion.start_character
<< "]-[" << completion.end_line << "." << completion.end_character << "]"
<< "\n";
}
}
// create moose_unit_app and moose_server to persist for reuse between tests
static void SetUpTestCase()
{
moose_unit_app = AppFactory::createAppShared("MooseUnitApp", 0, nullptr);
moose_server = std::make_unique<MooseServer>(*moose_unit_app);
}
// delete moose_unit_app and moose_server after all test runs have completed
static void TearDownTestCase()
{
moose_unit_app.reset();
moose_server.reset();
}
// statically declare moose_unit_app and moose_server for reuse across tests
static std::shared_ptr<MooseApp> moose_unit_app;
static std::unique_ptr<MooseServer> moose_server;
};
// define moose_unit_app and moose_server that are declared as static in class
std::shared_ptr<MooseApp> MooseServerTest::moose_unit_app;
std::unique_ptr<MooseServer> MooseServerTest::moose_server;
TEST_F(MooseServerTest, InitializeAndInitialized)
{
// initialize test parameters
int request_id = 1;
int process_id = -1;
std::string root_path = "";
wasp::DataObject client_capabilities;
// build initialize request with the test parameters
wasp::DataObject initialize_request;
std::stringstream initialize_errors;
EXPECT_TRUE(wasp::lsp::buildInitializeRequest(initialize_request,
initialize_errors,
request_id,
process_id,
root_path,
client_capabilities));
EXPECT_TRUE(initialize_errors.str().empty());
// handle the built initialize request with the moose_server
wasp::DataObject initialize_response;
EXPECT_TRUE(moose_server->handleInitializeRequest(initialize_request, initialize_response));
EXPECT_TRUE(moose_server->getErrors().empty());
// check the dissected values of the moose_server initialize response
std::stringstream response_errors;
int response_id;
wasp::DataObject server_capabilities;
EXPECT_TRUE(wasp::lsp::dissectInitializeResponse(
initialize_response, response_errors, response_id, server_capabilities));
EXPECT_TRUE(response_errors.str().empty());
EXPECT_EQ(request_id, response_id);
EXPECT_TRUE(server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_open_close].is_bool());
EXPECT_TRUE(server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_open_close].to_bool());
EXPECT_TRUE(server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_change].is_int());
EXPECT_EQ(1, server_capabilities[wasp::lsp::m_text_doc_sync][wasp::lsp::m_change].to_int());
// build initialized notification which takes no extra parameters
wasp::DataObject initialized_notification;
std::stringstream initialized_errors;
EXPECT_TRUE(
wasp::lsp::buildInitializedNotification(initialized_notification, initialized_errors));
EXPECT_TRUE(initialized_errors.str().empty());
// handle the built initialized notification with the moose_server
EXPECT_TRUE(moose_server->handleInitializedNotification(initialized_notification));
EXPECT_TRUE(moose_server->getErrors().empty());
}
TEST_F(MooseServerTest, DocumentOpenAndDiagnostics)
{
// didopen test parameters - note input has error with variable u twice
std::string document_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
std::string document_language_id = "test_language_id_string";
int document_version = 1;
std::string document_text_open = R"INPUT(
[Mesh]
type = GeneratedMesh
dim = 1
[]
[Variables]
[u]
order = THIRD
family = MONOMIAL
[]
[u]
order = FOURTH
family = MONOMIAL
[]
[]
[BCs]
[all]
type = VacuumBC
boundary = 'left right'
variable = u
[]
[]
[Executioner]
type = Transient
[]
[Problem]
solve = false
[]
)INPUT";
// build didopen notification with the test parameters
wasp::DataObject didopen_notification;
std::stringstream didopen_errors;
EXPECT_TRUE(wasp::lsp::buildDidOpenNotification(didopen_notification,
didopen_errors,
document_uri,
document_language_id,
document_version,
document_text_open));
EXPECT_TRUE(didopen_errors.str().empty());
// force enabling performance logs to check reset by moose_server after call
Moose::perf_log.enable_logging();
// handle the built didopen notification with the moose_server
wasp::DataObject diagnostics_notification;
EXPECT_TRUE(
moose_server->handleDidOpenNotification(didopen_notification, diagnostics_notification));
EXPECT_TRUE(moose_server->getErrors().empty());
// check behavior of performance logs was reset properly by the moose_server
EXPECT_TRUE(Moose::perf_log.logging_enabled());
// check set of messages built from the moose_server diagnostics notification
std::stringstream diagnostics_errors;
std::string response_uri;
wasp::DataArray diagnostics_array;
EXPECT_TRUE(wasp::lsp::dissectPublishDiagnosticsNotification(
diagnostics_notification, diagnostics_errors, response_uri, diagnostics_array));
EXPECT_TRUE(diagnostics_errors.str().empty());
EXPECT_EQ(document_uri, response_uri);
EXPECT_EQ(4u, diagnostics_array.size());
std::ostringstream diagnostics_actual;
format_diagnostics(diagnostics_array, diagnostics_actual);
// expected diagnostics with zero-based lines and columns - variable u twice
std::string diagnostics_expect = R"INPUT(
line:7 column:4 - parameter 'Variables/u/order' supplied multiple times
line:11 column:4 - parameter 'Variables/u/order' supplied multiple times
line:8 column:4 - parameter 'Variables/u/family' supplied multiple times
line:12 column:4 - parameter 'Variables/u/family' supplied multiple times
)INPUT";
EXPECT_EQ(diagnostics_expect, "\n" + diagnostics_actual.str());
}
TEST_F(MooseServerTest, DocumentOpenAndSymbols)
{
// symbols test parameters
int request_id = 2;
std::string document_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
// build symbols request with the test parameters
wasp::DataObject symbols_request;
std::stringstream symbols_errors;
EXPECT_TRUE(
wasp::lsp::buildSymbolsRequest(symbols_request, symbols_errors, request_id, document_uri));
EXPECT_TRUE(symbols_errors.str().empty());
// handle the built symbols request with the moose_server
wasp::DataObject symbols_response;
EXPECT_TRUE(moose_server->handleSymbolsRequest(symbols_request, symbols_response));
EXPECT_TRUE(moose_server->getErrors().empty());
// check set of paths built from the moose_server symbols response
std::ostringstream paths_actual;
format_symbolpaths(symbols_response, paths_actual);
// expected paths with zero-based lines and columns - note variable u twice
std::string paths_expect = R"INPUT(
/Mesh (1:0)
/Mesh/[ (1:0)
/Mesh/decl (1:1)
/Mesh/] (1:5)
/Mesh/type (2:2)
/Mesh/type/decl (2:2)
/Mesh/type/= (2:7)
/Mesh/type/value (2:9)
/Mesh/dim (3:2)
/Mesh/dim/decl (3:2)
/Mesh/dim/= (3:6)
/Mesh/dim/value (3:8)
/Mesh/term (4:0)
/Variables (5:0)
/Variables/[ (5:0)
/Variables/decl (5:1)
/Variables/] (5:10)
/Variables/u (6:2)
/Variables/u/[ (6:2)
/Variables/u/decl (6:3)
/Variables/u/] (6:4)
/Variables/u/order (7:4)
/Variables/u/order/decl (7:4)
/Variables/u/order/= (7:10)
/Variables/u/order/value (7:12)
/Variables/u/family (8:4)
/Variables/u/family/decl (8:4)
/Variables/u/family/= (8:11)
/Variables/u/family/value (8:13)
/Variables/u/term (9:2)
/Variables/u (10:2)
/Variables/u/[ (10:2)
/Variables/u/decl (10:3)
/Variables/u/] (10:4)
/Variables/u/order (11:4)
/Variables/u/order/decl (11:4)
/Variables/u/order/= (11:10)
/Variables/u/order/value (11:12)
/Variables/u/family (12:4)
/Variables/u/family/decl (12:4)
/Variables/u/family/= (12:11)
/Variables/u/family/value (12:13)
/Variables/u/term (13:2)
/Variables/term (14:0)
/BCs (15:0)
/BCs/[ (15:0)
/BCs/decl (15:1)
/BCs/] (15:4)
/BCs/all (16:2)
/BCs/all/[ (16:2)
/BCs/all/decl (16:3)
/BCs/all/] (16:6)
/BCs/all/type (17:4)
/BCs/all/type/decl (17:4)
/BCs/all/type/= (17:9)
/BCs/all/type/value (17:11)
/BCs/all/boundary (18:4)
/BCs/all/boundary/decl (18:4)
/BCs/all/boundary/= (18:13)
/BCs/all/boundary/' (18:15)
/BCs/all/boundary/value (18:16)
/BCs/all/boundary/value (18:21)
/BCs/all/boundary/' (18:26)
/BCs/all/variable (19:4)
/BCs/all/variable/decl (19:4)
/BCs/all/variable/= (19:13)
/BCs/all/variable/value (19:15)
/BCs/all/term (20:2)
/BCs/term (21:0)
/Executioner (22:0)
/Executioner/[ (22:0)
/Executioner/decl (22:1)
/Executioner/] (22:12)
/Executioner/type (23:2)
/Executioner/type/decl (23:2)
/Executioner/type/= (23:7)
/Executioner/type/value (23:9)
/Executioner/term (24:0)
/Problem (25:0)
/Problem/[ (25:0)
/Problem/decl (25:1)
/Problem/] (25:8)
/Problem/solve (26:2)
/Problem/solve/decl (26:2)
/Problem/solve/= (26:8)
/Problem/solve/value (26:10)
/Problem/term (27:0)
)INPUT";
EXPECT_EQ(paths_expect, "\n" + paths_actual.str());
}
TEST_F(MooseServerTest, DocumentChangeAndDiagnostics)
{
// didchange test parameters - note input has error with bad bcs boundary
std::string document_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
int document_version = 2;
int start_line = -1;
int start_character = -1;
int end_line = -1;
int end_character = -1;
int range_length = -1;
std::string document_text_change = R"INPUT(
[Mesh]
type = GeneratedMesh
dim = 1
[]
[Variables]
[u]
order = THIRD
family = MONOMIAL
[]
[v]
order = FOURTH
family = MONOMIAL
[]
[]
[BCs]
[all]
type = VacuumBC
boundary = 'left right top bottom'
variable = u
[]
[]
[Executioner]
type = Transient
[]
[Problem]
solve = false
[]
)INPUT";
// build didchange notification with the test parameters
wasp::DataObject didchange_notification;
std::stringstream didchange_errors;
EXPECT_TRUE(wasp::lsp::buildDidChangeNotification(didchange_notification,
didchange_errors,
document_uri,
document_version,
start_line,
start_character,
end_line,
end_character,
range_length,
document_text_change));
EXPECT_TRUE(didchange_errors.str().empty());
// force stopping performance logs to check reset by moose_server after call
Moose::perf_log.disable_logging();
// handle the built didchange notification with the moose_server
wasp::DataObject diagnostics_notification;
EXPECT_TRUE(
moose_server->handleDidChangeNotification(didchange_notification, diagnostics_notification));
EXPECT_TRUE(moose_server->getErrors().empty());
// check behavior of performance logs was reset properly by the moose_server
EXPECT_FALSE(Moose::perf_log.logging_enabled());
// check set of messages built from the moose_server diagnostics notification
std::stringstream diagnostics_errors;
std::string response_uri;
wasp::DataArray diagnostics_array;
EXPECT_TRUE(wasp::lsp::dissectPublishDiagnosticsNotification(
diagnostics_notification, diagnostics_errors, response_uri, diagnostics_array));
EXPECT_TRUE(diagnostics_errors.str().empty());
EXPECT_EQ(document_uri, response_uri);
EXPECT_EQ(7u, diagnostics_array.size());
std::ostringstream diagnostics_actual;
format_diagnostics(diagnostics_array, diagnostics_actual);
// expected diagnostics with zero-based lines and columns - bad bcs boundary
std::string diagnostics_expect = R"INPUT(
line:18 column:0 - (BCs/all/boundary):
line:18 column:0 - the following side sets (ids) do not exist on the mesh: top (2), bottom (3)
line:18 column:0 - MOOSE distinguishes between "node sets" and "side sets" depending on whether
line:18 column:0 - you are using "Nodal" or "Integrated" BCs respectively. Node sets corresponding
line:18 column:0 - to your side sets are constructed for you by default.
line:18 column:0 - Try setting "Mesh/construct_side_list_from_node_list=true" if you see this error.
line:18 column:0 - Note: If you are running with adaptivity you should prefer using side sets.
)INPUT";
EXPECT_EQ(diagnostics_expect, "\n" + diagnostics_actual.str());
}
TEST_F(MooseServerTest, DocumentChangeAndSymbols)
{
// symbols test parameters
int request_id = 3;
std::string document_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
// build symbols request with the test parameters
wasp::DataObject symbols_request;
std::stringstream symbols_errors;
EXPECT_TRUE(
wasp::lsp::buildSymbolsRequest(symbols_request, symbols_errors, request_id, document_uri));
EXPECT_TRUE(symbols_errors.str().empty());
// handle the built symbols request with the moose_server
wasp::DataObject symbols_response;
EXPECT_TRUE(moose_server->handleSymbolsRequest(symbols_request, symbols_response));
EXPECT_TRUE(moose_server->getErrors().empty());
// check set of paths built from the moose_server symbols response
std::ostringstream paths_actual;
format_symbolpaths(symbols_response, paths_actual);
// expected paths with zero-based lines and columns - note bad bcs boundary
std::string paths_expect = R"INPUT(
/Mesh (1:0)
/Mesh/[ (1:0)
/Mesh/decl (1:1)
/Mesh/] (1:5)
/Mesh/type (2:2)
/Mesh/type/decl (2:2)
/Mesh/type/= (2:7)
/Mesh/type/value (2:9)
/Mesh/dim (3:2)
/Mesh/dim/decl (3:2)
/Mesh/dim/= (3:6)
/Mesh/dim/value (3:8)
/Mesh/term (4:0)
/Variables (5:0)
/Variables/[ (5:0)
/Variables/decl (5:1)
/Variables/] (5:10)
/Variables/u (6:2)
/Variables/u/[ (6:2)
/Variables/u/decl (6:3)
/Variables/u/] (6:4)
/Variables/u/order (7:4)
/Variables/u/order/decl (7:4)
/Variables/u/order/= (7:10)
/Variables/u/order/value (7:12)
/Variables/u/family (8:4)
/Variables/u/family/decl (8:4)
/Variables/u/family/= (8:11)
/Variables/u/family/value (8:13)
/Variables/u/term (9:2)
/Variables/v (10:2)
/Variables/v/[ (10:2)
/Variables/v/decl (10:3)
/Variables/v/] (10:4)
/Variables/v/order (11:4)
/Variables/v/order/decl (11:4)
/Variables/v/order/= (11:10)
/Variables/v/order/value (11:12)
/Variables/v/family (12:4)
/Variables/v/family/decl (12:4)
/Variables/v/family/= (12:11)
/Variables/v/family/value (12:13)
/Variables/v/term (13:2)
/Variables/term (14:0)
/BCs (15:0)
/BCs/[ (15:0)
/BCs/decl (15:1)
/BCs/] (15:4)
/BCs/all (16:2)
/BCs/all/[ (16:2)
/BCs/all/decl (16:3)
/BCs/all/] (16:6)
/BCs/all/type (17:4)
/BCs/all/type/decl (17:4)
/BCs/all/type/= (17:9)
/BCs/all/type/value (17:11)
/BCs/all/boundary (18:4)
/BCs/all/boundary/decl (18:4)
/BCs/all/boundary/= (18:13)
/BCs/all/boundary/' (18:15)
/BCs/all/boundary/value (18:16)
/BCs/all/boundary/value (18:21)
/BCs/all/boundary/value (18:27)
/BCs/all/boundary/value (18:31)
/BCs/all/boundary/' (18:37)
/BCs/all/variable (19:4)
/BCs/all/variable/decl (19:4)
/BCs/all/variable/= (19:13)
/BCs/all/variable/value (19:15)
/BCs/all/term (20:2)
/BCs/term (21:0)
/Executioner (22:0)
/Executioner/[ (22:0)
/Executioner/decl (22:1)
/Executioner/] (22:12)
/Executioner/type (23:2)
/Executioner/type/decl (23:2)
/Executioner/type/= (23:7)
/Executioner/type/value (23:9)
/Executioner/term (24:0)
/Problem (25:0)
/Problem/[ (25:0)
/Problem/decl (25:1)
/Problem/] (25:8)
/Problem/solve (26:2)
/Problem/solve/decl (26:2)
/Problem/solve/= (26:8)
/Problem/solve/value (26:10)
/Problem/term (27:0)
)INPUT";
EXPECT_EQ(paths_expect, "\n" + paths_actual.str());
}
TEST_F(MooseServerTest, CompletionMeshDefaultedType)
{
// didchange test parameters - update input to set up autocomplete scenarios
std::string doc_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
int doc_version = 3;
std::string doc_text_change = R"INPUT(
[Mesh]
dim = 2
patch_update_strategy = AUTO
displacements = 'disp_x disp_y'
parallel_type = REPLICATED
[]
[Variables]
active = '__all__'
[u]
[]
[v]
[]
[]
[AuxVariables]
[disp_x]
[]
[disp_y]
[]
[]
[BCs]
[all]
type = VacuumBC
boundary = 'left right'
variable = u
displacements = 'disp_x'
[]
[]
[Executioner]
type = Transient
[]
[Problem]
solve = false
[]
[UserObjects]
[term_uo]
type = Terminator
expression = 'expr'
error_level = NONE
[]
[]
)INPUT";
// build didchange notification and handle it with the moose_server
wasp::DataObject didchange_notification;
std::stringstream errors;
wasp::DataObject diagnostics_notification;
EXPECT_TRUE(wasp::lsp::buildDidChangeNotification(
didchange_notification, errors, doc_uri, doc_version, -1, -1, -1, -1, -1, doc_text_change));
EXPECT_TRUE(
moose_server->handleDidChangeNotification(didchange_notification, diagnostics_notification));
// completion test parameters - in Mesh default FileMesh already with params
int request_id = 4;
int line = 6;
int character = 0;
// build completion request with the test parameters
wasp::DataObject completion_request;
std::stringstream completion_errors;
EXPECT_TRUE(wasp::lsp::buildCompletionRequest(
completion_request, completion_errors, request_id, doc_uri, line, character));
EXPECT_TRUE(completion_errors.str().empty());
// handle the built completion request with the moose_server
wasp::DataObject completion_response;
EXPECT_TRUE(moose_server->handleCompletionRequest(completion_request, completion_response));
EXPECT_TRUE(moose_server->getErrors().empty());
// check the dissected values of the moose_server completion response
std::stringstream response_errors;
int response_id;
bool response_is_incomplete;
wasp::DataArray completions_array;
EXPECT_TRUE(wasp::lsp::dissectCompletionResponse(completion_response,
response_errors,
response_id,
response_is_incomplete,
completions_array));
EXPECT_TRUE(response_errors.str().empty());
EXPECT_EQ(request_id, response_id);
EXPECT_EQ(47u, completions_array.size());
std::ostringstream completions_actual;
format_completions(completions_array, completions_actual);
// expected completions with zero-based lines and columns
std::string completions_expect = R"INPUT(
label: active text: active = '__all__' desc: If specified only the blocks named w... pos: [6.0]-[6.0]
label: add_subdomain_ids text: add_subdomain_ids = '0' desc: The listed subdomains will be assume... pos: [6.0]-[6.0]
label: allow_renumbering text: allow_renumbering = true desc: If allow_renumbering=false, node and... pos: [6.0]-[6.0]
label: alpha_rotation text: alpha_rotation = 0.0 desc: The number of degrees that the domai... pos: [6.0]-[6.0]
label: beta_rotation text: beta_rotation = 0.0 desc: The number of degrees that the domai... pos: [6.0]-[6.0]
label: block_id text: block_id = '0' desc: IDs of the block id/name pairs pos: [6.0]-[6.0]
label: block_name text: block_name = 'value' desc: Names of the block id/name pairs (mu... pos: [6.0]-[6.0]
label: boundary_id text: boundary_id = '0' desc: IDs of the boundary id/name pairs pos: [6.0]-[6.0]
label: boundary_name text: boundary_name = 'value' desc: Names of the boundary id/name pairs ... pos: [6.0]-[6.0]
label: build_all_side_lowerd_mesh text: build_all_side_lowerd_mesh = false desc: True to build the lower-dimensional ... pos: [6.0]-[6.0]
label: centroid_partitioner_direction text: centroid_partitioner_direction = RADIAL desc: Specifies the sort direction if usin... pos: [6.0]-[6.0]
label: clear_spline_nodes text: clear_spline_nodes = false desc: If clear_spline_nodes=true, IsoGeome... pos: [6.0]-[6.0]
label: construct_node_list_from_side_list text: construct_node_list_from_side_list = true desc: Whether or not to generate nodesets ... pos: [6.0]-[6.0]
label: construct_side_list_from_node_list text: construct_side_list_from_node_list = false desc: If true, construct side lists from t... pos: [6.0]-[6.0]
label: control_tags text: control_tags = 'value' desc: Adds user-defined labels for accessi... pos: [6.0]-[6.0]
label: coord_block text: coord_block = 'value' desc: Block IDs for the coordinate systems... pos: [6.0]-[6.0]
label: coord_type text: coord_type = 'XYZ' desc: Type of the coordinate system per bl... pos: [6.0]-[6.0]
label: enable text: enable = true desc: Set the enabled status of the MooseO... pos: [6.0]-[6.0]
label: file text: file = value desc: (REQUIRED) The name of the mesh file to read pos: [6.0]-[6.0]
label: gamma_rotation text: gamma_rotation = 0.0 desc: The number of degrees that the domai... pos: [6.0]-[6.0]
label: ghosted_boundaries text: ghosted_boundaries = 'value' desc: Boundaries to be ghosted if using Ne... pos: [6.0]-[6.0]
label: ghosted_boundaries_inflation text: ghosted_boundaries_inflation = '0.0' desc: If you are using ghosted boundaries ... pos: [6.0]-[6.0]
label: ghosting_patch_size text: ghosting_patch_size = 0 desc: The number of nearest neighbors cons... pos: [6.0]-[6.0]
label: inactive text: inactive = 'value' desc: If specified blocks matching these i... pos: [6.0]-[6.0]
label: include_local_in_ghosting text: include_local_in_ghosting = false desc: Boolean used to toggle on the inclus... pos: [6.0]-[6.0]
label: length_unit text: length_unit = value desc: How much distance one mesh length un... pos: [6.0]-[6.0]
label: max_leaf_size text: max_leaf_size = 10 desc: The maximum number of points in each... pos: [6.0]-[6.0]
label: nemesis text: nemesis = false desc: If nemesis=true and file=foo.e, actu... pos: [6.0]-[6.0]
label: output_ghosting text: output_ghosting = false desc: Boolean to turn on ghosting auxiliar... pos: [6.0]-[6.0]
label: partitioner text: partitioner = default desc: Specifies a mesh partitioner to use ... pos: [6.0]-[6.0]
label: patch_size text: patch_size = 40 desc: The number of nodes to consider in t... pos: [6.0]-[6.0]
label: rz_coord_axis text: rz_coord_axis = Y desc: The rotation axis (X | Y) for axisym... pos: [6.0]-[6.0]
label: rz_coord_blocks text: rz_coord_blocks = 'value' desc: Blocks using general axisymmetric co... pos: [6.0]-[6.0]
label: rz_coord_directions text: rz_coord_directions = '0.0' desc: Axis directions for each block in 'r... pos: [6.0]-[6.0]
label: rz_coord_origins text: rz_coord_origins = '0.0' desc: Axis origin points for each block in... pos: [6.0]-[6.0]
label: second_order text: second_order = false desc: Converts a first order mesh to a sec... pos: [6.0]-[6.0]
label: skip_deletion_repartition_after_refine text: skip_deletion_repartition_after_refine = false desc: If the flag is true, uniform refinem... pos: [6.0]-[6.0]
label: skip_partitioning text: skip_partitioning = false desc: If true the mesh won't be partitione... pos: [6.0]-[6.0]
label: skip_refine_when_use_split text: skip_refine_when_use_split = true desc: True to skip uniform refinements whe... pos: [6.0]-[6.0]
label: split_file text: split_file = value desc: Optional name of split mesh file(s) ... pos: [6.0]-[6.0]
label: type text: type = FileMesh desc: A string representing the Moose Obje... pos: [6.0]-[6.0]
label: uniform_refine text: uniform_refine = 0 desc: Specify the level of uniform refinem... pos: [6.0]-[6.0]
label: up_direction text: up_direction = X desc: Specify what axis corresponds to the... pos: [6.0]-[6.0]
label: use_displaced_mesh text: use_displaced_mesh = true desc: Create the displaced mesh if the 'di... pos: [6.0]-[6.0]
label: use_split text: use_split = false desc: Use split distributed mesh files; is... pos: [6.0]-[6.0]
label: * text: [block_name]\n \n[] desc: custom user named block pos: [6.0]-[6.0]
label: Partitioner text: [Partitioner]\n \n[] desc: application named block pos: [6.0]-[6.0]
)INPUT";
EXPECT_EQ(completions_expect, "\n" + completions_actual.str());
}
TEST_F(MooseServerTest, CompletionDocumentRootLevel)
{
// completion test parameters - at document root level outside of all blocks
int request_id = 4;
std::string doc_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
int line = 42;
int character = 0;
// build completion request with the test parameters
wasp::DataObject completion_request;
std::stringstream completion_errors;
EXPECT_TRUE(wasp::lsp::buildCompletionRequest(
completion_request, completion_errors, request_id, doc_uri, line, character));
EXPECT_TRUE(completion_errors.str().empty());
// handle the built completion request with the moose_server
wasp::DataObject completion_response;
EXPECT_TRUE(moose_server->handleCompletionRequest(completion_request, completion_response));
EXPECT_TRUE(moose_server->getErrors().empty());
// check the dissected values of the moose_server completion response
std::stringstream response_errors;
int response_id;
bool response_is_incomplete;
wasp::DataArray completions_array;
EXPECT_TRUE(wasp::lsp::dissectCompletionResponse(completion_response,
response_errors,
response_id,
response_is_incomplete,
completions_array));
EXPECT_TRUE(response_errors.str().empty());
EXPECT_EQ(request_id, response_id);
EXPECT_EQ(47u, completions_array.size());
std::ostringstream completions_actual;
format_completions(completions_array, completions_actual);
// expected completions with zero-based lines and columns
std::string completions_expect = R"INPUT(
label: active text: active = '__all__' desc: If specified only the blocks named w... pos: [42.0]-[42.0]
label: inactive text: inactive = 'value' desc: If specified blocks matching these i... pos: [42.0]-[42.0]
label: Adaptivity text: [Adaptivity]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: AuxKernels text: [AuxKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: AuxScalarKernels text: [AuxScalarKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: AuxVariables text: [AuxVariables]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: BCs text: [BCs]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Bounds text: [Bounds]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Constraints text: [Constraints]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Controls text: [Controls]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: DGKernels text: [DGKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Dampers text: [Dampers]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Debug text: [Debug]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: DeprecatedBlock text: [DeprecatedBlock]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: DiracKernels text: [DiracKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Distributions text: [Distributions]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Executioner text: [Executioner]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Executors text: [Executors]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: FVBCs text: [FVBCs]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: FVICs text: [FVICs]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: FVInterfaceKernels text: [FVInterfaceKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: FVKernels text: [FVKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Functions text: [Functions]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: FunctorMaterials text: [FunctorMaterials]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: GlobalParams text: [GlobalParams]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: ICs text: [ICs]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: InterfaceKernels text: [InterfaceKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Kernels text: [Kernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Materials text: [Materials]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Mesh text: [Mesh]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: MultiApps text: [MultiApps]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: NodalKernels text: [NodalKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: NodalNormals text: [NodalNormals]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Outputs text: [Outputs]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Positions text: [Positions]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Postprocessors text: [Postprocessors]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Preconditioning text: [Preconditioning]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Problem text: [Problem]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: ProjectedStatefulMaterialStorage text: [ProjectedStatefulMaterialStorage]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Reporters text: [Reporters]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Samplers text: [Samplers]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: ScalarKernels text: [ScalarKernels]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Times text: [Times]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Transfers text: [Transfers]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: UserObjects text: [UserObjects]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: Variables text: [Variables]\n \n[] desc: application named block pos: [42.0]-[42.0]
label: VectorPostprocessors text: [VectorPostprocessors]\n \n[] desc: application named block pos: [42.0]-[42.0]
)INPUT";
EXPECT_EQ(completions_expect, "\n" + completions_actual.str());
}
TEST_F(MooseServerTest, CompletionValueActiveBlocks)
{
// completion test parameters - on active parameter value in Variables block