Repository: apple/swift
File: test/Interop/Cxx/stdlib/use-std-pair.swift (Swift)

Code before:
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-6)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++14)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++17)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20)

// REQUIRES: executable_test

import StdlibUnittest
import StdPair
import CxxStdlib
import Cxx

var StdPairTestSuite = TestSuite("StdPair")

func takePair(_ _: consuming any CxxPair & ~Copyable) {}

StdPairTestSuite.test("StdPairInts.init") {
  let pi = PairInts(first: 1, second: 2)
  takePair(pi)
  expectEqual(pi.first, 1)
  expectEqual(pi.second, 2)
}

StdPairTestSuite.test("StdPairStrings.init") {
  let ps = PairStrings(first: std.string(), second: std.string())
  expectEqual(ps.first, std.string())
  expectEqual(ps.second, std.string())

  let ps2 = PairStrings(first: std.string("abc"), second: std.string("123"))
  expectEqual(ps2.first, std.string("abc"))
  expectEqual(ps2.second, std.string("123"))
}

StdPairTestSuite.test("StdPair.elements") {
  var pi = getIntPair()
  expectEqual(pi.first, -5)
  expectEqual(pi.second, 12)
  pi.first = 11
  expectEqual(pi.first, 11)
  expectEqual(pi.second, 12)

Review comment (suggestion):
Can you add some assertions in here too?

Eg make this take two extra args and assert equality? Just so that this is actually doing some runtime checking too. 

Code after:
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-6)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++14)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++17)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20)

// REQUIRES: executable_test
// FIXME importing a move-only std::pair into Swift causes a crash in the MoveOnlyChecker, in Linux
// REQUIRES: OS=macosx || OS=windows-msvc

import StdlibUnittest
import StdPair
import CxxStdlib
import Cxx

var StdPairTestSuite = TestSuite("StdPair")

func takePair<T: CxxPair & ~Copyable>(_ _: consuming T) { }

StdPairTestSuite.test("StdPairInts.init") {
  let pi = PairInts(first: 1, second: 2)
  takePair(pi)
  expectEqual(pi.first, 1)
  expectEqual(pi.second, 2)
}

StdPairTestSuite.test("StdPairStrings.init") {
  let ps = PairStrings(first: std.string(), second: std.string())
  expectEqual(ps.first, std.string())
  expectEqual(ps.second, std.string())

  let ps2 = PairStrings(first: std.string("abc"), second: std.string("123"))
  expectEqual(ps2.first, std.string("abc"))
  expectEqual(ps2.second, std.string("123"))
}

StdPairTestSuite.test("StdPair.elements") {
  var pi = getIntPair()
  expectEqual(pi.first, -5)
  expectEqual(pi.second, 12)
  pi.first = 11