Skip to content

Commit d48545d

Browse files
committed
Add tests for raw string literals with interpolations
1 parent 876d6cf commit d48545d

7 files changed

+77
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
main: () -> int = {
2+
i := 42;
3+
m : std::map<std::string, int> = ();
4+
m["one"] = 1;
5+
m["two"] = 2;
6+
7+
str : std::string = "this is a string";
8+
9+
raw_str : std::string = R"string(raw string without interpolation)string";
10+
11+
raw_str_inter : std::string = R"test(this is raw string literal
12+
that can last for multiple
13+
lines
14+
(i)$ R"(this can be added too)"
15+
calculations like m["one"] + m["two"] = (m["one"] + m["two"])$ also works
16+
("at the beginning of the line")$!!!)test";
17+
18+
std::cout << str << std::endl;
19+
std::cout << raw_str << std::endl;
20+
std::cout << raw_str_inter << std::endl;
21+
std::cout << (R"s((m["one"])$.)s" + R"s((m["two"])$.)s" + R"s((m["three"])$.)s" + R"s((i)$)s") << std::endl;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
this is a string
2+
raw string without interpolation
3+
this is raw string literal
4+
that can last for multiple
5+
lines
6+
42 R"(this can be added too)"
7+
calculations like m["one"] + m["two"] = 3 also works
8+
at the beginning of the line!!!
9+
1.2.0.42

regression-tests/test-results/apple-clang-14/pure2-raw-string-literal-and-interpolation.cpp.output

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
this is a string
2+
raw string without interpolation
3+
this is raw string literal
4+
that can last for multiple
5+
lines
6+
42 R"(this can be added too)"
7+
calculations like m["one"] + m["two"] = 3 also works
8+
at the beginning of the line!!!
9+
1.2.0.42

regression-tests/test-results/clang-12/pure2-raw-string-literal-and-interpolation.cpp.output

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
#include "cpp2util.h"
5+
6+
7+
#line 1 "pure2-raw-string-literal-and-interpolation.cpp2"
8+
[[nodiscard]] auto main() -> int;
9+
10+
//=== Cpp2 definitions ==========================================================
11+
12+
#line 1 "pure2-raw-string-literal-and-interpolation.cpp2"
13+
[[nodiscard]] auto main() -> int{
14+
auto i {42};
15+
std::map<std::string,int> m {};
16+
cpp2::assert_in_bounds(m, "one") = 1;
17+
cpp2::assert_in_bounds(m, "two") = 2;
18+
19+
std::string str {"this is a string"};
20+
21+
std::string raw_str {R"string(raw string without interpolation)string"};
22+
23+
std::string raw_str_inter {R"test(this is raw string literal
24+
that can last for multiple
25+
lines
26+
)test" + cpp2::to_string(i) + R"test( R"(this can be added too)"
27+
calculations like m["one"] + m["two"] = )test" + cpp2::to_string(cpp2::assert_in_bounds(m, "one") + cpp2::assert_in_bounds(m, "two")) + R"test( also works
28+
)test" + cpp2::to_string("at the beginning of the line") + R"test(!!!)test"};
29+
30+
std::cout << std::move(str) << std::endl;
31+
std::cout << std::move(raw_str) << std::endl;
32+
std::cout << std::move(raw_str_inter) << std::endl;
33+
std::cout << (R"s()s" + cpp2::to_string(cpp2::assert_in_bounds(m, "one")) + R"s(.)s" + R"s()s" + cpp2::to_string(cpp2::assert_in_bounds(m, "two")) + R"s(.)s" + R"s()s" + cpp2::to_string(cpp2::assert_in_bounds(std::move(m), "three")) + R"s(.)s" + R"s()s" + cpp2::to_string(std::move(i)) + R"s()s") << std::endl;
34+
}
35+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-raw-string-literal-and-interpolation.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)