|
Lift Framework example source code file (HListSpec.scala)
The Lift Framework HListSpec.scala source code/* * Copyright 2010-2011 WorldWide Conferencing, LLC * * 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 net.liftweb package common import org.specs.Specification /** * System under specification for Heterogeneous List. */ object HListSpec extends Specification("HList Specification") { "An HList" should { "get the types right" in { import HLists._ val x = 1 :+: "Foo" :+: HNil val head: Int = x.head val head2: String = x.tail.head x.head must_== 1 x.tail.head must_== "Foo" } } "A combinable box" should { "have a box built with a failure result in a failure" in { import CombinableBox._ val x = Full("a") :&: Full(1) :&: Empty // result in a failure x match { case Left(_) => true must_== true case _ => fail("Full elements available") } } "be able to build a box with all the Full elements matching" in { import CombinableBox._ import HLists._ val x = Full("a") :&: Full(1) :&: Full(List(1,2,3)) // result in a failure x match { case Right(a :+: one :+: lst :+:HNil) => { // val a2: Int = a fails... not type safe val as: String = a val onei: Int = one val lstl: List[Int] = lst true must_== true } case Left(_) => fail("Failure elements available") } } "be usable in for comprehension" in { import CombinableBox._ import HLists._ val res = for { a :+: one :+: lst :+: _ <- (Full("a") ?~ "Yak" :&: Full(1) :&: Full(List(1,2,3))) ?~! "Dude" } yield a.length * one * lst.foldLeft(1)(_ * _) res must_== Full(6) } } } Other Lift Framework examples (source code examples)Here is a short list of links related to this Lift Framework HListSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.