 // RUN: mkdir -p %t
 // RUN: %target-build-swift %s -parse-stdlib -Xfrontend -disable-access-control -o %t/a.out -Xlinker -dead_strip
-// RUN: %target-run %t/a.out env | FileCheck %s
-// RUN: %target-run %t/a.out ru_RU.UTF-8 | FileCheck %s
+// RUN: %target-run %t/a.out env %s
+// RUN: %target-run %t/a.out ru_RU.UTF-8 %s
 // REQUIRES: executable_test
 
 // XFAIL: linux
 
 import Swift
 import Darwin
-
-// Interpret the command line arguments.
+import StdlibUnittest
+
+let PrintTests = TestSuite("Print")
+
 let arg = Process.arguments[1]
-
 if arg == "env" {
   setlocale(LC_ALL, "")
 } else {
+  expectEqual("ru_RU.UTF-8", arg)
   setlocale(LC_ALL, arg)
 }
-
-import StdlibUnittest
-let PrintTests = TestSuite("Print")
 
 PrintTests.test("stdlib types have description") {
   func hasDescription(any: Any) {

    ClassPrintable(2), ClassPrintable(3) ] as Array<AnyObject>)
}

func test_DictionaryPrinting() {
  var dictSI: Dictionary<String, Int> = [:]
  printedIs(dictSI, "[:]")
  debugPrintedIs(dictSI, "[:]")

  dictSI = [ "aaa": 1 ]
  printedIs(dictSI, "[\"aaa\": 1]")
  debugPrintedIs(dictSI, "[\"aaa\": 1]")

  dictSI = [ "aaa": 1, "bbb": 2 ]
  printedIs(dictSI, "[\"aaa\": 1, \"bbb\": 2]", expected2: "[\"bbb\": 2, \"aaa\": 1]")
  debugPrintedIs(dictSI, "[\"aaa\": 1, \"bbb\": 2]", expected2: "[\"bbb\": 2, \"aaa\": 1]")

  let dictSS = [ "aaa": "bbb" ]
  printedIs(dictSS, "[\"aaa\": \"bbb\"]")
  debugPrintedIs(dictSS, "[\"aaa\": \"bbb\"]")

  print("test_DictionaryPrinting done")
}
test_DictionaryPrinting()
// CHECK: test_DictionaryPrinting done

func test_SetPrinting() {
  var sI = Set<Int>()
  printedIs(sI, "[]")
  debugPrintedIs(sI, "Set([])")

  sI = Set<Int>([11, 22])
  printedIs(sI, "[11, 22]", expected2: "[22, 11]")
  debugPrintedIs(sI, "Set([11, 22])", expected2: "Set([22, 11])")

  let sS = Set<String>(["Hello", "world"])
  printedIs(sS, "[\"Hello\", \"world\"]", expected2: "[\"world\", \"Hello\"]")
  debugPrintedIs(sS, "Set([\"Hello\", \"world\"])", expected2: "Set([\"world\", \"Hello\"])")

  print("test_SetPrinting done")
}
test_SetPrinting()
// CHECK: test_SetPrinting done

func test_TuplePrinting() {
  let tuple1 = (42, ())
  printedIs(tuple1, "(42, ())")

  let tuple2 = ((), 42)
  printedIs(tuple2, "((), 42)")

  let tuple3 = (42, StructPrintable(3))
  printedIs(tuple3, "(42, ►3◀︎)")

  let tuple4 = (42, LargeStructPrintable(10, 20, 30, 40))
  printedIs(tuple4, "(42, <10 20 30 40>)")

  let tuple5 = (42, ClassPrintable(3))
  printedIs(tuple5, "(42, ►3◀︎)")

  let tuple6 = ([123: 123], (1, 2, "3"))
  printedIs(tuple6, "([123: 123], (1, 2, \"3\"))")

  let arrayOfTuples1 =
      [ (1, "two", StructPrintable(3), StructDebugPrintable(4),
         WithoutDescription(5)) ]
  printedIs(arrayOfTuples1, "[(1, \"two\", ►3◀︎, ►4◀︎, a.WithoutDescription(x: 5))]")

  let arrayOfTuples2 =
      [ (1, "two", WithoutDescription(3)),
        (11, "twenty-two", WithoutDescription(33)),
        (111, "two hundred twenty-two", WithoutDescription(333)) ]
  printedIs(arrayOfTuples2, "[(1, \"two\", a.WithoutDescription(x: 3)), (11, \"twenty-two\", a.WithoutDescription(x: 33)), (111, \"two hundred twenty-two\", a.WithoutDescription(x: 333))]")

  print("test_TuplePrinting done")
}
test_TuplePrinting()
// CHECK: test_TuplePrinting done

