<commit_before><commit_msg>Add test for custom generic picklers<commit_after>
import scala.pickling._
import binary._

import org.scalatest.FunSuite


case class MyClass[A](myString: String, a: A)

class MyClassPickler[A](implicit val format: PickleFormat, aTypeTag: FastTypeTag[A],
                                     aPickler: SPickler[A], aUnpickler: Unpickler[A])
  extends SPickler[MyClass[A]] with Unpickler[MyClass[A]] {

  private val stringUnpickler = implicitly[Unpickler[String]]

  override def pickle(picklee: MyClass[A], builder: PBuilder) = {
    builder.beginEntry(picklee)

    builder.putField("myString",
      b => b.hintTag(FastTypeTag.ScalaString).beginEntry(picklee.myString).endEntry()
    )

    builder.putField("a",
      b => {      
        b.hintTag(aTypeTag)
        aPickler.pickle(picklee.a, b)
      }
    )

    builder.endEntry()
  }

  override def unpickle(tag: => FastTypeTag[_], reader: PReader): MyClass[A] = {
    reader.hintTag(FastTypeTag.ScalaString)
    val tag = reader.beginEntry()
	  val myStringUnpickled = stringUnpickler.unpickle(tag, reader).asInstanceOf[String]
	  reader.endEntry()

    reader.hintTag(aTypeTag)
    val aTag = reader.beginEntry()
    val aUnpickled = aUnpickler.unpickle(aTag, reader).asInstanceOf[A]
    reader.endEntry()

    MyClass(myStringUnpickled, aUnpickled)
  }

}


class CustomGenericPicklerTest extends FunSuite {

  implicit def myClassPickler[A: SPickler: Unpickler: FastTypeTag](implicit pf: PickleFormat) =
    new MyClassPickler

  test("main") {
    val inst = MyClass("test", 42)
    val pickle = inst.pickle
    val up = pickle.unpickle[MyClass[Int]]
    assert(up.toString === inst.toString)
  }
}
{'fraction_non_alphanumeric': 0.1159077468953282, 'fraction_numerical': 0.0011827321111768185, 'mean_word_length': 3.7262569832402233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3399072', 'n_tokens_mistral': 594, 'n_tokens_neox': 572, 'n_words': 107}