diff --git a/test/1_stdlib/Collection.swift b/test/1_stdlib/Collection.swift index 3973ad9c6c636..1daad9ca9d3de 100644 --- a/test/1_stdlib/Collection.swift +++ b/test/1_stdlib/Collection.swift @@ -1,6 +1,13 @@ -// RUN: %target-run-simple-swift | FileCheck %s +// RUN: %target-run-simple-swift --stdlib-unittest-in-process | tee %t.txt +// RUN: FileCheck %s < %t.txt +// note: remove the --stdlib-unittest-in-process once all the FileCheck tests +// have been converted to StdlibUnittest // REQUIRES: executable_test +import StdlibUnittest + +var CollectionTests = TestSuite("CollectionTests") + struct X : CollectionType { typealias Element = String.CharacterView.Generator.Element typealias Index = String.Index @@ -202,5 +209,38 @@ func testIsEmptyFirstLast() { } testIsEmptyFirstLast() +/// A `CollectionType` that vends just the default implementations for +/// `CollectionType` methods. +struct CollectionOnly : CollectionType { + var base: T + + var startIndex: T.Index { + return base.startIndex + } + + var endIndex: T.Index { + return base.endIndex + } + + func generate() -> T.Generator { + return base.generate() + } + + subscript(position: T.Index) -> T.Generator.Element { + return base[position] + } +} + // CHECK: all done. print("all done.") + +CollectionTests.test("first/performance") { + // accessing `first` should not perform duplicate work on lazy collections + var log: [Int] = [] + let col_ = (0..<10).lazy.filter({ log.append($0); return (2..<8).contains($0) }) + let col = CollectionOnly(base: col_) + expectEqual(2, col.first) + expectEqual([0, 1, 2], log) +} + +runAllTests()