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
class Example(description: String) { | |
def in[T](expectations: =>T)(implicit def m: scala.reflect.Manifest[T]): Example = { | |
if (m.erasure == this.getClass) | |
hasSubExamples = true | |
// store expectations for later evaluation | |
} | |
} | |
/** |
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
object ExtendedFunctions extends ExtendedFunctions | |
trait ExtendedFunctions { | |
implicit def extend[A, B](f: Function[A, B]) = new ExtendedFunction(f) | |
} | |
/** | |
* this class allows to use a function as if it was a partial function. | |
* | |
* It is especially useful when one want to overload a function with both functions and partial function | |
* literals. This usually is an issue because of the way the compiler interprets function and | |
* partial function literals (see the Scala Language Specification, section 8.5). |
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
// you can refactor all those mustEqual examples | |
// to be more concise and provide a complete description in the reports | |
"Json" should { | |
"quote strings" in { | |
"unicode within latin-1" in { | |
Json.quote("hello\n\u009f") mustEqual "\"hello\\n\\u009f\"" | |
} | |
"unicode outside of latin-1 (the word Tokyo)" in { | |
Json.quote("\u6771\u4eac") mustEqual "\"\\u6771\\u4eac\"" | |
} |
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
# | |
# A fatal error has been detected by the Java Runtime Environment: | |
# | |
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9799dc, pid=6948, tid=7116 | |
# | |
# JRE version: 6.0_20-b02 | |
# Java VM: Java HotSpot(TM) Client VM (16.3-b01 mixed mode windows-x86 ) | |
# Problematic frame: | |
# V [jvm.dll+0xc99dc] | |
# |
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
# | |
# A fatal error has been detected by the Java Runtime Environment: | |
# | |
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9572f3, pid=1384, tid=3640 | |
# | |
# JRE version: 6.0_21-b05 | |
# Java VM: Java HotSpot(TM) Client VM (17.0-b15 mixed mode windows-x86 ) | |
# Problematic frame: | |
# V [jvm.dll+0xa72f3] | |
# |
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
/** | |
* A quick debugging tip | |
*/ | |
/** | |
* If you have lots of definitions using the same type parameter names, like 'S' | |
*/ | |
def beEmpty[S <: HasIsEmpty]: Matcher[S] = new EmptyMatcher() | |
def compose[S] (f: S => T) = new Matcher[S] { ... } |
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
/** | |
* remove the first element satifying the predicate | |
* @return an iterable minus the first element satisfying the predicate | |
*/ | |
def removeFirst(predicate: T => Boolean): Iterable[T] = { | |
if (xs.isEmpty) xs | |
else if (predicate(xs.head)) xs.drop(1) | |
else xs.take(1) ++ xs.removeFirst(predicate) | |
} | |
/** |
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
import org.specs._ | |
import org.scalacheck._ | |
import com.codecommit.collection.Vector | |
/** | |
* An enhanced specification of the Vector class from http://github.com/djspiewak/scala-collections | |
* | |
* It uses "verifies" to remove the boilerplate declaration of a property which "must pass" | |
* It uses must throwAn[Exception] to specify that an exception must be thrown |
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
/** I think it's better if we can define replaceFirst generally on Iterables */ | |
def replaceFirst[T](it: Iterable[T], predicate:T=>Boolean, f:T=>T): Iterable[T] = { | |
if (it.isEmpty) it | |
else if (predicate(it.head)) it.take(1) .map(f) ++ it.tail | |
else it.take(1) ++ replaceFirst(it.tail, predicate, f) | |
} | |
/** | |
* Otherwise on Lists, that can be fun to use a foldLeft. | |
* It's a bit ugly though with the trailing _2 |
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 fails to compile with: | |
type mismatch; | |
found : Iterable[T] | |
required: CC[T] | |
else if (predicate(xs.head)) xs.drop(1) | |
^ | |
type mismatch; | |
found : Iterable[T] |
OlderNewer