Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update scalafmt-core from 3.8.3 to 3.8.5 #149

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

# Scala Steward: Reformat with scalafmt 3.8.2
1905008f11ffcbae185026dd4e6557dc298bbaf1

# Scala Steward: Reformat with scalafmt 3.8.5
f41e662e95129d9704da80b1d52ce9e3e7a9bc31
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.3"
version = "3.8.5"

runner.dialect = "scala213"

Expand Down
47 changes: 22 additions & 25 deletions src/test/scala/io/renku/jsonld/DefaultGraphSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ class DefaultGraphSpec extends AnyWordSpec with should.Matchers with ScalaCheckP

"toJson" should {

"turn the given DefaultGraph into JSON" in {
"turn the given DefaultGraph into JSON" in
forAll { (graph: DefaultGraph) =>
graph.toJson shouldBe Json.obj(
"@graph" -> Json.fromValues(graph.entities.map(_.toJson))
)
}
}
}

"entityId" should {
Expand Down Expand Up @@ -197,29 +196,27 @@ class DefaultGraphSpec extends AnyWordSpec with should.Matchers with ScalaCheckP
}

"return DefaultGraph with flattened entities in the sense of an JsonLDArray merge " +
"if there's more than one entity" in {
forAll {
(childlessGrandparent: JsonLDEntity, parentRelationProperty: Property, parentNotNested: JsonLDEntity) =>
val childrenTuples = entityProperties.generateNonEmptyList().toList
val parentWithProperties = parentNotNested.add(childrenTuples)
val grandparentWithChild = childlessGrandparent.add(parentRelationProperty -> parentWithProperties)

val flattenedGrandparent =
childlessGrandparent.add(parentRelationProperty -> JsonLD.fromEntityId(parentWithProperties.id))
val flattenedParent = childrenTuples
.foldLeft(parentNotNested) { case (parent, (property, child)) =>
parent.add(property -> child.id.asJsonLD)
}
val children = childrenTuples.map { case (_, entity) => entity: JsonLD }

val otherEntity = jsonLDEntities.generateOne
val edge = jsonLDEdges.generateOne

val Right(flattened) = DefaultGraph(grandparentWithChild, otherEntity, edge).flatten

flattened.entities should contain theSameElementsAs
flattenedGrandparent :: flattenedParent :: children ::: otherEntity :: edge :: Nil
}
"if there's more than one entity" in
forAll { (childlessGrandparent: JsonLDEntity, parentRelationProperty: Property, parentNotNested: JsonLDEntity) =>
val childrenTuples = entityProperties.generateNonEmptyList().toList
val parentWithProperties = parentNotNested.add(childrenTuples)
val grandparentWithChild = childlessGrandparent.add(parentRelationProperty -> parentWithProperties)

val flattenedGrandparent =
childlessGrandparent.add(parentRelationProperty -> JsonLD.fromEntityId(parentWithProperties.id))
val flattenedParent = childrenTuples
.foldLeft(parentNotNested) { case (parent, (property, child)) =>
parent.add(property -> child.id.asJsonLD)
}
val children = childrenTuples.map { case (_, entity) => entity: JsonLD }

val otherEntity = jsonLDEntities.generateOne
val edge = jsonLDEdges.generateOne

val Right(flattened) = DefaultGraph(grandparentWithChild, otherEntity, edge).flatten

flattened.entities should contain theSameElementsAs
flattenedGrandparent :: flattenedParent :: children ::: otherEntity :: edge :: Nil
}
}
}
6 changes: 2 additions & 4 deletions src/test/scala/io/renku/jsonld/EntityIdSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ class EntityIdSpec extends AnyWordSpec with ScalaCheckPropertyChecks with should
}
}

"allow passing a Property" in {
"allow passing a Property" in
forAll { (property: Property) =>
EntityId.of(property).value shouldBe property.url
}
}

