forked from googleapis/google-cloud-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doxygen2markdown_test.cc
1247 lines (1055 loc) · 44.3 KB
/
doxygen2markdown_test.cc
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
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "docfx/doxygen2markdown.h"
#include <gmock/gmock.h>
namespace docfx {
namespace {
using ::testing::HasSubstr;
using ::testing::IsEmpty;
using ::testing::Not;
TEST(Doxygen2Markdown, Sect4) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<sect4 id='tested-node'>
<title>This is the title</title>
<para>First paragraph.</para>
<para>Second paragraph.</para>
</sect4>
</doxygen>)xml";
auto constexpr kExpected = R"md(
##### This is the title
First paragraph.
Second paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfSect4(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, Sect3) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<sect3 id='tested-node'>
<title>This is the title</title>
<para>First paragraph.</para>
<para>Second paragraph.</para>
<sect4><title>This is a section4</title><para>Sect4 paragraph.</para></sect4>
</sect3>
</doxygen>)xml";
auto constexpr kExpected = R"md(
#### This is the title
First paragraph.
Second paragraph.
##### This is a section4
Sect4 paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfSect3(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, Sect2) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<sect2 id='tested-node'>
<title>This is the title</title>
<para>First paragraph.</para>
<para>Second paragraph.</para>
<sect3><title>This is a section3</title><para>Sect3 paragraph.</para></sect3>
</sect2>
</doxygen>)xml";
auto constexpr kExpected = R"md(
### This is the title
First paragraph.
Second paragraph.
#### This is a section3
Sect3 paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfSect2(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, Sect1) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<sect1 id='tested-node'>
<title>This is the title</title>
<para>First paragraph.</para>
<para>Second paragraph.</para>
<sect2><title>This is a section2</title><para>Sect2 paragraph.</para></sect2>
</sect1>
</doxygen>)xml";
auto constexpr kExpected = R"md(
## This is the title
First paragraph.
Second paragraph.
### This is a section2
Sect2 paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfSect1(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, DetailedDescription) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<detaileddescription id='tested-node'>
<sect1>
<title>This is the title (1)</title>
<para>First paragraph (1).</para>
<para>Second paragraph (1).</para>
<sect2><title>This is a section2</title><para>Sect2 paragraph.</para></sect2>
</sect1>
<sect1>
<title>This is the title (2)</title>
<para>First paragraph (2).</para>
<para>Second paragraph (2).</para>
</sect1>
</detaileddescription>
</doxygen>)xml";
auto constexpr kExpected = R"md(
## This is the title (1)
First paragraph (1).
Second paragraph (1).
### This is a section2
Sect2 paragraph.
## This is the title (2)
First paragraph (2).
Second paragraph (2).)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfDetailedDescription(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, DetailedDescriptionSkipSect1) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<detaileddescription id='tested-node'>
<sect2>
<title>This is the title (2)</title>
<para>First paragraph (2).</para>
<para>Second paragraph (2).</para>
</sect2>
<sect3>
<title>This is the title (3)</title>
<para>First paragraph (3).</para>
<para>Second paragraph (3).</para>
</sect3>
<sect4>
<title>This is the title (4)</title>
<para>First paragraph (4).</para>
<para>Second paragraph (4).</para>
</sect4>
</detaileddescription>
</doxygen>)xml";
auto constexpr kExpected = R"md(
### This is the title (2)
First paragraph (2).
Second paragraph (2).
#### This is the title (3)
First paragraph (3).
Second paragraph (3).
##### This is the title (4)
First paragraph (4).
Second paragraph (4).)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfDetailedDescription(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, DetailedDescriptionNotSkipped) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<compounddef xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="namespacegoogle_1_1cloud_1_1kms" kind="namespace" language="C++">
<compoundname>google::cloud::kms</compoundname>
<briefdescription>
</briefdescription>
<detaileddescription>
<para><xrefsect id="deprecated_1_deprecated000001"><xreftitle>Deprecated</xreftitle><xrefdescription><para>This namespace exists for backwards compatibility. Use the types defined in <ref refid="namespacegoogle_1_1cloud_1_1kms__v1" kindref="compound">kms_v1</ref> instead of the aliases defined in this namespace.</para>
</xrefdescription></xrefsect></para>
<para><xrefsect id="deprecated_1_deprecated000014"><xreftitle>Deprecated</xreftitle><xrefdescription><para>This namespace exists for backwards compatibility. Use the types defined in <ref refid="namespacegoogle_1_1cloud_1_1kms__v1" kindref="compound">kms_v1</ref> instead of the aliases defined in this namespace.</para>
</xrefdescription></xrefsect></para>
</detaileddescription>
</compounddef>
</doxygen>)xml";
auto constexpr kExpected = R"md(<aside class="deprecated"><b>Deprecated:</b>
This namespace exists for backwards compatibility. Use the types defined in [kms_v1](xref:namespacegoogle_1_1cloud_1_1kms__v1) instead of the aliases defined in this namespace.
</aside>
<aside class="deprecated"><b>Deprecated:</b>
This namespace exists for backwards compatibility. Use the types defined in [kms_v1](xref:namespacegoogle_1_1cloud_1_1kms__v1) instead of the aliases defined in this namespace.
</aside>)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//detaileddescription");
ASSERT_TRUE(selected);
std::ostringstream os;
MarkdownContext ctx;
ctx.paragraph_start = "";
EXPECT_TRUE(AppendIfDetailedDescription(os, ctx, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, DetailedDescriptionSkipped) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<compounddef xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="namespacegoogle_1_1cloud_1_1kms" kind="namespace" language="C++">
<compoundname>google::cloud::kms</compoundname>
<briefdescription>
</briefdescription>
<detaileddescription>
<para><xrefsect id="deprecated_1_deprecated000001"><xreftitle>Deprecated</xreftitle><xrefdescription><para>This namespace exists for backwards compatibility. Use the types defined in <ref refid="namespacegoogle_1_1cloud_1_1kms__v1" kindref="compound">kms_v1</ref> instead of the aliases defined in this namespace.</para>
</xrefdescription></xrefsect></para>
<para><xrefsect id="deprecated_1_deprecated000014"><xreftitle>Deprecated</xreftitle><xrefdescription><para>This namespace exists for backwards compatibility. Use the types defined in <ref refid="namespacegoogle_1_1cloud_1_1kms__v1" kindref="compound">kms_v1</ref> instead of the aliases defined in this namespace.</para>
</xrefdescription></xrefsect></para>
</detaileddescription>
</compounddef>
</doxygen>)xml";
auto constexpr kExpected = R"md(
)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//detaileddescription");
ASSERT_TRUE(selected);
std::ostringstream os;
MarkdownContext ctx;
ctx.paragraph_start = "";
ctx.skip_xrefsect = true;
EXPECT_TRUE(AppendIfDetailedDescription(os, ctx, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, BriefDescription) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<briefdescription id='tested-node'>
<para>This is <bold>not</bold> too detailed.</para>
</briefdescription>
</doxygen>)xml";
auto constexpr kExpected = R"md(
This is **not** too detailed.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfBriefDescription(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, PlainText) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id="plain-text">test-only-value 42</para>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='plain-text']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfPlainText(os, {}, *selected.node().children().begin()));
EXPECT_EQ(os.str(), "test-only-value 42");
}
TEST(Doxygen2Markdown, ULink) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<ulink id="test-node" url="https://example.com/">some text</ulink>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfULink(os, {}, selected.node()));
EXPECT_EQ(os.str(), "[some text](https://example.com/)");
}
TEST(Doxygen2Markdown, Bold) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<bold id="test-node">some text</bold>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfBold(os, {}, selected.node()));
EXPECT_EQ(os.str(), "**some text**");
}
TEST(Doxygen2Markdown, BoldComplex) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<bold id="test-node"><ref refid="group__test" kindref="compound">Some Text</ref></bold>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfBold(os, {}, selected.node()));
EXPECT_EQ(os.str(), "[**Some Text**](xref:group__test)");
}
TEST(Doxygen2Markdown, Strike) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<strike id="test-node">some text</strike>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfStrike(os, {}, selected.node()));
EXPECT_EQ(os.str(), "~some text~");
}
TEST(Doxygen2Markdown, StrikeComplex) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<strike id="test-node"><ref refid="group__test" kindref="compound">Some Text</ref></strike>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfStrike(os, {}, selected.node()));
EXPECT_EQ(os.str(), "[~Some Text~](xref:group__test)");
}
TEST(Doxygen2Markdown, Emphasis) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<emphasis id="test-node">some text</emphasis>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfEmphasis(os, {}, selected.node()));
EXPECT_EQ(os.str(), "*some text*");
}
TEST(Doxygen2Markdown, EmphasisComplex) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<emphasis id="test-node"><ref refid="group__test" kindref="compound">Some Text</ref></emphasis>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfEmphasis(os, {}, selected.node()));
EXPECT_EQ(os.str(), "[*Some Text*](xref:group__test)");
}
TEST(Doxygen2Markdown, ComputerOutput) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<computeroutput id="test-node">int f() { return 42; }</computeroutput>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfComputerOutput(os, {}, selected.node()));
EXPECT_EQ(os.str(), "`int f() { return 42; }`");
}
TEST(Doxygen2Markdown, ComputerOutputComplex) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<computeroutput id="test-node"><ref refid="group__test" kindref="compound">Some Text</ref></computeroutput>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfComputerOutput(os, {}, selected.node()));
EXPECT_EQ(os.str(), "[`Some Text`](xref:group__test)");
}
TEST(Doxygen2Markdown, RefExternal) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<ref id="test-node" external="/workspace/google/cloud/cloud.tag" refid="classgoogle_1_1cloud_1_1StatusOr">Reference Text</ref>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfRef(os, {}, selected.node()));
EXPECT_EQ("[Reference Text](xref:classgoogle_1_1cloud_1_1StatusOr)",
os.str());
}
TEST(Doxygen2Markdown, RefInternal) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<ref id="test-node" refid="some_id">Reference Text</ref>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfRef(os, {}, selected.node()));
EXPECT_EQ("[Reference Text](xref:some_id)", os.str());
}
TEST(Doxygen2Markdown, NDash) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<ndash id="test-node" />
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfNDash(os, {}, selected.node()));
EXPECT_EQ("–", os.str());
}
TEST(Doxygen2Markdown, Paragraph) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>Try using <computeroutput id="test-node">int f() { return 42; }</computeroutput> in your code.</para>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(os.str(), "\n\nTry using `int f() { return 42; }` in your code.");
}
TEST(Doxygen2Markdown, ParagraphWithUnknown) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>Uh oh: <unknown></unknown></para>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
EXPECT_THROW(AppendIfParagraph(os, {}, selected.node()), std::runtime_error);
}
TEST(Doxygen2Markdown, ParagraphWithUnknownOutput) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>Uh oh:
<unknown a1="attr1" a2="attr2">
<child>1</child><child>2</child>
</unknown></para>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
EXPECT_THROW(
try {
AppendIfParagraph(os, {}, selected.node());
} catch (std::runtime_error const& ex) {
EXPECT_THAT(ex.what(), Not(HasSubstr("\n")));
EXPECT_THAT(ex.what(),
HasSubstr("<unknown a1=\"attr1\" a2=\"attr2\">"));
EXPECT_THAT(ex.what(), HasSubstr("<child>1</child>"));
EXPECT_THAT(ex.what(), HasSubstr("<child>2</child>"));
EXPECT_THAT(ex.what(), HasSubstr("</unknown>"));
throw;
},
std::runtime_error);
}
TEST(Doxygen2Markdown, ParagraphSimpleContents) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-000'>The answer is 42.</para>
<para id='test-001'><bold>The answer is 42.</bold></para>
<para id='test-002'><strike>The answer is 42.</strike></para>
<para id='test-003'><emphasis>The answer is 42.</emphasis></para>
<para id='test-004'><computeroutput>The answer is 42.</computeroutput></para>
<para id='test-005'><ref refid="test_id">The answer is 42.</ref></para>
<para id='test-006'><ulink url="https://example.com/">The answer is 42.</ulink></para>
<para id='test-007'><ndash/></para>
<para id='test-008'><ref refid="group__guac" kindref="compound">Authentication Components</ref></para>
<para id='test-009'><ref refid="classgoogle_1_1cloud_1_1Options" kindref="compound">google::cloud::Options</ref></para>
<para id='test-010'><ref refid="classgoogle_1_1cloud_1_1Options" kindref="compound">Options</ref></para>
<para id='test-011'>abc<zwj/>123</para>
<para id='test-012'><ulink url="https://example.com/">google::cloud::Test</ulink></para>
<para id='test-013'><computeroutput>projects/*‍/secrets/*‍/versions/*</computeroutput></para>
</doxygen>)xml";
struct TestCase {
std::string id;
std::string expected;
} const cases[] = {
{"test-000", "\n\nThe answer is 42."},
{"test-001", "\n\n**The answer is 42.**"},
{"test-002", "\n\n~The answer is 42.~"},
{"test-003", "\n\n*The answer is 42.*"},
{"test-004", "\n\n`The answer is 42.`"},
{"test-005", "\n\n[The answer is 42.](xref:test_id)"},
{"test-006", "\n\n[The answer is 42.](https://example.com/)"},
{"test-007", "\n\n–"},
{"test-008", "\n\n[Authentication Components](xref:group__guac)"},
{"test-009",
"\n\n[`google::cloud::Options`](xref:classgoogle_1_1cloud_1_1Options)"},
{"test-010", "\n\n[Options](xref:classgoogle_1_1cloud_1_1Options)"},
{"test-011", "\n\nabc123"},
{"test-012", "\n\n[`google::cloud::Test`](https://example.com/)"},
{"test-013", "\n\n`projects/*/secrets/*/versions/*`"},
};
pugi::xml_document doc;
doc.load_string(kXml);
for (auto const& test : cases) {
SCOPED_TRACE("Testing with id=" + test.id + ", expected=" + test.expected);
auto selected = doc.select_node(("//*[@id='" + test.id + "']").c_str());
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(test.expected, os.str());
}
}
TEST(Doxygen2Markdown, ParagraphSimpleSect) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<simplesect kind="remark">
<para>First remark paragraph.</para>
<para>Second remark paragraph.</para>
</simplesect>
<simplesect kind="warning">
<para>First warning paragraph.</para>
<para>Second warning paragraph.</para>
</simplesect>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
<aside class="note"><b>Remark:</b>
First remark paragraph.
Second remark paragraph.
</aside>
<aside class="warning"><b>Warning:</b>
First warning paragraph.
Second warning paragraph.
</aside>)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphOrderedList) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<orderedlist>
<listitem><para>First item.</para></listitem>
<listitem>
<para>Second item.</para><para>With a second paragraph.</para>
</listitem>
</orderedlist>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
1. First item.
1. Second item.
With a second paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphItemizedList) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<itemizedlist>
<listitem><para>First item.</para></listitem>
<listitem>
<para>Second item.</para><para>With a second paragraph.</para>
</listitem>
</itemizedlist>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
- First item.
- Second item.
With a second paragraph.)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphProgramListing) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<programlisting><codeline><highlight class="normal">auto<sp/>sr<sp/>=<sp/>MakeStreamRange<T>({t1,<sp/>t2});</highlight></codeline>
<codeline><highlight class="normal">for<sp/>(StatusOr<int><sp/>const&<sp/>v<sp/>:<sp/>sr)<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>//<sp/>Yields<sp/>t1<sp/>-><sp/>t2</highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
<codeline/>
<codeline><highlight class="normal">sr<sp/>=<sp/>MakeStreamRange<T>({t1,<sp/>t2},<sp/>BadStatus());</highlight></codeline>
<codeline><highlight class="normal">for<sp/>(StatusOr<int><sp/>const&<sp/>v<sp/>:<sp/>sr)<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>//<sp/>Yields<sp/>t1<sp/>-><sp/>t2<sp/>-><sp/>BadStatus()</highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
</programlisting>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
```cpp
auto sr = MakeStreamRange<T>({t1, t2});
for (StatusOr<int> const& v : sr) {
// Yields t1 -> t2
}
sr = MakeStreamRange<T>({t1, t2}, BadStatus());
for (StatusOr<int> const& v : sr) {
// Yields t1 -> t2 -> BadStatus()
}
```)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphProgramListingAddsNewLine) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<detaileddescription id='test-node'>
<para>
<simplesect kind="par">
<title>Error Handling</title>
<para>Description goes here.</para>
</simplesect>
<programlisting>
<codeline><highlight class="keyword">namespace<sp/></highlight><highlight class="normal">cbt<sp/>=<sp/><ref refid="namespacegoogle_1_1cloud_1_1bigtable" kindref="compound">google::cloud::bigtable</ref>;</highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keyword">namespace<sp/></highlight><highlight class="normal">btadmin<sp/>=<sp/>google::bigtable::admin::v2;</highlight></codeline>
</programlisting>
</para>
</detaileddescription>
</doxygen>)xml";
auto constexpr kExpected = R"md(
###### Error Handling
Description goes here.
```cpp
namespace cbt = google::cloud::bigtable;
namespace btadmin = google::bigtable::admin::v2;
```)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
MarkdownContext mdctx;
mdctx.paragraph_start = "";
ASSERT_TRUE(AppendIfDetailedDescription(os, mdctx, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphVerbatim) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<verbatim>https://cloud.google.com/storage/docs/transcoding
</verbatim>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
```
https://cloud.google.com/storage/docs/transcoding
```)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphParBlock) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<parblock>
<para>First paragraph</para>
<para>Second paragraph</para>
</parblock>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
First paragraph
Second paragraph)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphTable) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='test-node'>
<table rows="3" cols="2">
<row>
<entry thead="yes"><para>Environment Variable</para></entry>
<entry thead="yes"><para><ref refid="classgoogle_1_1cloud_1_1Options" kindref="compound" external="/workspace/cmake-out/google/cloud/cloud.tag">Options</ref> setting</para></entry>
</row>
<row>
<entry thead="no"><para><computeroutput>SPANNER_OPTIMIZER_VERSION</computeroutput></para></entry>
<entry thead="no"><para><computeroutput><ref refid="structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerVersionOption" kindref="compound">QueryOptimizerVersionOption</ref></computeroutput></para></entry>
</row>
<row>
<entry thead="no"><para><computeroutput>SPANNER_OPTIMIZER_STATISTICS_PACKAGE</computeroutput></para></entry>
<entry thead="no">
<para><computeroutput><ref refid="structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerStatisticsPackageOption" kindref="compound">QueryOptimizerStatisticsPackageOption</ref></computeroutput></para>
<para>With another paragraph</para>
</entry>
</row>
</table>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
| Environment Variable | [Options](xref:classgoogle_1_1cloud_1_1Options) setting |
| ---- | ---- |
| `SPANNER_OPTIMIZER_VERSION` | [`QueryOptimizerVersionOption`](xref:structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerVersionOption) |
| `SPANNER_OPTIMIZER_STATISTICS_PACKAGE` | [`QueryOptimizerStatisticsPackageOption`](xref:structgoogle_1_1cloud_1_1spanner_1_1QueryOptimizerStatisticsPackageOption) With another paragraph |)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphXrefSect) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='tested-node'>
<xrefsect id="deprecated_1_deprecated000001">
<xreftitle>Deprecated</xreftitle>
<xrefdescription>
<para>Use <computeroutput><ref refid="classgoogle_1_1cloud_1_1Options" kindref="compound">Options</ref></computeroutput> and <computeroutput><ref refid="structgoogle_1_1cloud_1_1EndpointOption" kindref="compound">EndpointOption</ref></computeroutput>.</para>
</xrefdescription>
</xrefsect>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(<aside class="deprecated"><b>Deprecated:</b>
Use [`Options`](xref:classgoogle_1_1cloud_1_1Options) and [`EndpointOption`](xref:structgoogle_1_1cloud_1_1EndpointOption).
</aside>)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
MarkdownContext ctx;
ctx.paragraph_start = "";
ASSERT_TRUE(AppendIfParagraph(os, ctx, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphLinebreak) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='tested-node'>Required. Parent resource name. The format of this value varies depending on the scope of the request (project or organization) and whether you have <ulink url="https://cloud.google.com/dlp/docs/specifying-location">specified a processing location</ulink>:<itemizedlist>
<listitem><para>Projects scope, location specified:<linebreak/>
<computeroutput>projects/</computeroutput><emphasis>PROJECT_ID</emphasis><computeroutput>/locations/</computeroutput><emphasis>LOCATION_ID</emphasis></para>
</listitem><listitem><para>Projects scope, no location specified (defaults to global):<linebreak/>
<computeroutput>projects/</computeroutput><emphasis>PROJECT_ID</emphasis></para>
</listitem><listitem><para>Organizations scope, location specified:<linebreak/>
<computeroutput>organizations/</computeroutput><emphasis>ORG_ID</emphasis><computeroutput>/locations/</computeroutput><emphasis>LOCATION_ID</emphasis></para>
</listitem><listitem><para>Organizations scope, no location specified (defaults to global):<linebreak/>
<computeroutput>organizations/</computeroutput><emphasis>ORG_ID</emphasis>
</listitem>
</itemizedlist>
</para>
)xml";
auto constexpr kExpected = R"md(
Required. Parent resource name. The format of this value varies depending on the scope of the request (project or organization) and whether you have [specified a processing location](https://cloud.google.com/dlp/docs/specifying-location):
- Projects scope, location specified:<br>`projects/`*PROJECT_ID*`/locations/`*LOCATION_ID*
- Projects scope, no location specified (defaults to global):<br>`projects/`*PROJECT_ID*
- Organizations scope, location specified:<br>`organizations/`*ORG_ID*`/locations/`*LOCATION_ID*
- Organizations scope, no location specified (defaults to global):<br>`organizations/`*ORG_ID*)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ParagraphWithParagraph) {
auto constexpr kXml = R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<para id='tested-node'>
<para>
<simplesect kind="warning">
<para>Something clever about the warning.</para>
</para>
</para>
</doxygen>)xml";
auto constexpr kExpected = R"md(
<aside class="warning"><b>Warning:</b>
Something clever about the warning.
</aside>)md";
pugi::xml_document doc;
doc.load_string(kXml);
auto selected = doc.select_node("//*[@id='tested-node']");
ASSERT_TRUE(selected);
std::ostringstream os;
ASSERT_TRUE(AppendIfParagraph(os, {}, selected.node()));
EXPECT_EQ(kExpected, os.str());
}
TEST(Doxygen2Markdown, ItemizedListSimple) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<itemizedlist id='test-node'>
<listitem><para>Item 1</para></listitem>
<listitem><para>Item 2: <computeroutput>brrr</computeroutput></para></listitem>
</itemizedlist>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfItemizedList(os, {}, selected.node()));
EXPECT_EQ(os.str(), R"md(
- Item 1
- Item 2: `brrr`)md");
}
TEST(Doxygen2Markdown, ItemizedListSimpleWithParagraphs) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<itemizedlist id='test-node'>
<listitem><para>Item 1</para><para>More about Item 1</para></listitem>
<listitem><para>Item 2: <computeroutput>brrr</computeroutput></para></listitem>
</itemizedlist>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfItemizedList(os, {}, selected.node()));
EXPECT_EQ(os.str(), R"md(
- Item 1
More about Item 1
- Item 2: `brrr`)md");
}
TEST(Doxygen2Markdown, ItemizedListNested) {
pugi::xml_document doc;
doc.load_string(R"xml(<?xml version="1.0" standalone="yes"?>
<doxygen version="1.9.1" xml:lang="en-US">
<itemizedlist id='test-node'>
<listitem><para>Item 1</para><para>More about Item 1</para></listitem>
<listitem><para>Item 2: <computeroutput>brrr</computeroutput>
<itemizedlist>
<listitem>
<para>Sub 1</para>
</listitem>
<listitem><para>Sub 2</para>
<para>More about Sub 2<itemizedlist>
<listitem><para>Sub 2.1</para></listitem>
<listitem><para>Sub 2.2</para><para>More about Sub 2.2</para></listitem>
</itemizedlist>
</para>
</listitem>
<listitem><para>Sub 3</para></listitem>
</itemizedlist></para>
</listitem>
</itemizedlist>
</doxygen>)xml");
auto selected = doc.select_node("//*[@id='test-node']");
std::ostringstream os;
ASSERT_TRUE(AppendIfItemizedList(os, {}, selected.node()));
EXPECT_EQ(os.str(), R"md(
- Item 1