<commit_before>import XCTest
@testable import Prelude

private let square: (Int) -> Int = { $0 * $0 }
private let add: (Int) -> (Int) -> Int = { lhs in { lhs + $0 } }
private let incr: (Int) -> Int = add(1)

final class LensTests: XCTestCase {
  private let user = User(id: 1, location: Location(id: 2, city: City(id: 3)), name: "blob")

  func testLensComposition() {
    XCTAssertEqual(2, User._location.compose(Location._id).view(user))
    XCTAssertEqual(3, User._location.compose(Location._city.compose(City._id)).view(user))
  }

  func testLensCompositionOperator() {
    XCTAssertEqual(2, (User._location • Location._id).view(user))
    XCTAssertEqual(3, (User._location • Location._city • City._id).view(user))
  }

  func testLensSetOperator() {
    XCTAssertEqual(4, (User._id .~ 4)(user).id)
  }

  func testLensSetAndCompositionOperatorPrecedence() {
    XCTAssertEqual(4, ((User._location • Location._id) .~ 4)(user).location.id)
  }

  func testLensViewOperator() {
    XCTAssertEqual(1, user ^* User._id)
  }

  func testLensViewAndCompositionOperatorPrecedence() {
    XCTAssertEqual(2, user ^* User._location • Location._id)
  }

  func testComporator() {
    let user1 = user |> User._name .~ "blob"
    let user2 = user |> User._name .~ "glob"

    XCTAssert(user1 < user2)
    XCTAssert(user1 < user1)
    XCTAssertFalse(user2 < user1)
  }

  func testOver() {
    XCTAssertEqual(2, User._id.over(incr)(user).id)
  }

  func testOverOperator() {
    XCTAssertEqual(2, (User._id %~ incr)(user).id)
  }

  func testOverAndCompositionOperatorPrecedence() {
    XCTAssertEqual(3, ((User._location • Location._id) %~ incr)(user).location.id)
  }

  func testOperatorPrecedences() {
    XCTAssertEqual(User(id: 11, location: Location(id: 12, city: City(id: 13)), name: "brando"),
      user
        |> User._id %~ add(10)
        |> (User._location • Location._id) %~ square
        |> (User._location • Location._id) %~ add(8)
        |> (User._location • Location._city • City._id) .~ 13
        |> User._name .~ "brando"
    )

    XCTAssertEqual(13,
      user
        |> User._id %~ add(10)
        |> (User._location • Location._id) %~ square
        |> (User._location • Location._id) %~ add(8)
        |> (User._location • Location._city • City._id) .~ 13
        ^* (User._location • Location._city • City._id)
    )
  }

  func testSemigroupOperator() {
    XCTAssertEqual(user.name + "!", (user |> User._name <>~ "!").name)
  }
}

private struct User: Equatable {
  let id: Int
  let location: Location
  let name: String

  static let _id = Lens<User, Int>(
    view: { $0.id },<commit_msg>Updated some deprecated operators.<commit_after>import XCTest
@testable import Prelude

private let square: (Int) -> Int = { $0 * $0 }
private let add: (Int) -> (Int) -> Int = { lhs in { lhs + $0 } }
private let incr: (Int) -> Int = add(1)

final class LensTests: XCTestCase {
  private let user = User(id: 1, location: Location(id: 2, city: City(id: 3)), name: "blob")

  func testLensComposition() {
    XCTAssertEqual(2, User._location.compose(Location._id).view(user))
    XCTAssertEqual(3, User._location.compose(Location._city.compose(City._id)).view(user))
  }

  func testLensCompositionOperator() {
    XCTAssertEqual(2, (User._location..Location._id).view(user))
    XCTAssertEqual(3, (User._location..Location._city..City._id).view(user))
  }

  func testLensSetOperator() {
    XCTAssertEqual(4, (User._id .~ 4)(user).id)
  }

  func testLensSetAndCompositionOperatorPrecedence() {
    XCTAssertEqual(4, ((User._location..Location._id) .~ 4)(user).location.id)
  }

  func testLensViewOperator() {
    XCTAssertEqual(1, user ^* User._id)
  }

  func testLensViewAndCompositionOperatorPrecedence() {
    XCTAssertEqual(2, user ^* User._location..Location._id)
  }

  func testComporator() {
    let user1 = user |> User._name .~ "blob"
    let user2 = user |> User._name .~ "glob"

    XCTAssert(user1 < user2)
    XCTAssert(user1 < user1)
    XCTAssertFalse(user2 < user1)
  }

  func testOver() {
    XCTAssertEqual(2, User._id.over(incr)(user).id)
  }

  func testOverOperator() {
    XCTAssertEqual(2, (User._id %~ incr)(user).id)
  }

  func testOverAndCompositionOperatorPrecedence() {
    XCTAssertEqual(3, ((User._location..Location._id) %~ incr)(user).location.id)
  }

  func testOperatorPrecedences() {
    XCTAssertEqual(User(id: 11, location: Location(id: 12, city: City(id: 13)), name: "brando"),
      user
        |> User._id %~ add(10)
        |> (User._location..Location._id) %~ square
        |> (User._location..Location._id) %~ add(8)
        |> (User._location..Location._city..City._id) .~ 13
        |> User._name .~ "brando"
    )

    XCTAssertEqual(13,
      user
        |> User._id %~ add(10)
        |> (User._location..Location._id) %~ square
        |> (User._location..Location._id) %~ add(8)
        |> (User._location..Location._city..City._id) .~ 13
        ^* (User._location..Location._city..City._id)
    )
  }

  func testSemigroupOperator() {
    XCTAssertEqual(user.name + "!", (user |> User._name <>~ "!").name)
  }
}

private struct User: Equatable {
  let id: Int
  let location: Location
  let name: String

  static let _id = Lens<User, Int>(
    view: { $0.id },
{'fraction_non_alphanumeric': 0.1605268180950563, 'fraction_numerical': 0.01794235541133804, 'mean_word_length': 3.2497972424979724, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 39, 'https://': 0, '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': '4249452', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1835, 'n_words': 373}