File tree 2 files changed +74
-0
lines changed
test/Interop/Cxx/stdlib/overlay 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,40 @@ extension std.u16string: ExpressibleByStringLiteral {
53
53
}
54
54
}
55
55
56
+ // MARK: Concatenating and comparing C++ strings
57
+
58
+ extension std . string : Equatable {
59
+ public static func == ( lhs: std . string , rhs: std . string ) -> Bool {
60
+ return lhs. compare ( rhs) == 0
61
+ }
62
+
63
+ public static func += ( lhs: inout std . string , rhs: std . string ) {
64
+ lhs. __appendUnsafe ( rhs) // ignore the returned pointer
65
+ }
66
+
67
+ public static func + ( lhs: std . string , rhs: std . string ) -> std . string {
68
+ var copy = lhs
69
+ copy += rhs
70
+ return copy
71
+ }
72
+ }
73
+
74
+ extension std . u16string : Equatable {
75
+ public static func == ( lhs: std . u16string , rhs: std . u16string ) -> Bool {
76
+ return lhs. compare ( rhs) == 0
77
+ }
78
+
79
+ public static func += ( lhs: inout std . u16string , rhs: std . u16string ) {
80
+ lhs. __appendUnsafe ( rhs) // ignore the returned pointer
81
+ }
82
+
83
+ public static func + ( lhs: std . u16string , rhs: std . u16string ) -> std . u16string {
84
+ var copy = lhs
85
+ copy += rhs
86
+ return copy
87
+ }
88
+ }
89
+
56
90
// MARK: Getting a Swift description of a C++ string
57
91
58
92
extension std . string : CustomDebugStringConvertible {
Original file line number Diff line number Diff line change @@ -45,6 +45,46 @@ StdStringOverlayTestSuite.test("std::string <=> Swift.String") {
45
45
expectEqual ( swift7, " ��� " )
46
46
}
47
47
48
+ StdStringOverlayTestSuite . test ( " std::string operators " ) {
49
+ var s1 = std. string ( " something " )
50
+ let s2 = std. string ( " 123 " )
51
+ let sum = s1 + s2
52
+ expectEqual ( sum, std. string ( " something123 " ) )
53
+
54
+ expectFalse ( s1 == s2)
55
+ let s3 = std. string ( " something123 " )
56
+ expectFalse ( s1 == s3)
57
+ expectFalse ( s2 == s3)
58
+
59
+ s1 += s2
60
+ expectTrue ( s1 == std. string ( " something123 " ) )
61
+ expectTrue ( s1 == s3)
62
+
63
+ // Make sure the operators work together with ExpressibleByStringLiteral conformance.
64
+ s1 += " literal "
65
+ expectTrue ( s1 == " something123literal " )
66
+ }
67
+
68
+ StdStringOverlayTestSuite . test ( " std::u16string operators " ) {
69
+ var s1 = std. u16string ( " something " )
70
+ let s2 = std. u16string ( " 123 " )
71
+ let sum = s1 + s2
72
+ expectEqual ( sum, std. u16string ( " something123 " ) )
73
+
74
+ expectFalse ( s1 == s2)
75
+ let s3 = std. u16string ( " something123 " )
76
+ expectFalse ( s1 == s3)
77
+ expectFalse ( s2 == s3)
78
+
79
+ s1 += s2
80
+ expectTrue ( s1 == std. u16string ( " something123 " ) )
81
+ expectTrue ( s1 == s3)
82
+
83
+ // Make sure the operators work together with ExpressibleByStringLiteral conformance.
84
+ s1 += " literal "
85
+ expectTrue ( s1 == " something123literal " )
86
+ }
87
+
48
88
StdStringOverlayTestSuite . test ( " std::u16string <=> Swift.String " ) {
49
89
let cxx1 = std. u16string ( )
50
90
let swift1 = String ( cxx1)
You can’t perform that action at this time.
0 commit comments