-
Notifications
You must be signed in to change notification settings - Fork 138
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
Showing
9 changed files
with
65 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package frameless | ||
|
||
import shapeless._ | ||
import shapeless.labelled.FieldType | ||
|
||
/** Evidence that `T` is a Value class */ | ||
@annotation.implicitNotFound(msg = "${T} is not a Value class") | ||
final class IsValueClass[T] private() {} | ||
|
||
object IsValueClass { | ||
/** Provides an evidence `A` is a Value class */ | ||
implicit def apply[A <: AnyVal, G <: ::[_, HNil], H <: ::[_ <: FieldType[_ <: Symbol, _], HNil]]( | ||
implicit | ||
i0: LabelledGeneric.Aux[A, G], | ||
i1: DropUnitValues.Aux[G, H]): IsValueClass[A] = new IsValueClass[A] | ||
|
||
} |
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
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,31 @@ | ||
package frameless | ||
|
||
import shapeless.Refute | ||
import shapeless.test.illTyped | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
final class IsValueClassTests extends AnyFunSuite with Matchers { | ||
test("Case class is not Value class") { | ||
illTyped("IsValueClass[P]") | ||
illTyped("IsValueClass[Q]") | ||
} | ||
|
||
test("Scala value type is not Value class (excluded)") { | ||
illTyped("implicitly[IsValueClass[Double]]") | ||
illTyped("implicitly[IsValueClass[Float]]") | ||
illTyped("implicitly[IsValueClass[Long]]") | ||
illTyped("implicitly[IsValueClass[Int]]") | ||
illTyped("implicitly[IsValueClass[Char]]") | ||
illTyped("implicitly[IsValueClass[Short]]") | ||
illTyped("implicitly[IsValueClass[Byte]]") | ||
illTyped("implicitly[IsValueClass[Unit]]") | ||
illTyped("implicitly[IsValueClass[Boolean]]") | ||
} | ||
|
||
test("Value class evidence") { | ||
implicitly[IsValueClass[RecordEncoderTests.Name]] | ||
illTyped("implicitly[Refute[IsValueClass[RecordEncoderTests.Name]]]") | ||
} | ||
} |
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