 NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
   var s = "abc あかさた"
   if true {
+    // The largest buffer that can not accomodate the string plus null terminator.
     let bufferLength = 16
     var buffer = Array(
       count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
-    var result = s.getCString(&buffer, maxLength: 100,
-        encoding: NSUTF8StringEncoding)
+    let result = s.getCString(&buffer, maxLength: 100,
+      encoding: NSUTF8StringEncoding)
     expectFalse(result)
   }
   if true {
+    // The smallest buffer where the result can fit.
     let bufferLength = 17
     var expectedStr = map("abc あかさた\0".utf8) { CChar(bitPattern: $0) }
     while (expectedStr.count != bufferLength) {

    }
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    var result = s.getCString(&buffer, maxLength: 100,
        encoding: NSUTF8StringEncoding)
    expectTrue(result)
    expectTrue(equal(expectedStr, buffer))
  }
  if true {
    let bufferLength = 100
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    var result = s.getCString(&buffer, maxLength: 8,
        encoding: NSUTF8StringEncoding)
    expectFalse(result)
  }
  if true {
    let illFormedUTF16: String = NonContiguousNSString([ 0xd800 ])
    let bufferLength = 16
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    var result = s.getCString(&buffer, maxLength: 100,
      encoding: NSUTF8StringEncoding)
    expectFalse(result)
  }

    }
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    let result = s.getFileSystemRepresentation(
      &buffer, maxLength: bufferLength)
    expectTrue(result)
    expectTrue(equal(expectedStr, buffer))
  }
  if true {
    // Limit buffer size with 'maxLength'.
    let bufferLength = 100
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    let result = s.getFileSystemRepresentation(&buffer, maxLength: 19)
    expectFalse(result)
  }
  if true {
    // String with unpaired surrogates.
    let illFormedUTF16: String = NonContiguousNSString([ 0xd800 ])
    let bufferLength = 100
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    let result = illFormedUTF16.getFileSystemRepresentation(
      &buffer, maxLength: 100)
    expectFalse(result)
  }
}

