-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from iRevive/tests-cleanup
Tests: reuse existing `Arbitrary`, `Gen`, and `Cogen` instances
- Loading branch information
Showing
36 changed files
with
641 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
core/common/src/test/scala/org/typelevel/otel4s/scalacheck/Gens.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2022 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.typelevel.otel4s | ||
package scalacheck | ||
|
||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Gen | ||
import org.typelevel.otel4s.Attribute.KeySelect | ||
|
||
trait Gens { | ||
|
||
val nonEmptyString: Gen[String] = | ||
Gen.alphaNumStr.suchThat(_.nonEmpty) | ||
|
||
val attribute: Gen[Attribute[_]] = { | ||
implicit val stringArb: Arbitrary[String] = | ||
Arbitrary(nonEmptyString) | ||
|
||
implicit def listArb[A: Arbitrary]: Arbitrary[List[A]] = | ||
Arbitrary(Gen.nonEmptyListOf(Arbitrary.arbitrary[A])) | ||
|
||
def attribute[A: KeySelect: Arbitrary]: Gen[Attribute[A]] = | ||
for { | ||
key <- nonEmptyString | ||
value <- Arbitrary.arbitrary[A] | ||
} yield Attribute(key, value) | ||
|
||
val string: Gen[Attribute[String]] = attribute[String] | ||
val boolean: Gen[Attribute[Boolean]] = attribute[Boolean] | ||
val long: Gen[Attribute[Long]] = attribute[Long] | ||
val double: Gen[Attribute[Double]] = attribute[Double] | ||
|
||
val stringList: Gen[Attribute[List[String]]] = attribute[List[String]] | ||
val booleanList: Gen[Attribute[List[Boolean]]] = attribute[List[Boolean]] | ||
val longList: Gen[Attribute[List[Long]]] = attribute[List[Long]] | ||
val doubleList: Gen[Attribute[List[Double]]] = attribute[List[Double]] | ||
|
||
Gen.oneOf( | ||
boolean, | ||
string, | ||
long, | ||
double, | ||
stringList, | ||
booleanList, | ||
longList, | ||
doubleList | ||
) | ||
} | ||
|
||
val attributes: Gen[Attributes] = | ||
for { | ||
attributes <- Gen.listOf(attribute) | ||
} yield Attributes.fromSpecific(attributes) | ||
|
||
} | ||
|
||
object Gens extends Gens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.