]> git.lyx.org Git - lyx.git/blob - src/tests/check_ListingsCaption.cpp
Fix quotation marks in PDF TOC
[lyx.git] / src / tests / check_ListingsCaption.cpp
1 #include <config.h>
2
3 #include "../support/debug.h"
4 #include "../support/regex.h"
5
6 #include <iostream>
7
8
9 using namespace lyx;
10 using namespace std;
11
12
13 // This function is unfortunately copied from ../insets/InsetListing.cpp, so we
14 // should try to make sure to keep the two in sync.
15 string test_ListingsCaption(string const & cap)
16 {
17         // convert from
18         //     blah1\label{blah2} blah3
19         // to
20         //     blah1 blah3},label={blah2
21         // to form options
22         //     caption={blah1 blah3},label={blah2}
23         //
24         // NOTE that } is not allowed in blah2.
25         regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
26         string const new_cap("$1$3},label={$2");
27         return regex_replace(cap, reg, new_cap);
28 }
29
30 void test_test_ListingsCaptions()
31 {
32         cout << test_ListingsCaption("\\label{}") << endl;
33         cout << test_ListingsCaption("\\label{blah2}") << endl;
34         cout << test_ListingsCaption("\\label{blah2} blah3") << endl;
35         cout << test_ListingsCaption("\\label{} blah3") << endl;
36         cout << test_ListingsCaption("blah1\\label{}") << endl;
37         cout << test_ListingsCaption("blah1\\label{} blah3") << endl;
38         cout << test_ListingsCaption("blah1\\label{blah2}") << endl;
39         cout << test_ListingsCaption("blah1\\label{blah2} blah3") << endl;
40 }
41
42
43 int main(int, char **)
44 {
45         // Connect lyxerr with cout instead of cerr to catch error output
46         lyx::lyxerr.setStream(cout);
47         test_test_ListingsCaptions();
48 }