Files
SwiftShell/SwiftShellTests/Stream_Tests.swift
T
Kare Morstol ed34a689ec ReadableStreamType inherits from Streamable.
Also tried out and commented stuff that does not work in beta 6.
2014-08-23 21:02:08 +02:00

61 lines
1.3 KiB
Swift

//
// Stream_Tests.swift
// SwiftShell
//
// Created by Kåre Morstøl on 21/08/14.
// Copyright (c) 2014 NotTooBad Software. All rights reserved.
//
import SwiftShell
import XCTest
class Stream_Tests: XCTestCase {
func testStreamFromAString () {
XCTAssertEqual( "this is a string", stream("this is a string").read() )
XCTAssertEqual( "These are weird↔️🐻♨︎", stream("These are weird↔️🐻♨︎").read() )
}
func testCustomStream () {
let result = stream ({
var finished = false
return {
if !finished {
finished = true
return "this is it"
} else {
return nil
}
}
})
XCTAssertEqual( result.read(), "this is it" )
}
func testStreamFromArray () {
XCTAssertEqual( stream(["item 1","item 2"]).read(), "item 1item 2")
}
func streams () -> (WriteableStreamType, ReadableStreamType) {
let pipe = NSPipe()
return (pipe.fileHandleForWriting, pipe.fileHandleForReading)
}
func testPrintStreamToStream () {
var (writable, readable) = streams()
let input = stream("this goes in")
// doesn't work in beta 6 (see Pipes.Swift)
// stream("this goes in") |> writable
// nor does this. Damn you beta 6
// print(stream("this goes in") , &writable)
// input.writeTo(&writable)
writable.write(input.read())
XCTAssertEqual(readable.readSome()!, "this goes in")
}
}