func test_ArbitraryStructPrinting() {
  let arrayOfArbitraryStructs =
    [ WithoutDescription(1), WithoutDescription(2), WithoutDescription(3) ]
  printedIs(
    arrayOfArbitraryStructs,
    "[a.WithoutDescription(x: 1), a.WithoutDescription(x: 2), a.WithoutDescription(x: 3)]")
  debugPrintedIs(
    arrayOfArbitraryStructs,
    "[a.WithoutDescription(x: 1), a.WithoutDescription(x: 2), a.WithoutDescription(x: 3)]")

  printedIs(
    EmptyStructWithoutDescription(),
    "EmptyStructWithoutDescription()")
  debugPrintedIs(
    EmptyStructWithoutDescription(),
    "a.EmptyStructWithoutDescription()")

  printedIs(
    ValuesWithoutDescription(1.25, "abc", [ 1, 2, 3 ]),
    "ValuesWithoutDescription<Double, String, Array<Int>>(t: 1.25, u: \"abc\", v: [1, 2, 3])")
  debugPrintedIs(
    ValuesWithoutDescription(1.25, "abc", [ 1, 2, 3 ]),
    "a.ValuesWithoutDescription<Swift.Double, Swift.String, Swift.Array<Swift.Int>>(t: 1.25, u: \"abc\", v: [1, 2, 3])")

  print("test_ArbitraryStructPrinting done")
}
test_ArbitraryStructPrinting()
// CHECK: test_ArbitraryStructPrinting done

func test_MetatypePrinting() {
  printedIs(Int.self, "Int")
  debugPrintedIs(Int.self, "Swift.Int")

  print("test_MetatypePrinting done")
}
test_MetatypePrinting()
// CHECK: test_MetatypePrinting done

func test_StringInterpolation() {
  assertEquals("1", "\(1)")
  assertEquals("2", "\(1 + 1)")
  assertEquals("aaa1bbb2ccc", "aaa\(1)bbb\(2)ccc")

  assertEquals("1.0", "\(1.0)")
  assertEquals("1.5", "\(1.5)")
  assertEquals("1e-12", "\(1.0 / (1000000000000))")

  assertEquals("inf", "\(1 / 0.0)")
  assertEquals("-inf", "\(-1 / 0.0)")
  assertEquals("nan", "\(0 / 0.0)")

  assertEquals("<[►1◀︎, ►2◀︎, ►3◀︎]>", "<\([ StructPrintable(1), StructPrintable(2), StructPrintable(3) ])>")
  assertEquals("WithoutDescription(x: 1)", "\(WithoutDescription(1))")

  print("test_StringInterpolation done")
}
test_StringInterpolation()
// CHECK: test_StringInterpolation done

struct MyString : StringLiteralConvertible, StringInterpolationConvertible {
  init(str: String) {

}

PrintTests.test("optional strings") {
  expectPrinted("nil", String!())
  expectPrinted("meow", String!("meow"))
  expectPrinted("nil", String?())
  expectPrinted("Optional(\"meow\")", String?("meow"))
}

PrintTests.test("custom string convertible structs") {
