mirror of https://github.com/swig/swig
Add more tests for C++11 raw string literals
Test added to check fixes for: - Issue #948 and issue #1019 and issue #1273 - raw string delimiters not being stripped off - Issue #538 - Ruby support for "docstring" feature
This commit is contained in:
parent
96d33287b4
commit
0c4491eaae
|
@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2019-01-05: wsfulton
|
||||
#948 #1019 #1273 Fix for C++11 raw strings where the delimiters were mistakenly left
|
||||
in the string contents in situations where the string was copied into generated code.
|
||||
For example, %constant, the "docstring" feature and for C#/Java/D constants turned on
|
||||
with %javaconst/%csconst/%dmanifestconst.
|
||||
|
||||
2019-01-05: wsfulton
|
||||
[Ruby] #538. Fix Ruby support for %feature("docstring").
|
||||
|
||||
|
|
|
@ -59,3 +59,43 @@ const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
|
|||
const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
|
||||
%}
|
||||
|
||||
// Constants
|
||||
#if defined(SWIGJAVA)
|
||||
%javaconst(1);
|
||||
#elif SWIGCSHARP
|
||||
%csconst(1);
|
||||
#elif SWIGD
|
||||
%dmanifestconst;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#define jj ")I'm an \"ascii\" \\ string constant."
|
||||
#define kk R"XXX()I'm an "ascii" \ string constant.)XXX";
|
||||
%}
|
||||
|
||||
%constant mm = R"XXX()I'm an "ascii" \ string constant with multiple
|
||||
|
||||
lines.)XXX";
|
||||
|
||||
// docstring feature
|
||||
%feature("docstring") RawStringDoc::WW "Single line documentation comment"
|
||||
%feature("docstring") RawStringDoc::XX %{
|
||||
Multi-line
|
||||
documentation
|
||||
comment
|
||||
%}
|
||||
%feature("docstring") RawStringDoc::YY R"RRR(Single line "raw string" documentation comment)RRR"
|
||||
%feature("docstring") RawStringDoc::ZZ R"FOO(Documentation comment
|
||||
|
||||
as a "raw string"
|
||||
on multiple lines including a \ backslash)FOO"
|
||||
|
||||
%inline %{
|
||||
struct RawStringDoc {
|
||||
void WW() {}
|
||||
void XX() {}
|
||||
void YY() {}
|
||||
void ZZ() {}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import cpp11_raw_string_literals.*;
|
||||
|
||||
public class cpp11_raw_string_literals_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("cpp11_raw_string_literals");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
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);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
if (cpp11_raw_string_literals.getL() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (cpp11_raw_string_literals.getU8() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (cpp11_raw_string_literals.getU() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (UStruct.U != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
|
||||
if (cpp11_raw_string_literals.getR() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (cpp11_raw_string_literals.getLR() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (cpp11_raw_string_literals.getU8R() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (cpp11_raw_string_literals.getUR() != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (URStruct.UR != 100)
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
|
||||
if (!cpp11_raw_string_literals.getAa().equals("Wide string"))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (!cpp11_raw_string_literals.getBb().equals("UTF-8 string"))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (!cpp11_raw_string_literals.getXx().equals(")I'm an \"ascii\" \\ string."))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (!cpp11_raw_string_literals.getEe().equals(")I'm an \"ascii\" \\ string."))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (!cpp11_raw_string_literals.getFf().equals("I'm a \"raw wide\" \\ string."))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
if (!cpp11_raw_string_literals.getGg().equals("I'm a \"raw UTF-8\" \\ string."))
|
||||
throw new RuntimeException("failed!");
|
||||
|
||||
|
||||
|
||||
if (!cpp11_raw_string_literalsConstants.mm.equals(")I'm an \"ascii\" \\ string constant with multiple\n\nlines."))
|
||||
throw new RuntimeException("failed!");
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
from cpp11_raw_string_literals import *
|
||||
import inspect
|
||||
|
||||
if cvar.L != 100:
|
||||
raise RuntimeError
|
||||
|
@ -46,3 +47,29 @@ if cvar.ff != "I'm a \"raw wide\" \\ string.":
|
|||
|
||||
if cvar.gg != "I'm a \"raw UTF-8\" \\ string.":
|
||||
raise RuntimeError, cvar.gg
|
||||
|
||||
|
||||
def check(got, expected):
|
||||
expected_list = expected.split("\n")
|
||||
got_list = got.split("\n")
|
||||
|
||||
if expected_list != got_list:
|
||||
raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list))
|
||||
|
||||
# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options
|
||||
# such as -O and -builtin may produce different initial indentation.
|
||||
check(inspect.getdoc(RawStringDoc.WW), "Single line documentation comment")
|
||||
check(inspect.getdoc(RawStringDoc.XX),
|
||||
"""Multi-line
|
||||
documentation
|
||||
comment""")
|
||||
check(inspect.getdoc(RawStringDoc.YY), """Single line "raw string" documentation comment""")
|
||||
check(inspect.getdoc(RawStringDoc.ZZ),
|
||||
"""Documentation comment
|
||||
|
||||
as a "raw string"
|
||||
on multiple lines including a \ backslash""")
|
||||
|
||||
check(mm, """)I'm an "ascii" \ string constant with multiple
|
||||
|
||||
lines.""")
|
||||
|
|
Loading…
Reference in New Issue