<commit_before>/*
 This source file is part of the Swift System open source project

 Copyright (c) 2020 Apple Inc. and the Swift System project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See https://swift.org/LICENSE.txt for license information
*/

// Tests for PlatformString, SystemString, and FilePath's forwarding APIs

// TODO: Adapt test to Windows

import XCTest

#if SYSTEM_PACKAGE
@testable import SystemPackage
#else
@testable import System
#endif

private func makeRaw(
  _ str: String
) -> [CInterop.PlatformChar] {
  var str = str
  var array = str.withUTF8 { $0.withMemoryRebound(to: CChar.self, Array.init) }
  array.append(0)
  return array
}
private func makeStr(
  _ raw: [CInterop.PlatformChar]
) -> String {
  precondition((raw.last ?? 0) == 0)
  // FIXME: Unfortunately, this relies on some of the same mechanisms tested...
  return raw.withUnsafeBufferPointer {
    String(platformString: $0.baseAddress!)
  }
}

struct StringTest: TestCase {<commit_msg>Tests: change the conversion for string to array<commit_after>/*
 This source file is part of the Swift System open source project

 Copyright (c) 2020 Apple Inc. and the Swift System project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See https://swift.org/LICENSE.txt for license information
*/

// Tests for PlatformString, SystemString, and FilePath's forwarding APIs

// TODO: Adapt test to Windows

import XCTest

#if SYSTEM_PACKAGE
@testable import SystemPackage
#else
@testable import System
#endif

private func makeRaw(
  _ str: String
) -> [CInterop.PlatformChar] {
  var str = str
#if os(Windows)
  var array = Array(str.utf16)
#else
  var array = str.withUTF8 { $0.withMemoryRebound(to: CChar.self, Array.init) }
#endif
  array.append(0)
  return array
}
private func makeStr(
  _ raw: [CInterop.PlatformChar]
) -> String {
  precondition((raw.last ?? 0) == 0)
  // FIXME: Unfortunately, this relies on some of the same mechanisms tested...
  return raw.withUnsafeBufferPointer {
    String(platformString: $0.baseAddress!)
  }
}

struct StringTest: TestCase {
{'fraction_non_alphanumeric': 0.09258384506376949, 'fraction_numerical': 0.01228153046764289, 'mean_word_length': 4.153284671532846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4140087', 'n_tokens_mistral': 657, 'n_tokens_neox': 623, 'n_words': 230}