 import Darwin
 
 // Interpret the command line arguments.
-var arg = Process.arguments[1]
+let arg = Process.arguments[1]
 
 if arg == "env" {
   setlocale(LC_ALL, "")

  }
}

func test_StdlibTypesPrinted() {
  printedIs(Float(1.0), "1.0")
  printedIs(Float(-1.0), "-1.0")
  printedIs(Double(1.0), "1.0")
  printedIs(Double(-1.0), "-1.0")

  printedIs(CChar(42), "42")
  printedIs(CUnsignedChar(42), "42")
  printedIs(CUnsignedShort(42), "42")
  printedIs(CUnsignedInt(42), "42")
  printedIs(CUnsignedLong(42), "42")
  printedIs(CUnsignedLongLong(42), "42")
  printedIs(CSignedChar(42), "42")
  printedIs(CShort(42), "42")
  printedIs(CInt(42), "42")
  printedIs(CLong(42), "42")
  printedIs(CLongLong(42), "42")
  printedIs(CFloat(1.0), "1.0")
  printedIs(CFloat(-1.0), "-1.0")
  printedIs(CDouble(1.0), "1.0")
  printedIs(CDouble(-1.0), "-1.0")

  printedIs(CWideChar(42), "*")
  printedIs(CChar16(42), "42")
  printedIs(CChar32(42), "*")
  printedIs(CBool(true), "true")
  printedIs(CBool(false), "false")

  var s: String = "abc"
  printedIs(s, "abc")
  debugPrintedIs(s, "\"abc\"")
  s = "\\ \' \" \0 \n \r \t \u{05}"
  debugPrintedIs(s, "\"\\\\ \\\' \\\" \\0 \\n \\r \\t \\u{05}\"")

  let ch: Character = "a"
  printedIs(ch, "a")
  debugPrintedIs(ch, "\"a\"")

  var us: UnicodeScalar = "a"
  printedIs(us, "a")
  debugPrintedIs(us, "\"a\"")
  us = "\\"
  printedIs(us, "\\")
  assertEquals("\"\\\\\"", us.description)
  debugPrintedIs(us, "\"\\\\\"")
  us = "あ"
  printedIs(us, "あ")
  assertEquals("\"あ\"", us.description)
  debugPrintedIs(us, "\"\\u{3042}\"")

  do {
    var implicitlyUnwrappedString: String! = nil
    printedIs(implicitlyUnwrappedString, "nil")
    implicitlyUnwrappedString = "meow"
    printedIs(implicitlyUnwrappedString, "meow")
  }
  do {
    var optionalString: String? = nil
    printedIs(optionalString, "nil")
    optionalString = "meow"
    printedIs(optionalString, "Optional(\"meow\")")
  }
  do {
    struct Wrapper : CustomStringConvertible {
      var x: CustomStringConvertible? = nil

      var description: String {
        return "Wrapper(" + x.debugDescription + ")"
      }
    }
    printedIs(Wrapper(), "Wrapper(nil)")
    printedIs(Wrapper(x: Wrapper()), "Wrapper(Optional(Wrapper(nil)))")
    printedIs(Wrapper(x: Wrapper(x: Wrapper())),
        "Wrapper(Optional(Wrapper(Optional(Wrapper(nil)))))")
  }

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

func test_IntegerPrinting() {
  if (UInt64(Int.max) > 0x1_0000_0000 as UInt64) {
    printedIs(Int.min, "-9223372036854775808")
    printedIs(Int.max, "9223372036854775807")
  } else {
    printedIs(Int.min, "-2147483648")
    printedIs(Int.max, "2147483647")
  }
  printedIs(Int(0), "0")
  printedIs(Int(42), "42")
  printedIs(Int(-42), "-42")

  if (UInt64(UInt.max) > 0x1_0000_0000 as UInt64) {
    printedIs(UInt.max, "18446744073709551615")
  } else {
    printedIs(UInt.max, "4294967295")
  }
  printedIs(UInt.min, "0")
  printedIs(UInt(0), "0")
  printedIs(UInt(42), "42")

  printedIs(Int8.min, "-128")
  printedIs(Int8.max, "127")
  printedIs(Int8(0), "0")
  printedIs(Int8(42), "42")
  printedIs(Int8(-42), "-42")

  printedIs(UInt8.min, "0")
  printedIs(UInt8.max, "255")
  printedIs(UInt8(0), "0")
  printedIs(UInt8(42), "42")

  printedIs(Int16.min, "-32768")
  printedIs(Int16.max, "32767")
  printedIs(Int16(0), "0")
  printedIs(Int16(42), "42")
  printedIs(Int16(-42), "-42")

  printedIs(UInt16.min, "0")
  printedIs(UInt16.max, "65535")
  printedIs(UInt16(0), "0")
  printedIs(UInt16(42), "42")

  printedIs(Int32.min, "-2147483648")
  printedIs(Int32.max, "2147483647")
  printedIs(Int32(0), "0")
  printedIs(Int32(42), "42")
  printedIs(Int32(-42), "-42")

  printedIs(UInt32.min, "0")
  printedIs(UInt32.max, "4294967295")
  printedIs(UInt32(0), "0")
  printedIs(UInt32(42), "42")

  printedIs(Int64.min, "-9223372036854775808")
  printedIs(Int64.max, "9223372036854775807")
  printedIs(Int64(0), "0")
  printedIs(Int64(42), "42")
  printedIs(Int64(-42), "-42")

  printedIs(UInt64.min, "0")
  printedIs(UInt64.max, "18446744073709551615")
  printedIs(UInt64(0), "0")
  printedIs(UInt64(42), "42")

  printedIs(Int8(-42), "-42")
  printedIs(Int16(-42), "-42")
  printedIs(Int32(-42), "-42")
  printedIs(Int64(-42), "-42")
  printedIs(UInt8(42), "42")
  printedIs(UInt16(42), "42")
  printedIs(UInt32(42), "42")
  printedIs(UInt64(42), "42")

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

func test_FloatingPointPrinting() {
  func asFloat32(f: Float32) -> Float32 { return f }

  setlocale(LC_ALL, arg)
}

import StdlibUnittest
let PrintTests = TestSuite("Print")

PrintTests.test("stdlib types have description") {
  func hasDescription(any: Any) {
    expectTrue(any is CustomStringConvertible)
  }

  hasDescription(Int(42))
  hasDescription(UInt(42))
