-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
461be54
commit 5d066b4
Showing
5 changed files
with
84 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include ".scalafix-common.conf" | ||
|
||
OrganizeImports.removeUnused = false | ||
OrganizeImports.targetDialect = Scala3 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.ags | ||
|
||
import eu.timepit.refined.string.MatchesRegex | ||
import eu.timepit.refined.types.string.NonEmptyString | ||
import lucuma.core.util.RefinedNewType | ||
import monocle.Prism | ||
|
||
import scala.util.matching.Regex | ||
|
||
// For now, at least, we only support Gaia. | ||
// The same regex used in the odb for a database check. When changing one, both should be updated. | ||
private val regexStr = """^Gaia DR3 (-?\d+)$""" | ||
type GuideStarNamePred = MatchesRegex[regexStr.type] | ||
|
||
object GuideStarName extends RefinedNewType[String, GuideStarNamePred]: | ||
def gaiaSourceId: Prism[GuideStarName, Long] = | ||
Prism[GuideStarName, Long](_.toGaiaSourceId)(id => GuideStarName.unsafeFrom(s"Gaia DR3 $id")) | ||
|
||
extension (self: GuideStarName) | ||
def toGaiaSourceId: Option[Long] = | ||
val regex = Regex(regexStr) | ||
self.value.value match | ||
case regex(d) => d.toLongOption | ||
case _ => None | ||
def toNonEmptyString: NonEmptyString = NonEmptyString.unsafeFrom(self.value.value) | ||
|
||
type GuideStarName = GuideStarName.Type |
27 changes: 27 additions & 0 deletions
27
modules/testkit/src/main/scala/lucuma/ags/arb/ArbGuideStarName.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,27 @@ | ||
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.ags.arb | ||
|
||
import lucuma.ags.GuideStarName | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Cogen | ||
import org.scalacheck.Gen | ||
|
||
trait ArbGuideStarName: | ||
|
||
given Arbitrary[GuideStarName] = | ||
Arbitrary { | ||
Gen | ||
.frequency( | ||
// Get the occasional name with too many digits | ||
1 -> s"9${Long.MaxValue}", | ||
20 -> Arbitrary.arbLong.arbitrary | ||
) | ||
.map(a => GuideStarName.unsafeFrom(s"Gaia DR3 $a")) | ||
} | ||
|
||
given Cogen[GuideStarName] = | ||
Cogen[String].contramap(_.value.value) | ||
|
||
object ArbGuideStarName extends ArbGuideStarName |
24 changes: 24 additions & 0 deletions
24
modules/tests/shared/src/test/scala/lucuma/ags/GuideStarNameSuite.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,24 @@ | ||
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.ags | ||
|
||
import cats.kernel.Eq | ||
import cats.kernel.laws.discipline.EqTests | ||
import eu.timepit.refined.cats.* | ||
import io.circe.* | ||
import io.circe.refined.* | ||
import io.circe.testing.CodecTests | ||
import io.circe.testing.instances.arbitraryJson | ||
import lucuma.ags.arb.ArbGuideStarName.given | ||
import monocle.law.discipline.PrismTests | ||
|
||
class GuideStarNameSuite extends munit.DisciplineSuite { | ||
test("typeclasses") { | ||
checkAll("GuideStarName", EqTests[GuideStarName].eqv) | ||
checkAll("GuideStarNameCodec", CodecTests[GuideStarName].codec) | ||
checkAll("GuideStarName.from", PrismTests(GuideStarName.from)) | ||
checkAll("GuideStarName.gaiaSourceId", PrismTests(GuideStarName.gaiaSourceId)) | ||
} | ||
|
||
} |