Skip to content

Commit

Permalink
Forward port to shapless-2.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
milessabin committed Jan 16, 2015
1 parent 7239479 commit 78179ef
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 140 deletions.
12 changes: 4 additions & 8 deletions core/src/test/scala/shapeless/coproduct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,23 @@ class CoproductTests {

@Test
def testWithKeys {
import syntax.singleton._
import record.RecordType
import union._
import ops.union._

val uSchema = RecordType.like('i ->> 23 :: 's ->> "foo" :: 'b ->> true :: HNil)
val cKeys = Keys[uSchema.Union].apply()
type Keys = HList.`'i, 's, 'b`.T

val u1 = Coproduct[ISB](23).zipWithKeys(cKeys)
val u1 = Coproduct[ISB](23).zipWithKeys[Keys]
val v1 = u1.get('i)
typed[Option[Int]](v1)
assertEquals(Some(23), v1)
assertEquals(None, u1.get('s))

val u2 = Coproduct[ISB]("foo").zipWithKeys(cKeys)
val u2 = Coproduct[ISB]("foo").zipWithKeys[Keys]
val v2 = u2.get('s)
typed[Option[String]](v2)
assertEquals(Some("foo"), v2)
assertEquals(None, u2.get('b))

val u3 = Coproduct[ISB](true).zipWithKeys(cKeys)
val u3 = Coproduct[ISB](true).zipWithKeys[Keys]
val v3 = u3.get('b)
typed[Option[Boolean]](v3)
assertEquals(Some(true), v3)
Expand Down
20 changes: 0 additions & 20 deletions core/src/test/scala/shapeless/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,6 @@ class GenericTests {
typed[Generic[(Int, String, Boolean)] { type Repr = Int :: String :: Boolean :: HNil }](gen3)
}

@Test
def testHLists {
type T0 = HNil
type T1 = Int :: HNil
type T2 = Int :: String :: HNil
type T3 = Int :: String :: Boolean :: HNil

val gen0 = Generic[HNil]
typed[Generic[T0] { type Repr = T0 }](gen0)

val gen1 = Generic[Int :: HNil]
typed[Generic[T1] { type Repr = T1 }](gen1)

val gen2 = Generic[Int :: String :: HNil]
typed[Generic[T2] { type Repr = T2 }](gen2)

val gen3 = Generic[Int :: String :: Boolean :: HNil]
typed[Generic[T3] { type Repr = T3 }](gen3)
}

@Test
def testProductMapBasics {
val p = Person("Joe Soap", "Brighton", 23)
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/shapeless/hlist.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ class HListTests {

@Test
def testWithKeys {
import record._
import syntax.singleton._

val orig =
Expand Down
7 changes: 2 additions & 5 deletions core/src/test/scala/shapeless/labelledgeneric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ object LabelledGenericTestsAux {
val tapl2 = Book("Benjamin Pierce", "Types and Programming Languages (2nd Ed.)", 262162091, 46.11)
val taplExt = ExtendedBook("Benjamin Pierce", "Types and Programming Languages", 262162091, 44.11, true)

type BookRec = Record.`'author -> String, 'title -> String, 'id -> Int, 'price -> Double`.T

val taplRecord =
('author ->> "Benjamin Pierce") ::
('title ->> "Types and Programming Languages") ::
('id ->> 262162091) ::
('price ->> 44.11) ::
HNil

val bookSchema = RecordType.like(taplRecord)
type BookRec = bookSchema.Record
type BookKeys = bookSchema.Keys
type BookValues = bookSchema.Values

sealed trait Tree
case class Node(left: Tree, right: Tree) extends Tree
case class Leaf(value: Int) extends Tree
Expand Down
16 changes: 9 additions & 7 deletions core/src/test/scala/shapeless/lenses.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package shapeless
import org.junit.Test
import org.junit.Assert._

import testutil._

case class Address(street : String, city : String, postcode : String)
case class Person(name : String, age : Int, address : Address)

trait LensTests {
import test._
import labelled._
import lens._

val address = Address("Southover Street", "Brighton", "BN2 9UA")
Expand Down Expand Up @@ -184,19 +187,18 @@ trait LensTests {

@Test
def testRecords {
import record.FieldType, syntax.singleton._
import record._, syntax.singleton._

val (fooT, barT) = (Witness("foo"), Witness("bar"))
type LT = (fooT.T FieldType Int) :: (barT.T FieldType String) :: HNil
type LT = Record.`"foo" -> Int, "bar" -> String`.T
val l = ("foo" ->> 42) :: ("bar" ->> "hi") :: HNil
typed[LT](l)

val li = recordLens[LT, Int]("foo")
assertEquals(42, li.get(l))
val li = recordLens[LT]("foo")
assertTypedEquals[Int](42, li.get(l))
assertEquals(("foo" ->> 84) :: ("bar" ->> "hi") :: HNil, li.set(l)(84))

val ls = recordLens[LT, String]("bar")
assertEquals("hi", ls.get(l))
val ls = recordLens[LT]("bar")
assertTypedEquals[String]("hi", ls.get(l))
assertEquals(("foo" ->> 42) :: ("bar" ->> "bye") :: HNil, ls.set(l)("bye"))
}

Expand Down
4 changes: 1 addition & 3 deletions core/src/test/scala/shapeless/monoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package MonoidAux {
def append(a : String, b : String) = a+b
}

implicit val monoidInstance: ProductTypeClass[Monoid] = new ProductTypeClass[Monoid] {
object typeClass extends ProductTypeClass[Monoid] {
def emptyProduct = new Monoid[HNil] {
def zero = HNil
def append(a : HNil, b : HNil) = HNil
Expand Down Expand Up @@ -99,8 +99,6 @@ class MonoidTests {

@Test
def testAuto {
import Monoid.auto._

val f = Foo(13, "foo") |+| Foo(23, "bar")
assertEquals(Foo(36, "foobar"), f)

Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/shapeless/records.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.junit.Test
import org.junit.Assert._

class RecordTests {
import labelled._
import record._
import syntax.singleton._
import test._
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/shapeless/singletons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class SingletonTypesTests {
implicit def relFalse: Rel[False] { type Out = String } = new Rel[False] { type Out = String }
}

def check(w: WitnessWith[Rel])(v: w.Out) = v
def check(w: WitnessWith[Rel])(v: w.instance.Out) = v

@Test
def testWitnessWithOut {
Expand Down
19 changes: 1 addition & 18 deletions core/src/test/scala/shapeless/sybclass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SybClassTests {
object incAll extends Poly1 {
implicit def caseInt = at[Int](_+1)
implicit def caseString = at[String](_+"*")
implicit def default[T](implicit data : DataT[this.type, T, T]) = at[T](data.gmapT)
implicit def default[T](implicit data : DataT.Aux[this.type, T, T]) = at[T](data.gmapT)
}

object inc extends Poly1 {
Expand Down Expand Up @@ -442,23 +442,6 @@ class SybClassTests {
assertEquals(expected4, result4)
}

@Test
def testList {
val input: List[Apple] = List(Apple(1), Apple(2), Apple(3))
val expected: List[String] = List("Pomme", "Pomme", "Pomme")

val result = everywhere(showFruit)(input)
typed[List[String]](result)
assertEquals(expected, result)

val input2: List[Apple] = List(Apple(1), Apple(1), Apple(1))
val expected2: List[Pear] = List(Pear(1), Pear(1), Pear(1))

val result2 = everywhere(cycleFruit)(input2)
typed[List[Pear]](result2)
assertEquals(expected2, result2)
}

/*
@Test
def testCoproduct3 {
Expand Down
16 changes: 14 additions & 2 deletions core/src/test/scala/shapeless/tuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,20 @@ class TupleTests {

object mkString extends (Any -> String)(_.toString)
object fruit extends (Fruit -> Fruit)(f => f)
object incInt extends (Int >-> Int)(_ + 1)
object extendedChoose extends LiftU(choose)

trait incInt0 extends Poly1 {
implicit def default[T] = at[T](t => ())
}
object incInt extends incInt0 {
implicit val caseInt = at[Int](i => Tuple1(i+1))
}

trait extendedChoose0 extends Poly1 {
implicit def default[T] = at[T](t => ())
}
object extendedChoose extends extendedChoose0 {
implicit def caseSet[T] = at[Set[T]](s => Tuple1(s.headOption))
}

@Test
def testBasics {
Expand Down
22 changes: 11 additions & 11 deletions core/src/test/scala/shapeless/typeable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,28 @@ class TypeableTests {
def testNull {
val n : Any = null
val cn = n.cast[AnyVal]
assertTrue(cn.isDefined)
assertTrue(!cn.isDefined)

val cn1 = n.cast[AnyRef]
assertTrue(cn1.isDefined)
assertTrue(!cn1.isDefined)

val cn2 = n.cast[Int]
assertTrue(cn2.isDefined)
assertTrue(!cn2.isDefined)

val cn3 = n.cast[String]
assertTrue(cn3.isDefined)
assertTrue(!cn3.isDefined)

val cn4 = n.cast[List[Int]]
assertTrue(cn4.isDefined)
assertTrue(!cn4.isDefined)

val cn5 = n.cast[HNil]
assertTrue(cn5.isDefined)
assertTrue(!cn5.isDefined)

val cn6 = n.cast[Int :: String :: Boolean :: HNil]
assertTrue(cn6.isDefined)
assertTrue(!cn6.isDefined)

val cn7 = n.cast[(Int, String)]
assertTrue(cn7.isDefined)
assertTrue(!cn7.isDefined)
}

@Test
Expand Down Expand Up @@ -271,10 +271,10 @@ class TypeableTests {
val cd2 = d.cast[B with A]
assertTrue(cd2.isDefined)

val cd3 = d.cast[A with C] // Initial type of arbitrary intersection is OK
assertTrue(cd3.isDefined)
val cd3 = d.cast[A with C]
assertTrue(cd3.isEmpty)

val cd4 = d.cast[C with A] // Subsequent types are not
val cd4 = d.cast[C with A]
assertTrue(cd4.isEmpty)
}

Expand Down
Loading

0 comments on commit 78179ef

Please sign in to comment.