|
| 1 | +// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-6) |
| 2 | +// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift) |
| 3 | +// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++14) |
| 4 | +// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++17) |
| 5 | +// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20) |
| 6 | + |
| 7 | +// Also test this with a bridging header instead of the StdSet module. |
| 8 | +// RUN: %empty-directory(%t2) |
| 9 | +// RUN: cp %S/Inputs/std-stack.h %t2/std-stack-bridging-header.h |
| 10 | +// RUN: %target-run-simple-swift(-D BRIDGING_HEADER -import-objc-header %t2/std-stack-bridging-header.h -cxx-interoperability-mode=swift-6) |
| 11 | +// RUN: %target-run-simple-swift(-D BRIDGING_HEADER -import-objc-header %t2/std-stack-bridging-header.h -cxx-interoperability-mode=upcoming-swift) |
| 12 | + |
| 13 | +// REQUIRES: executable_test |
| 14 | +// |
| 15 | +// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514 |
| 16 | +// REQUIRES: OS=macosx || OS=linux-gnu |
| 17 | + |
| 18 | +import StdlibUnittest |
| 19 | +#if !BRIDGING_HEADER |
| 20 | +import StdStack |
| 21 | +#endif |
| 22 | +import CxxStdlib |
| 23 | + |
| 24 | +var StdStackTestSuite = TestSuite("StdStack") |
| 25 | + |
| 26 | +StdStackTestSuite.test("stack count") { |
| 27 | + let s1 = initStackOfCInt() |
| 28 | + expectEqual(s1.count, 3) |
| 29 | + |
| 30 | + let s2 = initEmptyStackOfCInt() |
| 31 | + expectEqual(s2.count, 0) |
| 32 | +} |
| 33 | + |
| 34 | +StdStackTestSuite.test("stack isEmpty") { |
| 35 | + let s1 = initStackOfCInt() |
| 36 | + expectFalse(s1.isEmpty) |
| 37 | + |
| 38 | + let s2 = initEmptyStackOfCInt() |
| 39 | + expectTrue(s2.isEmpty) |
| 40 | +} |
| 41 | + |
| 42 | +StdStackTestSuite.test("stack top") { |
| 43 | + let s1 = initStackOfCInt() |
| 44 | + expectEqual(s1.top(), 3) |
| 45 | + |
| 46 | + let s2 = initEmptyStackOfCInt() |
| 47 | + expectNil(s2.top()) |
| 48 | +} |
| 49 | + |
| 50 | +StdStackTestSuite.test("stack push") { |
| 51 | + var s1 = initStackOfCInt() |
| 52 | + |
| 53 | + s1.push(4) |
| 54 | + expectEqual(s1.top(), 4) |
| 55 | + expectEqual(s1.count, 4) |
| 56 | + s1.safePop() |
| 57 | + expectEqual(s1.top(), 3) |
| 58 | + expectEqual(s1.count, 3) |
| 59 | + |
| 60 | + var s2 = initEmptyStackOfCInt() |
| 61 | + |
| 62 | + s2.push(4) |
| 63 | + expectEqual(s2.top(), 4) |
| 64 | + expectEqual(s2.count, 1) |
| 65 | +} |
| 66 | + |
| 67 | +StdStackTestSuite.test("stack safePop") { |
| 68 | + var s1 = initStackOfCInt() |
| 69 | + |
| 70 | + expectEqual(s1.safePop(), 3) |
| 71 | + expectEqual(s1.safePop(), 2) |
| 72 | + expectEqual(s1.safePop(), 1) |
| 73 | + expectNil(s1.safePop()) |
| 74 | + expectTrue(s1.isEmpty) |
| 75 | + |
| 76 | + var s2 = initEmptyStackOfCInt() |
| 77 | + expectNil(s2.safePop()) |
| 78 | +} |
| 79 | + |
| 80 | +runAllTests() |
0 commit comments