Skip to content

Commit 0c4491e

Browse files
committed
Add more tests for C++11 raw string literals
Test added to check fixes for: - Issue swig#948 and issue swig#1019 and issue swig#1273 - raw string delimiters not being stripped off - Issue swig#538 - Ruby support for "docstring" feature
1 parent 96d3328 commit 0c4491e

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

CHANGES.current

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.0.0 (in progress)
88
===========================
99

10+
2019-01-05: wsfulton
11+
#948 #1019 #1273 Fix for C++11 raw strings where the delimiters were mistakenly left
12+
in the string contents in situations where the string was copied into generated code.
13+
For example, %constant, the "docstring" feature and for C#/Java/D constants turned on
14+
with %javaconst/%csconst/%dmanifestconst.
15+
1016
2019-01-05: wsfulton
1117
[Ruby] #538. Fix Ruby support for %feature("docstring").
1218

Examples/test-suite/cpp11_raw_string_literals.i

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,43 @@ const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
5959
const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
6060
%}
6161

62+
// Constants
63+
#if defined(SWIGJAVA)
64+
%javaconst(1);
65+
#elif SWIGCSHARP
66+
%csconst(1);
67+
#elif SWIGD
68+
%dmanifestconst;
69+
#endif
70+
71+
%inline %{
72+
#define jj ")I'm an \"ascii\" \\ string constant."
73+
#define kk R"XXX()I'm an "ascii" \ string constant.)XXX";
74+
%}
75+
76+
%constant mm = R"XXX()I'm an "ascii" \ string constant with multiple
77+
78+
lines.)XXX";
79+
80+
// docstring feature
81+
%feature("docstring") RawStringDoc::WW "Single line documentation comment"
82+
%feature("docstring") RawStringDoc::XX %{
83+
Multi-line
84+
documentation
85+
comment
86+
%}
87+
%feature("docstring") RawStringDoc::YY R"RRR(Single line "raw string" documentation comment)RRR"
88+
%feature("docstring") RawStringDoc::ZZ R"FOO(Documentation comment
89+
90+
as a "raw string"
91+
on multiple lines including a \ backslash)FOO"
92+
93+
%inline %{
94+
struct RawStringDoc {
95+
void WW() {}
96+
void XX() {}
97+
void YY() {}
98+
void ZZ() {}
99+
};
100+
%}
101+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import cpp11_raw_string_literals.*;
2+
3+
public class cpp11_raw_string_literals_runme {
4+
5+
static {
6+
try {
7+
System.loadLibrary("cpp11_raw_string_literals");
8+
} catch (UnsatisfiedLinkError e) {
9+
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
10+
System.exit(1);
11+
}
12+
}
13+
14+
public static void main(String argv[]) {
15+
if (cpp11_raw_string_literals.getL() != 100)
16+
throw new RuntimeException("failed!");
17+
18+
if (cpp11_raw_string_literals.getU8() != 100)
19+
throw new RuntimeException("failed!");
20+
21+
if (cpp11_raw_string_literals.getU() != 100)
22+
throw new RuntimeException("failed!");
23+
24+
if (UStruct.U != 100)
25+
throw new RuntimeException("failed!");
26+
27+
28+
if (cpp11_raw_string_literals.getR() != 100)
29+
throw new RuntimeException("failed!");
30+
31+
if (cpp11_raw_string_literals.getLR() != 100)
32+
throw new RuntimeException("failed!");
33+
34+
if (cpp11_raw_string_literals.getU8R() != 100)
35+
throw new RuntimeException("failed!");
36+
37+
if (cpp11_raw_string_literals.getUR() != 100)
38+
throw new RuntimeException("failed!");
39+
40+
if (URStruct.UR != 100)
41+
throw new RuntimeException("failed!");
42+
43+
44+
if (!cpp11_raw_string_literals.getAa().equals("Wide string"))
45+
throw new RuntimeException("failed!");
46+
47+
if (!cpp11_raw_string_literals.getBb().equals("UTF-8 string"))
48+
throw new RuntimeException("failed!");
49+
50+
if (!cpp11_raw_string_literals.getXx().equals(")I'm an \"ascii\" \\ string."))
51+
throw new RuntimeException("failed!");
52+
53+
if (!cpp11_raw_string_literals.getEe().equals(")I'm an \"ascii\" \\ string."))
54+
throw new RuntimeException("failed!");
55+
56+
if (!cpp11_raw_string_literals.getFf().equals("I'm a \"raw wide\" \\ string."))
57+
throw new RuntimeException("failed!");
58+
59+
if (!cpp11_raw_string_literals.getGg().equals("I'm a \"raw UTF-8\" \\ string."))
60+
throw new RuntimeException("failed!");
61+
62+
63+
64+
if (!cpp11_raw_string_literalsConstants.mm.equals(")I'm an \"ascii\" \\ string constant with multiple\n\nlines."))
65+
throw new RuntimeException("failed!");
66+
}
67+
}

Examples/test-suite/python/cpp11_raw_string_literals_runme.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from cpp11_raw_string_literals import *
2+
import inspect
23

34
if cvar.L != 100:
45
raise RuntimeError
@@ -46,3 +47,29 @@
4647

4748
if cvar.gg != "I'm a \"raw UTF-8\" \\ string.":
4849
raise RuntimeError, cvar.gg
50+
51+
52+
def check(got, expected):
53+
expected_list = expected.split("\n")
54+
got_list = got.split("\n")
55+
56+
if expected_list != got_list:
57+
raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list))
58+
59+
# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options
60+
# such as -O and -builtin may produce different initial indentation.
61+
check(inspect.getdoc(RawStringDoc.WW), "Single line documentation comment")
62+
check(inspect.getdoc(RawStringDoc.XX),
63+
"""Multi-line
64+
documentation
65+
comment""")
66+
check(inspect.getdoc(RawStringDoc.YY), """Single line "raw string" documentation comment""")
67+
check(inspect.getdoc(RawStringDoc.ZZ),
68+
"""Documentation comment
69+
70+
as a "raw string"
71+
on multiple lines including a \ backslash""")
72+
73+
check(mm, """)I'm an "ascii" \ string constant with multiple
74+
75+
lines.""")

0 commit comments

Comments
 (0)