<commit_before>package monocle

import monocle.macros.{GenLens, Lenses, PLenses}
import monocle.macros.syntax.lens._
import shapeless.test.illTyped

class LensMonoExample extends MonocleSuite {

  // @Lenses generate Lens automatically in the companion object
  @Lenses case class Address(streetNumber: Int, streetName: String)
  @Lenses case class Person(name: String, age: Int, address: Address)

  object Manual { // Lens created manually (i.e. without macro)
    val _name = Lens[Person, String](_.name)(n => p => p.copy(name = n))
    val _age = Lens[Person, Int](_.age)(a => p => p.copy(age = a))
    val _address = Lens[Person, Address](_.address)(a => p => p.copy(address = a))
    val _streetNumber = Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
  }

  object Semi { // Lens generated semi automatically using GenLens macro
    val name = GenLens[Person](_.name)
    val age = GenLens[Person](_.age)
    val address = GenLens[Person](_.address)
    val streetNumber = GenLens[Address](_.streetNumber)
  }

  val john = Person("John", 30, Address(126, "High Street"))

  test("get") {
    Manual._name.get(john) shouldEqual "John"
    Semi.name.get(john)    shouldEqual "John"
    Person.name.get(john)  shouldEqual "John"
    john.lens(_.name).get  shouldEqual "John"
  }

  test("set") {
    val changedJohn = john.copy(age = 45)

    Manual._age.set(45)(john) shouldEqual changedJohn
    Semi.age.set(45)(john)    shouldEqual changedJohn
    Person.age.set(45)(john)  shouldEqual changedJohn
    john.lens(_.age).set(45)  shouldEqual changedJohn
  }

  test("compose") {
    (Manual._address composeLens Manual._streetNumber).get(john) shouldEqual 126
    (Semi.address composeLens Semi.streetNumber).get(john)       shouldEqual 126
    (Person.address composeLens Address.streetNumber).get(john)  shouldEqual 126
    john.lens(_.address.streetNumber).get                        shouldEqual 126
  }

  @Lenses("_") // this generates lenses prefixed with _ in the Cat companion object
  case class Cat(age: Int)

  val alpha = Cat(2)

  test("@Lenses takes an optional prefix string") {
    Cat._age.get(alpha) shouldEqual 2
  }

  test("Modifications through lenses are chainable") {
    @Lenses case class Point(x: Int, y: Int)
    import Point._

    val update = x.modify(_ + 100) compose y.set(7)
    update(Point(1,2)) shouldEqual Point(101,7)
  }

  test("@Lenses is for case classes only") {
    illTyped( """@Lenses class C""", "Invalid annotation target: must be a case class")
  }

  test("GenApplyLensOps has no collision with .value") {
    case class MyString(s: String)
    object MyString {
      implicit class Ops(self: MyString) {
        val value: String = self.s
      }
    }
    MyString("a").value shouldEqual "a"
  }
}

class LensPolyExample extends MonocleSuite {

  @PLenses case class Foo[A,B](q: Map[(A,B),Double], default: Double)

  object Manual { // Lens created manually (i.e. without macro)
  def q[A,B] = Lens((_: Foo[A,B]).q)(q => f => f.copy(q = q))
    def default[A,B] = Lens((_: Foo[A,B]).default)(d => f => f.copy(default = d))
  }

  object Semi { // Lens generated semi automatically using GenLens macro
  def q[A,B] = GenLens[Foo[A,B]](_.q)
    def default[A,B] = GenLens[Foo[A,B]](_.default)
  }

  val candyTrade = Foo(Map[(Int,Symbol),Double]((0,'Buy) -> -3.0, (12,'Sell) -> 7), 0.0)

  test("get") {
    Manual.default.get(candyTrade) shouldEqual 0.0
    Semi.default.get(candyTrade)   shouldEqual 0.0
    Foo.default.get(candyTrade)    shouldEqual 0.0
  }

