File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import Foundation
2
+
3
+
1
4
public enum Argument {
2
5
case quoted( QuotedString )
3
6
case verbatim( String )
@@ -21,11 +24,23 @@ public enum Argument {
21
24
}
22
25
23
26
27
+ extension Argument : ExpressibleByStringLiteral {
28
+ public init ( stringLiteral value: StringLiteralType ) {
29
+ self = . quoted( . init( value) )
30
+ }
31
+ }
32
+
33
+
24
34
extension Argument : CustomStringConvertible {
25
35
public var description : String { string }
26
36
}
27
37
28
38
39
+ extension Argument {
40
+ public static func url( _ url: URL ) -> Self { url. absoluteString. verbatim }
41
+ }
42
+
43
+
29
44
extension String {
30
45
public var quoted : Argument { . init( quoted: self ) }
31
46
public var verbatim : Argument { . init( verbatim: self ) }
Original file line number Diff line number Diff line change @@ -215,4 +215,14 @@ class ShellOutTests: XCTestCase {
215
215
arguments: [ " foo ; echo bar " . verbatim] ) ,
216
216
" foo \n bar " )
217
217
}
218
+
219
+ func test_Argument_ExpressibleByStringLiteral( ) throws {
220
+ XCTAssertEqual ( ( " foo " as Argument ) . string, " foo " )
221
+ XCTAssertEqual ( ( " foo bar " as Argument ) . string, " 'foo bar' " )
222
+ }
223
+
224
+ func test_Argument_url( ) throws {
225
+ XCTAssertEqual ( Argument . url ( . init( string: " https://example.com " ) !) . string,
226
+ " https://example.com " )
227
+ }
218
228
}
You can’t perform that action at this time.
0 commit comments