<commit_before>package models

import generator.ScalaService
import org.scalatest.{ ShouldMatchers, FunSpec }

class Play2JsonSpec extends FunSpec with ShouldMatchers {

  describe("for models with lists") {

    val json = """
    {
      "base_url": "http://localhost:9000",
      "name": "Api Doc Test",

      "models": {
        "content": {
          "fields": [
            { "name": "required_tags", "type": "[string]" },
            { "name": "optional_tags", "type": "[string]", "required": false },
            { "name": "data", "type": "map[long]", "required": false }
          ]
        }
      }
    }
    """

    it("generates valid json readers") {
      val ssd = TestHelper.scalaService(json)
      val model = ssd.models.head
      TestHelper.assertEqualsFile(
        "test/resources/play2-json-spec-model-readers.txt",
        Play2Json("Api Doc Test", model).fieldReaders()
      )
    }

  }

  describe("quality schema") {

    lazy val quality = new ScalaService(TestHelper.parseFile("test/resources/examples/quality.json"))

    describe("plan") {

      lazy val plan = quality.models.find(_.name == "Plan").get

      it("readers") {
        TestHelper.assertEqualsFile(
          "test/resources/generators/play-2-json-spec-quality-plan-readers.txt",
          Play2Json(quality.name, plan).readers()
        )
      }

      it("writers") {
        TestHelper.assertEqualsFile(<commit_msg>Update unit test to service.json<commit_after>package models

import generator.ScalaService
import org.scalatest.{ ShouldMatchers, FunSpec }

class Play2JsonSpec extends FunSpec with ShouldMatchers {

  describe("for models with lists") {

    val json = """
    {
      "base_url": "http://localhost:9000",
      "name": "Api Doc Test",
      "namespace": "test.apidoc.apidoctest",

      "models": [
        {
          "name": "content",
          "plural": "contents",
          "fields": [
            { "name": "required_tags", "type": "[string]", "required": true },
            { "name": "optional_tags", "type": "[string]", "required": false },
            { "name": "data", "type": "map[long]", "required": false }
          ]
        }
      ]
    }
    """

    it("generates valid json readers") {
      val ssd = TestHelper.scalaService(json)
      val model = ssd.models.head
      TestHelper.assertEqualsFile(
        "test/resources/play2-json-spec-model-readers.txt",
        Play2Json("Api Doc Test", model).fieldReaders()
      )
    }

  }

  describe("quality schema") {

    lazy val quality = new ScalaService(TestHelper.parseFile("test/resources/examples/quality.json"))

    describe("plan") {

      lazy val plan = quality.models.find(_.name == "Plan").get

      it("readers") {
        TestHelper.assertEqualsFile(
          "test/resources/generators/play-2-json-spec-quality-plan-readers.txt",
          Play2Json(quality.name, plan).readers()
        )
      }

      it("writers") {
        TestHelper.assertEqualsFile(
{'fraction_non_alphanumeric': 0.15131136516476126, 'fraction_numerical': 0.00605245460659045, 'mean_word_length': 2.4552845528455283, 'pattern_counts': {'":': 29, '<': 3, '<?xml version=': 0, '>': 3, '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': '4133380', 'n_tokens_mistral': 911, 'n_tokens_neox': 879, 'n_words': 172}