Files
swift-mirror/test/stdlib/Repeat.swift
Max Desiatov 372ada0e24 test: add handling for Wasm/WASI (#39519)
This change adds support for WASI in stdlib tests. Some tests that expect a crash to happen had to be disabled, since there's currently no way to observe such crash from a WASI host.
2022-01-12 14:24:50 +00:00

36 lines
937 B
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
let RepeatTests = TestSuite("Repeated")
RepeatTests.test("repeatElement") {
let sequence = repeatElement(1, count: 5)
expectEqual(sequence.count, 5)
expectEqualSequence(sequence, [1, 1, 1, 1, 1])
expectEqual(sequence.startIndex, 0)
expectEqual(sequence.endIndex, 5)
expectEqual(sequence[0], 1)
}
RepeatTests.test("associated-types") {
typealias Subject = Repeated<String>
expectRandomAccessCollectionAssociatedTypes(
collectionType: Subject.self,
iteratorType: IndexingIterator<Subject>.self,
subSequenceType: Slice<Subject>.self,
indexType: Int.self,
indicesType: CountableRange<Int>.self)
}
#if !os(WASI)
// Trap tests aren't available on WASI.
RepeatTests.test("out-of-bounds") {
let sequence = repeatElement(0, count: 1)
expectCrashLater()
_ = sequence[sequence.count]
}
#endif
runAllTests()