diff --git a/SwiftShell/Command.swift b/SwiftShell/Command.swift index a13fc6c..31fa001 100644 --- a/SwiftShell/Command.swift +++ b/SwiftShell/Command.swift @@ -84,6 +84,6 @@ public func $ (shellcommand: String) -> String { } /** Turn a sequence into valid parameters for a shell command, properly quoted */ -public func parameters (sequence: S) -> String { - return " " + ( sequence |> map {"\"\(toString($0))\""} |> join(" ") ) +public func parameters (sequence: S) -> String { + return " " + ( sequence |> map { "\"\(toString($0))\"" } |> join(" ") ) } diff --git a/SwiftShell/Pipes.swift b/SwiftShell/Pipes.swift index 73755de..b2f48ac 100644 --- a/SwiftShell/Pipes.swift +++ b/SwiftShell/Pipes.swift @@ -14,7 +14,7 @@ It can be used on its own. infix operator |> { precedence 50 associativity left } -public func |> (lhs: T, rhs: T -> U) -> U { +public func |> (lhs: T, rhs: T -> U) -> U { return rhs(lhs) } @@ -77,7 +77,7 @@ public func join operator. */ -public func toArray (sequence: S) -> [T] { +public func toArray (sequence: S) -> [S.Generator.Element] { return Array(sequence) } @@ -86,7 +86,7 @@ public func drop LazySequence> { - + return sequence |> filter { !contains(tobedropped, $0) } } diff --git a/SwiftShell/Stream.swift b/SwiftShell/Stream.swift index 6c23918..bb9d522 100644 --- a/SwiftShell/Stream.swift +++ b/SwiftShell/Stream.swift @@ -86,7 +86,7 @@ public func stream ( closure:() -> () -> String? ) -> ReadableStreamType { } /** Create a stream from a sequence of Strings. */ -public func stream (sequence: Seq) -> ReadableStreamType { +public func stream (sequence: Seq) -> ReadableStreamType { return stream { var generator = sequence.generate() return { generator.next() } @@ -148,7 +148,7 @@ Write something to a stream. something |> writeTo(writablestream) */ -public func writeTo (stream: WriteableStreamType)(input: T) { +public func writeTo (stream: WriteableStreamType)(input: T) { stream.write( toString(input) ) } @@ -160,7 +160,7 @@ public func writeTo (stream: WriteableStreamType)(input: String) { } /** Write a sequence to a stream. */ -public func writeTo (stream: WriteableStreamType)(seq: S) { +public func writeTo (stream: WriteableStreamType)(seq: S) { for item in seq { item |> writeTo(stream) } @@ -173,7 +173,7 @@ Write something to a stream. something |>> writablestream */ -public func |>> (input: T, stream: WriteableStreamType) { +public func |>> (input: T, stream: WriteableStreamType) { writeTo(stream)(input: input) } @@ -185,6 +185,6 @@ public func |>> (text: String, stream: WriteableStreamType) { } /** Write a sequence to a stream. */ -public func |>> (seq: S, stream: WriteableStreamType) { +public func |>> (seq: S, stream: WriteableStreamType) { writeTo(stream)(seq: seq) } diff --git a/SwiftShellTests/Command_Tests.swift b/SwiftShellTests/Command_Tests.swift index b39ff71..112771c 100644 --- a/SwiftShellTests/Command_Tests.swift +++ b/SwiftShellTests/Command_Tests.swift @@ -16,21 +16,21 @@ class Command_Tests: XCTestCase { } func testSimpleCommandWithOutput () { - XCTAssertEqual( SwiftShell.run("echo this is streamed").read(), "this is streamed\n") + XCTAssertEqual( SwiftShell.run("echo this is streamed").read(), "this is streamed\n" ) } func testChainedCommands () { - let result = SwiftShell.run("echo this is streamed") |> SwiftShell.run( "wc -w") - XCTAssertEqual( result.read().trim(), "3", "the number of words should be 3") + let result = SwiftShell.run("echo this is streamed") |> SwiftShell.run("wc -w") + XCTAssertEqual( result.read().trim(), "3", "the number of words should be 3" ) } func testInlineCommand () { - XCTAssertEqual( $("echo one"), "one") + XCTAssertEqual( $("echo one"), "one" ) } func testInlineCommandInsideRunCommandAfterPipe () { let result = stream("line 1\nline 2\nline 3") |> SwiftShell.run("grep " + $("echo 2")) - XCTAssertEqual( result.read(), "line 2\n") + XCTAssertEqual( result.read(), "line 2\n" ) } func testParametersFromSequenceOfStrings () { @@ -40,7 +40,7 @@ class Command_Tests: XCTestCase { func testParametersFromSequenceOfStreams () { var (writable, readable) = streams() - let result = SequenceOf([stream("one"), stream("two"), stream("three")].generate()) |> parameters + let result = SequenceOf( [stream("one"), stream("two"), stream("three")].generate() ) |> parameters XCTAssertEqual( result, " \"one\" \"two\" \"three\"" ) } diff --git a/SwiftShellTests/Files_Tests.swift b/SwiftShellTests/Files_Tests.swift index afc08e8..54f5b37 100644 --- a/SwiftShellTests/Files_Tests.swift +++ b/SwiftShellTests/Files_Tests.swift @@ -12,7 +12,7 @@ import XCTest class Files_Tests: XCTestCase { func testTempDirectory_IsTheSameAfterRepeatedCalls () { - XCTAssertEqual(tempdirectory, tempdirectory) + XCTAssertEqual( tempdirectory, tempdirectory ) } func testWorkDirectory_IsCurrentDirectory () { diff --git a/SwiftShellTests/Stream_Tests.swift b/SwiftShellTests/Stream_Tests.swift index 1290270..51ef893 100644 --- a/SwiftShellTests/Stream_Tests.swift +++ b/SwiftShellTests/Stream_Tests.swift @@ -32,7 +32,7 @@ class Stream_Tests: XCTestCase { } func testStreamFromArray () { - XCTAssertEqual( stream(["item 1","item 2"]).read(), "item 1item 2") + XCTAssertEqual( stream(["item 1","item 2"]).read(), "item 1item 2" ) } func testPrintStreamToStream () { @@ -40,7 +40,7 @@ class Stream_Tests: XCTestCase { stream("this goes in") |>> writable - XCTAssertEqual( readable.readSome()!, "this goes in") + XCTAssertEqual( readable.readSome()!, "this goes in" ) } func testPrintStreamToStreamInPieces () { @@ -49,7 +49,7 @@ class Stream_Tests: XCTestCase { stream(["this ", "goes", " in"]) |>> writable writable.closeStream() - XCTAssertEqual( readable.read(), "this goes in") + XCTAssertEqual( readable.read(), "this goes in" ) } func testPrintStringToStream () { @@ -57,7 +57,7 @@ class Stream_Tests: XCTestCase { "this goes in" |>> writable - XCTAssertEqual( readable.readSome()!, "this goes in") + XCTAssertEqual( readable.readSome()!, "this goes in" ) } func testCommandChainToStream () { @@ -65,7 +65,7 @@ class Stream_Tests: XCTestCase { SwiftShell.run("echo this is streamed") |> SwiftShell.run("wc -w") |>> writable - XCTAssertEqual( readable.readSome()!.trim(), "3") + XCTAssertEqual( readable.readSome()!.trim(), "3" ) } func testSequenceOfStreamsToStream () { @@ -74,7 +74,7 @@ class Stream_Tests: XCTestCase { // make sure the array isn't printed as a Printable. SequenceOf([stream("line 1"), stream("line 2"), stream("line 3")].generate()) |>> writable - XCTAssertEqual( readable.readSome()!.trim(), "line 1line 2line 3") + XCTAssertEqual( readable.readSome()!.trim(), "line 1line 2line 3" ) } func testChainWithSequenceOfStreamsPrintedToStream () { @@ -85,7 +85,7 @@ class Stream_Tests: XCTestCase { |> map { line in SwiftShell.run("echo \(line)") } |>> writable - XCTAssertEqual( readable.readSome()!.trim(), "line 1\nline 2\nline 3") + XCTAssertEqual( readable.readSome()!.trim(), "line 1\nline 2\nline 3" ) } func testChainWithSequenceOfStringsPrintedToStream () { @@ -94,6 +94,6 @@ class Stream_Tests: XCTestCase { stream("line 1\nline 2\nline 3").lines() |> map {line in "line \(i++): \(line)\n"} |>> writable - XCTAssertEqual( readable.readSome()!.trim(), "line 1: line 1\nline 2: line 2\nline 3: line 3") + XCTAssertEqual( readable.readSome()!.trim(), "line 1: line 1\nline 2: line 2\nline 3: line 3" ) } } diff --git a/SwiftShellTests/String_Tests.swift b/SwiftShellTests/String_Tests.swift index e37b8c7..689af12 100644 --- a/SwiftShellTests/String_Tests.swift +++ b/SwiftShellTests/String_Tests.swift @@ -14,12 +14,12 @@ class String_Tests: XCTestCase { func testCountOccurrencesOfStringInstring () { let text = "how many are there here" - XCTAssertEqual( text.countOccurrencesOf( "e"), 5) - XCTAssertEqual( text.countOccurrencesOf( "x"), 0) - XCTAssertEqual( text.countOccurrencesOf( "h"), 3) - XCTAssertEqual( text.countOccurrencesOf( "ho"), 1) - XCTAssertEqual( text.countOccurrencesOf( "re"), 3) - XCTAssertEqual( text.countOccurrencesOf( "Not found"), 0) + XCTAssertEqual( text.countOccurrencesOf( "e"), 5 ) + XCTAssertEqual( text.countOccurrencesOf( "x"), 0 ) + XCTAssertEqual( text.countOccurrencesOf( "h"), 3 ) + XCTAssertEqual( text.countOccurrencesOf( "ho"), 1 ) + XCTAssertEqual( text.countOccurrencesOf( "re"), 3 ) + XCTAssertEqual( text.countOccurrencesOf( "Not found"), 0 ) } func testFindAll () { @@ -29,35 +29,35 @@ class String_Tests: XCTestCase { return text.findAll(findstring) |> toArray } - XCTAssertEqual(ranges("a").count, 5) - XCTAssertEqual(ranges("bb").count, 1) - XCTAssertEqual(ranges("a ").count, 2) + XCTAssertEqual( ranges("a").count, 5 ) + XCTAssertEqual( ranges("bb").count, 1 ) + XCTAssertEqual( ranges("a ").count, 2 ) } func testReplaceStringwithstring () { let text = "a b c aa bb cc ab bc ca" - XCTAssertEqual( text.replace("a", "x"), "x b c xx bb cc xb bc cx") - XCTAssertEqual( text.replace("b ", "x"), "a xc aa bxcc axbc ca") + XCTAssertEqual( text.replace("a", "x"), "x b c xx bb cc xb bc cx" ) + XCTAssertEqual( text.replace("b ", "x"), "a xc aa bxcc axbc ca" ) } func testReplaceOnlySomeStringsWithString () { let text = "a b c aa bb cc ab bc ca" - XCTAssertEqual( text.replace("a", "x", limit: 0), "a b c aa bb cc ab bc ca") - XCTAssertEqual( text.replace("a", "x", limit: 2), "x b c xa bb cc ab bc ca") - XCTAssertEqual( text.replace("a", "x", limit: 4), "x b c xx bb cc xb bc ca") - XCTAssertEqual( text.replace("a", "x", limit: 5), "x b c xx bb cc xb bc cx") - XCTAssertEqual( text.replace("a", "x", limit: 6), "x b c xx bb cc xb bc cx") + XCTAssertEqual( text.replace("a", "x", limit: 0), "a b c aa bb cc ab bc ca" ) + XCTAssertEqual( text.replace("a", "x", limit: 2), "x b c xa bb cc ab bc ca" ) + XCTAssertEqual( text.replace("a", "x", limit: 4), "x b c xx bb cc xb bc ca" ) + XCTAssertEqual( text.replace("a", "x", limit: 5), "x b c xx bb cc xb bc cx" ) + XCTAssertEqual( text.replace("a", "x", limit: 6), "x b c xx bb cc xb bc cx" ) - XCTAssertEqual( text.replace("a", "[xy]", limit: 4), "[xy] b c [xy][xy] bb cc [xy]b bc ca") - XCTAssertEqual( text.replace("a", "[xy]", limit: 5), "[xy] b c [xy][xy] bb cc [xy]b bc c[xy]") - XCTAssertEqual( text.replace("a", "[xy]", limit: 6), "[xy] b c [xy][xy] bb cc [xy]b bc c[xy]") + XCTAssertEqual( text.replace("a", "[xy]", limit: 4), "[xy] b c [xy][xy] bb cc [xy]b bc ca" ) + XCTAssertEqual( text.replace("a", "[xy]", limit: 5), "[xy] b c [xy][xy] bb cc [xy]b bc c[xy]" ) + XCTAssertEqual( text.replace("a", "[xy]", limit: 6), "[xy] b c [xy][xy] bb cc [xy]b bc c[xy]" ) - XCTAssertEqual( text.replace("a ", "x", limit: 0), "a b c aa bb cc ab bc ca") - XCTAssertEqual( text.replace("a ", "x", limit: 1), "xb c aa bb cc ab bc ca") - XCTAssertEqual( text.replace("a ", "x", limit: 2), "xb c axbb cc ab bc ca") - XCTAssertEqual( text.replace("a ", "x", limit: 3), "xb c axbb cc ab bc ca") + XCTAssertEqual( text.replace("a ", "x", limit: 0), "a b c aa bb cc ab bc ca" ) + XCTAssertEqual( text.replace("a ", "x", limit: 1), "xb c aa bb cc ab bc ca" ) + XCTAssertEqual( text.replace("a ", "x", limit: 2), "xb c axbb cc ab bc ca" ) + XCTAssertEqual( text.replace("a ", "x", limit: 3), "xb c axbb cc ab bc ca" ) } }