Tidy up / nitpick.
This commit is contained in:
@@ -84,6 +84,6 @@ public func $ (shellcommand: String) -> String {
|
||||
}
|
||||
|
||||
/** Turn a sequence into valid parameters for a shell command, properly quoted */
|
||||
public func parameters <S : SequenceType>(sequence: S) -> String {
|
||||
return " " + ( sequence |> map {"\"\(toString($0))\""} |> join(" ") )
|
||||
public func parameters <S : SequenceType> (sequence: S) -> String {
|
||||
return " " + ( sequence |> map { "\"\(toString($0))\"" } |> join(" ") )
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ It can be used on its own.
|
||||
|
||||
infix operator |> { precedence 50 associativity left }
|
||||
|
||||
public func |> <T,U>(lhs: T, rhs: T -> U) -> U {
|
||||
public func |> <T,U> (lhs: T, rhs: T -> U) -> U {
|
||||
return rhs(lhs)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public func join <C : ExtensibleCollectionType, S : SequenceType where S.Generat
|
||||
}
|
||||
|
||||
/** Turn a sequence into an array. For use after the |> operator. */
|
||||
public func toArray <S : SequenceType, T where S.Generator.Element == T>(sequence: S) -> [T] {
|
||||
public func toArray <S : SequenceType> (sequence: S) -> [S.Generator.Element] {
|
||||
return Array(sequence)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public func drop <S : SequenceType, T : Equatable where S.Generator.Element == T
|
||||
(tobedropped: [T])
|
||||
(sequence: S)
|
||||
-> LazySequence<FilterSequenceView<S>> {
|
||||
|
||||
|
||||
return sequence |> filter { !contains(tobedropped, $0) }
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public func stream ( closure:() -> () -> String? ) -> ReadableStreamType {
|
||||
}
|
||||
|
||||
/** Create a stream from a sequence of Strings. */
|
||||
public func stream <Seq : SequenceType where Seq.Generator.Element == String>(sequence: Seq) -> ReadableStreamType {
|
||||
public func stream <Seq : SequenceType where Seq.Generator.Element == String> (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 <T>(stream: WriteableStreamType)(input: T) {
|
||||
public func writeTo <T> (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 <S : SequenceType>(stream: WriteableStreamType)(seq: S) {
|
||||
public func writeTo <S : SequenceType> (stream: WriteableStreamType)(seq: S) {
|
||||
for item in seq {
|
||||
item |> writeTo(stream)
|
||||
}
|
||||
@@ -173,7 +173,7 @@ Write something to a stream.
|
||||
|
||||
something |>> writablestream
|
||||
*/
|
||||
public func |>> <T>(input: T, stream: WriteableStreamType) {
|
||||
public func |>> <T> (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 |>> <S : SequenceType>(seq: S, stream: WriteableStreamType) {
|
||||
public func |>> <S : SequenceType> (seq: S, stream: WriteableStreamType) {
|
||||
writeTo(stream)(seq: seq)
|
||||
}
|
||||
|
||||
@@ -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\"" )
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import XCTest
|
||||
class Files_Tests: XCTestCase {
|
||||
|
||||
func testTempDirectory_IsTheSameAfterRepeatedCalls () {
|
||||
XCTAssertEqual(tempdirectory, tempdirectory)
|
||||
XCTAssertEqual( tempdirectory, tempdirectory )
|
||||
}
|
||||
|
||||
func testWorkDirectory_IsCurrentDirectory () {
|
||||
|
||||
@@ -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" )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user