<commit_before>package lib

import com.gilt.apidoc.spec.v0.models._
import org.scalatest.{FunSpec, ShouldMatchers}

class ServiceDiffSpec extends FunSpec with ShouldMatchers {

  new play.core.StaticApplication(new java.io.File("."))

  private lazy val service = TestHelper.readService("../spec/api.json")

  it("no changes") {
    ServiceDiff(service, service).differences should be(Nil)
  }

  it("apidoc version") {
    ServiceDiff(service, service.copy(apidoc = Apidoc(version = "0.0.1"))).differences should be(
      Seq(
        Difference.NonBreaking(s"apidoc/version changed from ${service.apidoc.version} to 0.0.1")
      )
    )
  }

  it("name") {
    ServiceDiff(service, service.copy(name = "test")).differences should be(
      Seq(
        Difference.NonBreaking(s"name changed from ${service.name} to test")
      )
    )
  }

  it("organization key") {
    ServiceDiff(service, service.copy(organization = Organization(key = "foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"organization/key changed from ${service.organization.key} to foo")
      )
    )
  }

  it("application key") {
    ServiceDiff(service, service.copy(application = Application(key = "foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"application/key changed from ${service.application.key} to foo")
      )
    )
  }

  it("namespace") {
    ServiceDiff(service, service.copy(namespace = "test")).differences should be(
      Seq(
        Difference.Breaking(s"namespace changed from ${service.namespace} to test")
      )
    )
  }

  it("version") {
    ServiceDiff(service, service.copy(version = "0.0.1")).differences should be(
      Seq(
        Difference.NonBreaking(s"version changed from ${service.version} to 0.0.1")
      )
    )
  }

  it("baseUrl") {
    val base = service.copy(baseUrl = None)

    ServiceDiff(base, base.copy(baseUrl = None)).differences should be(Nil)

    ServiceDiff(base, base.copy(baseUrl = Some("http://foo.com"))).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url added: http://foo.com")
      )
    )

    ServiceDiff(base.copy(baseUrl = Some("http://foo.com")), base).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url removed: http://foo.com")
      )
    )

    ServiceDiff(
      base.copy(baseUrl = Some("http://foo.com")),
      base.copy(baseUrl = Some("http://foobar.com"))
    ).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url changed from http://foo.com to http://foobar.com")
      )
    )
  }

  it("description") {
    val base = service.copy(description = None)

    ServiceDiff(base, base.copy(description = None)).differences should be(Nil)

    ServiceDiff(base, base.copy(description = Some("foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"description added: foo")
      )
    )

    ServiceDiff(base.copy(description = Some("foo")), base).differences should be(
      Seq(
        Difference.NonBreaking(s"description removed: foo")
      )
    )

    ServiceDiff(
      base.copy(description = Some("foo")),
      base.copy(description = Some("foobar"))
    ).differences should be(
      Seq(
        Difference.NonBreaking(s"description changed from foo to foobar")
      )
    )
  }


}<commit_msg>Add initial tests for headers<commit_after>package lib

import com.gilt.apidoc.spec.v0.models._
import org.scalatest.{FunSpec, ShouldMatchers}

class ServiceDiffSpec extends FunSpec with ShouldMatchers {

  new play.core.StaticApplication(new java.io.File("."))

  private lazy val service = TestHelper.readService("../spec/api.json")

  it("no changes") {
    ServiceDiff(service, service).differences should be(Nil)
  }

  it("apidoc version") {
    ServiceDiff(service, service.copy(apidoc = Apidoc(version = "0.0.1"))).differences should be(
      Seq(
        Difference.NonBreaking(s"apidoc/version changed from ${service.apidoc.version} to 0.0.1")
      )
    )
  }

  it("name") {
    ServiceDiff(service, service.copy(name = "test")).differences should be(
      Seq(
        Difference.NonBreaking(s"name changed from ${service.name} to test")
      )
    )
  }

  it("organization key") {
    ServiceDiff(service, service.copy(organization = Organization(key = "foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"organization/key changed from ${service.organization.key} to foo")
      )
    )
  }

  it("application key") {
    ServiceDiff(service, service.copy(application = Application(key = "foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"application/key changed from ${service.application.key} to foo")
      )
    )
  }

  it("namespace") {
    ServiceDiff(service, service.copy(namespace = "test")).differences should be(
      Seq(
        Difference.Breaking(s"namespace changed from ${service.namespace} to test")
      )
    )
  }

  it("version") {
    ServiceDiff(service, service.copy(version = "0.0.1")).differences should be(
      Seq(
        Difference.NonBreaking(s"version changed from ${service.version} to 0.0.1")
      )
    )
  }

  it("baseUrl") {
    val base = service.copy(baseUrl = None)

    ServiceDiff(base, base.copy(baseUrl = None)).differences should be(Nil)

    ServiceDiff(base, base.copy(baseUrl = Some("http://foo.com"))).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url added: http://foo.com")
      )
    )

    ServiceDiff(base.copy(baseUrl = Some("http://foo.com")), base).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url removed: http://foo.com")
      )
    )

    ServiceDiff(
      base.copy(baseUrl = Some("http://foo.com")),
      base.copy(baseUrl = Some("http://foobar.com"))
    ).differences should be(
      Seq(
        Difference.NonBreaking(s"base_url changed from http://foo.com to http://foobar.com")
      )
    )
  }

  it("description") {
    val base = service.copy(description = None)

    ServiceDiff(base, base.copy(description = None)).differences should be(Nil)

    ServiceDiff(base, base.copy(description = Some("foo"))).differences should be(
      Seq(
        Difference.NonBreaking(s"description added: foo")
      )
    )

    ServiceDiff(base.copy(description = Some("foo")), base).differences should be(
      Seq(
        Difference.NonBreaking(s"description removed: foo")
      )
    )

    ServiceDiff(
      base.copy(description = Some("foo")),
      base.copy(description = Some("foobar"))
    ).differences should be(
      Seq(
        Difference.NonBreaking(s"description changed from foo to foobar")
      )
    )
  }

  describe("headers") {
    val header = Header(
      name = "x-test",
      `type` = "string",
      description = None,
      deprecation = None,
      required = false,
      default = None
    )

    val base = service.copy(headers = Nil)
    val serviceWithHeader = base.copy(headers = Seq(header))

    it("no change") {
      ServiceDiff(serviceWithHeader, serviceWithHeader).differences should be(Nil)
    }

    it("removing a header") {
      ServiceDiff(serviceWithHeader, base).differences should be(
        Seq(
          Difference.NonBreaking("header removed: x-test")
        )
      )
    }

    it("adding an optional header") {
      ServiceDiff(base, serviceWithHeader).differences should be(
        Seq(
          Difference.NonBreaking("optional header added: x-test")
        )
      )
    }

    it("adding a required header") {
      val serviceWithRequiredHeader = base.copy(headers = Seq(header.copy(required = true)))
      ServiceDiff(base, serviceWithRequiredHeader).differences should be(
        Seq(
          Difference.Breaking("required header added: x-test")
        )
      )
    }
  }
}
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.003347926860674736, 'mean_word_length': 2.9089079013588326, 'pattern_counts': {'":': 0, '<': 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': '2743952', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2371, 'n_words': 470}