<commit_before>package io.sphere.mongo.format

import java.util.Locale
import io.sphere.mongo.format.DefaultMongoFormats._
import io.sphere.mongo.generic._
import io.sphere.util.LangTag
import org.bson.BasicBSONObject
import org.bson.types.BasicBSONList
import org.scalacheck.Gen
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

import scala.collection.JavaConverters._

object DefaultMongoFormatsTest {
  case class User(name: String)
  object User {
    implicit val mongo: MongoFormat[User] = mongoProduct(apply _)
  }
}

class DefaultMongoFormatsTest extends AnyWordSpec with Matchers with ScalaCheckDrivenPropertyChecks {
  import DefaultMongoFormatsTest._

  "DefaultMongoFormats" must {
    "support List[String]" in {
      val format = listFormat[String]
      val list = Gen.listOf(Gen.alphaNumStr)

      forAll(list) { l =>
        val dbo = format.toMongoValue(l)
        dbo.asInstanceOf[BasicBSONList].asScala.toList must be (l)
        val resultList = format.fromMongoValue(dbo)
        resultList must be (l)
      }
    }

    "support List[A: MongoFormat]" in {
      val format = listFormat[User]
      val list = Gen.listOf(Gen.alphaNumStr.map(User.apply))

      check(list, format)
    }

    "support Set[String]" in {
      val format = setFormat[String]
      val set = Gen.listOf(Gen.alphaNumStr).map(_.toSet)

      forAll(set) { s =>
        val dbo = format.toMongoValue(s)
        dbo.asInstanceOf[BasicBSONList].asScala.toSet must be (s)
        val resultSet = format.fromMongoValue(dbo)
        resultSet must be (s)
      }
    }

    "support Set[A: MongoFormat]" in {
      val format = setFormat[User]
      val set = Gen.listOf(Gen.alphaNumStr.map(User.apply)).map(_.toSet)

      check(set, format)
    }

    "support Map[String, String]" in {
      val format = mapFormat[String]<commit_msg>Add missing unit test for MongoFormat[Vector[_]]<commit_after>package io.sphere.mongo.format

import java.util.Locale
import io.sphere.mongo.format.DefaultMongoFormats._
import io.sphere.mongo.generic._
import io.sphere.util.LangTag
import org.bson.BasicBSONObject
import org.bson.types.BasicBSONList
import org.scalacheck.Gen
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

import scala.collection.JavaConverters._

object DefaultMongoFormatsTest {
  case class User(name: String)
  object User {
    implicit val mongo: MongoFormat[User] = mongoProduct(apply _)
  }
}

class DefaultMongoFormatsTest extends AnyWordSpec with Matchers with ScalaCheckDrivenPropertyChecks {
  import DefaultMongoFormatsTest._

  "DefaultMongoFormats" must {
    "support List[String]" in {
      val format = listFormat[String]
      val list = Gen.listOf(Gen.alphaNumStr)

      forAll(list) { l =>
        val dbo = format.toMongoValue(l)
        dbo.asInstanceOf[BasicBSONList].asScala.toList must be (l)
        val resultList = format.fromMongoValue(dbo)
        resultList must be (l)
      }
    }

    "support List[A: MongoFormat]" in {
      val format = listFormat[User]
      val list = Gen.listOf(Gen.alphaNumStr.map(User.apply))

      check(list, format)
    }

    "support Vector[String]" in {
      val format = vecFormat[String]
      val vector = Gen.listOf(Gen.alphaNumStr).map(_.toVector)

      forAll(vector) { v =>
        val dbo = format.toMongoValue(v)
        dbo.asInstanceOf[BasicBSONList].asScala.toVector must be (v)
        val resultVector = format.fromMongoValue(dbo)
        resultVector must be (v)
      }
    }

    "support Vector[A: MongoFormat]" in {
      val format = vecFormat[User]
      val vector = Gen.listOf(Gen.alphaNumStr.map(User.apply)).map(_.toVector)

      check(vector, format)
    }

    "support Set[String]" in {
      val format = setFormat[String]
      val set = Gen.listOf(Gen.alphaNumStr).map(_.toSet)

      forAll(set) { s =>
        val dbo = format.toMongoValue(s)
        dbo.asInstanceOf[BasicBSONList].asScala.toSet must be (s)
        val resultSet = format.fromMongoValue(dbo)
        resultSet must be (s)
      }
    }

    "support Set[A: MongoFormat]" in {
      val format = setFormat[User]
      val set = Gen.listOf(Gen.alphaNumStr.map(User.apply)).map(_.toSet)

      check(set, format)
    }

    "support Map[String, String]" in {
      val format = mapFormat[String]
{'fraction_non_alphanumeric': 0.10200892857142857, 'fraction_numerical': 0.0, 'mean_word_length': 3.239356669820246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1794863', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1472, 'n_words': 301}