"allow passing a Schema" in {
"allow passing a Schema" in
forAll { (schema: Schema) =>
EntityId.of(schema).value shouldBe schema.url
}
}

"return an EntityId with the URI created from the given value using the converter" in {
case class Value(v: String)
Expand Down
18 changes: 6 additions & 12 deletions src/test/scala/io/renku/jsonld/EntityTypeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,40 @@ class EntityTypeSpec extends AnyWordSpec with ScalaCheckPropertyChecks with shou

"show" should {

"return the value" in {
"return the value" in
forAll { t: EntityType => t.show shouldBe t.value }
}
}

"EntityTypes.show" should {

"return string representations of all the types separated with `; `" in {
"return string representations of all the types separated with `; `" in
forAll { t: EntityTypes => t.show shouldBe t.list.map(_.value).nonEmptyIntercalate("; ") }
}
}

"EntityTypes.equals" should {
"return true if the types are identical regardless of the order" in {
"return true if the types are identical regardless of the order" in
forAll { t: EntityTypes =>
val equalTypes = EntityTypes(NonEmptyList.fromListUnsafe(Random.shuffle(t.list.toList)))
t shouldBe equalTypes
t.hashCode() shouldBe equalTypes.hashCode()
}
}

"return false if the types are not identical" in {
"return false if the types are not identical" in
forAll { (t1: EntityTypes, t2: EntityTypes) =>
t1 should not be t2
t1.hashCode() should not be t2.hashCode()
}
}
}

"contains" should {
"return true for exact match although in different order" in {
"return true for exact match although in different order" in
forAll { entityTypes: EntityTypes =>
val shuffledTypes = Random.shuffle(entityTypes.toList)
(entityTypes contains EntityTypes.of(shuffledTypes.head, shuffledTypes.tail: _*)) shouldBe true
}
}
"return true if there are at least the searched types" in {
"return true if there are at least the searched types" in
forAll { (type1: EntityType, type2: EntityType, type3: EntityType) =>
EntityTypes.of(type1, type2, type3).contains(type2, type1) shouldBe true
}
}
}
}
27 changes: 9 additions & 18 deletions src/test/scala/io/renku/jsonld/JsonLDDecoderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ class JsonLDDecoderSpec

"emap" should {

"use the given function to map the result" in {
"use the given function to map the result" in
forAll { value: String =>
val decoder = decodeString.emap(_.length.asRight[String])
JsonLD.fromString(value).cursor.as[Int](decoder) shouldBe Right(value.length)
}
}

"fail with the message given in the mapping function" in {
"fail with the message given in the mapping function" in
forAll { value: String =>
val message = nonEmptyStrings().generateOne
val decoder = decodeString.emap(_ => message.asLeft[Int])
JsonLD.fromString(value).cursor.as[Int](decoder).leftMap(_.message) shouldBe Left(message)
}
}

case class Person(name: String)

Expand All @@ -71,7 +69,7 @@ class JsonLDDecoderSpec
result.getClass shouldBe decoder.getClass
}