  test("set") {
    val changedTrade = candyTrade.copy(q = candyTrade.q.updated((0,'Buy), -2.0))
    Foo.q.modify((_: Map[(Int,Symbol),Double]).updated((0,'Buy), -2.0))(candyTrade) shouldEqual changedTrade
  }

  test("@PLenses generates polymorphic lenses") {
    val changedTrade = candyTrade.copy(q = candyTrade.q.map{case (x, y) => (x.swap, y)})
    Foo.q.modify((_: Map[(Int, Symbol), Double]).map {case (x, y) => (x.swap, y)})(candyTrade) shouldEqual changedTrade
  }

  @PLenses("_") case class Cat(age: Int)

  val alpha = Cat(2)

  test("@PLenses takes an optional prefix string") {
    Cat._age.get(alpha) shouldEqual 2
  }
}<commit_msg>fix warnings. Symbol literal is deprecated since Scala 2.13<commit_after>package monocle

import monocle.macros.{GenLens, Lenses, PLenses}
import monocle.macros.syntax.lens._
import shapeless.test.illTyped

class LensMonoExample extends MonocleSuite {

  // @Lenses generate Lens automatically in the companion object
  @Lenses case class Address(streetNumber: Int, streetName: String)
  @Lenses case class Person(name: String, age: Int, address: Address)

  object Manual { // Lens created manually (i.e. without macro)
    val _name = Lens[Person, String](_.name)(n => p => p.copy(name = n))
    val _age = Lens[Person, Int](_.age)(a => p => p.copy(age = a))
    val _address = Lens[Person, Address](_.address)(a => p => p.copy(address = a))
    val _streetNumber = Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
  }

  object Semi { // Lens generated semi automatically using GenLens macro
    val name = GenLens[Person](_.name)
    val age = GenLens[Person](_.age)
    val address = GenLens[Person](_.address)
    val streetNumber = GenLens[Address](_.streetNumber)
  }

  val john = Person("John", 30, Address(126, "High Street"))

  test("get") {
    Manual._name.get(john) shouldEqual "John"
    Semi.name.get(john)    shouldEqual "John"
    Person.name.get(john)  shouldEqual "John"
    john.lens(_.name).get  shouldEqual "John"
  }

  test("set") {
    val changedJohn = john.copy(age = 45)

    Manual._age.set(45)(john) shouldEqual changedJohn
    Semi.age.set(45)(john)    shouldEqual changedJohn
    Person.age.set(45)(john)  shouldEqual changedJohn
    john.lens(_.age).set(45)  shouldEqual changedJohn
  }

  test("compose") {
    (Manual._address composeLens Manual._streetNumber).get(john) shouldEqual 126
    (Semi.address composeLens Semi.streetNumber).get(john)       shouldEqual 126
    (Person.address composeLens Address.streetNumber).get(john)  shouldEqual 126
    john.lens(_.address.streetNumber).get                        shouldEqual 126
  }

  @Lenses("_") // this generates lenses prefixed with _ in the Cat companion object
  case class Cat(age: Int)

  val alpha = Cat(2)

  test("@Lenses takes an optional prefix string") {
    Cat._age.get(alpha) shouldEqual 2
  }

  test("Modifications through lenses are chainable") {
    @Lenses case class Point(x: Int, y: Int)
    import Point._

    val update = x.modify(_ + 100) compose y.set(7)
    update(Point(1,2)) shouldEqual Point(101,7)
  }

  test("@Lenses is for case classes only") {
    illTyped( """@Lenses class C""", "Invalid annotation target: must be a case class")
  }

  test("GenApplyLensOps has no collision with .value") {
    case class MyString(s: String)
    object MyString {
      implicit class Ops(self: MyString) {
        val value: String = self.s
      }
    }
    MyString("a").value shouldEqual "a"
  }
}

class LensPolyExample extends MonocleSuite {

  @PLenses case class Foo[A,B](q: Map[(A,B),Double], default: Double)

  object Manual { // Lens created manually (i.e. without macro)
  def q[A,B] = Lens((_: Foo[A,B]).q)(q => f => f.copy(q = q))
    def default[A,B] = Lens((_: Foo[A,B]).default)(d => f => f.copy(default = d))
  }

  object Semi { // Lens generated semi automatically using GenLens macro
  def q[A,B] = GenLens[Foo[A,B]](_.q)
    def default[A,B] = GenLens[Foo[A,B]](_.default)
  }

  val candyTrade = Foo(Map[(Int,Symbol),Double]((0, Symbol("Buy")) -> -3.0, (12, Symbol("Sell")) -> 7), 0.0)

  test("get") {
    Manual.default.get(candyTrade) shouldEqual 0.0
    Semi.default.get(candyTrade)   shouldEqual 0.0
    Foo.default.get(candyTrade)    shouldEqual 0.0
  }

  test("set") {
    val changedTrade = candyTrade.copy(q = candyTrade.q.updated((0, Symbol("Buy")), -2.0))
    Foo.q.modify((_: Map[(Int,Symbol),Double]).updated((0, Symbol("Buy")), -2.0))(candyTrade) shouldEqual changedTrade
  }

  test("@PLenses generates polymorphic lenses") {
    val changedTrade = candyTrade.copy(q = candyTrade.q.map{case (x, y) => (x.swap, y)})
    Foo.q.modify((_: Map[(Int, Symbol), Double]).map {case (x, y) => (x.swap, y)})(candyTrade) shouldEqual changedTrade
  }

  @PLenses("_") case class Cat(age: Int)

  val alpha = Cat(2)

  test("@PLenses takes an optional prefix string") {
    Cat._age.get(alpha) shouldEqual 2
  }
}
{'fraction_non_alphanumeric': 0.1478507321681625, 'fraction_numerical': 0.01476145488899386, 'mean_word_length': 3.6253413435281265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '3306746', 'n_tokens_mistral': 3132, 'n_tokens_neox': 2889, 'n_words': 728}