"apply the function when called on JsonLDEntityDecoder" in {
"apply the function when called on JsonLDEntityDecoder" in
forAll(Gen.alphaNumStr) { value: String =>
val decoder: JsonLDEntityDecoder[Person] = JsonLDDecoder.entity(EntityTypes.of(schema / "Person")) { cursor =>
cursor.downField(schema / "name").as[String].map(Person)
Expand All @@ -92,7 +90,6 @@ class JsonLDDecoderSpec

decoded shouldBe Person(value.reverse)
}
}

"fail if emap is returning a Left on JsonLDEntityDecoder" in {
val decoder: JsonLDEntityDecoder[Person] = JsonLDDecoder.entity(EntityTypes.of(schema / "Person")) { cursor =>
Expand All @@ -116,12 +113,11 @@ class JsonLDDecoderSpec
}

"map" should {
"appy the given function" in {
"appy the given function" in
forAll { value: String =>
val decoder = decodeString.map(_.length)
JsonLD.fromString(value).cursor.as[Int](decoder) shouldBe Right(value.length)
}
}
}

"implicit decoders" should {
Expand All @@ -143,19 +139,17 @@ class JsonLDDecoderSpec

forAll(scenarios) {
case (typeName, decoder, generator, illegalType: JsonLDValue[_]) =>
s"allow to successfully decode $typeName JsonLDValues to $typeName" in {
s"allow to successfully decode $typeName JsonLDValues to $typeName" in
forAll(generator) { case (value, jsonLD) =>
jsonLD.cursor.as(decoder) shouldBe Right(value)
}
}

s"fail to decode JsonLDValues of illegal type to $typeName" in {
s"fail to decode JsonLDValues of illegal type to $typeName" in
forAll(generator) { case (_, _) =>
illegalType.cursor.as(decoder) shouldBe Left(
DecodingFailure(s"Cannot decode ${illegalType.value} to $typeName", Nil)
)
}
}

case (_, _, _, illegalType) => fail(s"Missing tests for $illegalType")
}
Expand All @@ -175,13 +169,12 @@ class JsonLDDecoderSpec
JsonLD.fromString(date.toString).cursor.as[LocalDate] shouldBe Right(date)
}

"allow to successfully decode any JsonLD to JsonLD" in {
"allow to successfully decode any JsonLD to JsonLD" in
forAll { json: JsonLD =>
json.cursor.as[JsonLD] shouldBe Right(json)
}
}

"allow to decode to Some for optional property if it exists" in {
"allow to decode to Some for optional property if it exists" in
forAll(entityIds, entityTypesObject, properties, Gen.oneOf(jsonLDValues, jsonLDEntities)) {
(entityId, entityTypes, property, value) =>
JsonLD
Expand All @@ -190,17 +183,15 @@ class JsonLDDecoderSpec
.downField(property)
.as[Option[JsonLD]] shouldBe Some(value).asRight
}
}

"allow to decode to None for optional property if it does not exists" in {
"allow to decode to None for optional property if it does not exists" in
forAll { (entityId: EntityId, entityTypes: EntityTypes) =>
JsonLD
.entity(entityId, entityTypes, Map.empty[Property, JsonLD])
.cursor
.downField(schema / "non-existing")
.as[Option[JsonLD]] shouldBe None.asRight
}
}
}

"decode" should {
Expand Down
9 changes: 3 additions & 6 deletions src/test/scala/io/renku/jsonld/JsonLDEncoderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,34 @@ class JsonLDEncoderSpec extends AnyWordSpec with ScalaCheckPropertyChecks with s

"instance" should {

"allow to create a JsonLDEncoder for the given type" in {
"allow to create a JsonLDEncoder for the given type" in
forAll { (id: EntityId, types: EntityTypes, property: Property, value: String) =>
val encoder = JsonLDEncoder.instance[Object] { o =>
JsonLD.entity(id, types, property -> o.field.asJsonLD)
}

encoder(Object(value)) shouldBe JsonLD.entity(id, types, property -> value.asJsonLD)
}
}
}

"entityId" should {

"allow to create a JsonLDEncoder producing EntityId for the given type" in {
"allow to create a JsonLDEncoder producing EntityId for the given type" in
forAll { (value: String) =>
val encoder = JsonLDEncoder.entityId[Object] { o =>
EntityId.of(o.field)
}

encoder(Object(value)) shouldBe JsonLD.fromEntityId(EntityId.of(value))
}
}
}

"schema" should {

"allow to create a JsonLDEncoder producing EntityId for the given type" in {
"allow to create a JsonLDEncoder producing EntityId for the given type" in
forAll { (schema: Schema) =>
schema.asJsonLD shouldBe JsonLDEntityId(EntityId.of(schema.toString))
}
}
}

"apply" should {
Expand Down
Loading
Loading