Created
February 7, 2012 07:51
-
-
Save jhajduk/1758108 to your computer and use it in GitHub Desktop.
proposed pattern for HtmlProperties
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.specs2.mutable._ | |
trait BaseType { | |
def First(me:BaseType): String | |
def First: String = First(this) | |
def setFirst(newFirst: () => String) = { | |
val old = this | |
new BaseType { | |
def First(me:BaseType) = old.First(me) | |
override def First = newFirst() | |
def Second(me:BaseType) = old.Second(me) | |
def Third(me:BaseType) = old.Third(me) | |
} | |
} | |
def Second(me:BaseType): String | |
def Second: String = Second(this) | |
def setSecond(newSecond: () => String) = { | |
val old = this | |
new BaseType { | |
def First(me:BaseType) = old.First(me) | |
def Second(me:BaseType) = old.Second(me) | |
override def Second = newSecond() | |
def Third(me:BaseType) = | |
old.Third(me) | |
} | |
} | |
def Third(me:BaseType): String | |
def Third: String = Third(this) | |
def setThird(newThird: () => String) = { | |
val old = this | |
new BaseType { | |
def First(me:BaseType) = old.First(me) | |
def Second(me:BaseType) = old.Second(me) | |
def Third(me:BaseType) = old.Third(me) | |
override def Third = newThird() | |
} | |
} | |
} | |
case class TestType(param: String) extends BaseType { | |
def First(me:BaseType) = | |
"HELLO" | |
def Second(me:BaseType) = | |
me.First + " WORLD" | |
def Third(me:BaseType) = | |
me.First + " " + me.Second + "!!!" | |
} | |
class TestProposed extends Specification { | |
val t1 = TestType("") | |
val t4 = TestType("").setFirst(()=>"GOODBYE") | |
val t5 = t4.setSecond(()=>"YAY") | |
val t6 = TestType("").setSecond(()=>"YOO") | |
"test new" should { | |
// specs wierdness (ambiguious overload) when i try to do | |
// t1.Third must beEqualTo("HELLO HELLOW WORLD!!!") | |
val basicString:String = t1.Third | |
"nothing" in { | |
basicString must beEqualTo("HELLO HELLO WORLD!!!") | |
} | |
"simple test" in { | |
t4.Second must beEqualTo("GOODBYE WORLD") | |
} | |
"harder test" in { | |
t4.Third must beEqualTo("GOODBYE GOODBYE WORLD!!!") | |
} | |
"another test" in { | |
t5.Third must beEqualTo("HELLO YAY!!!") | |
} | |
"yet another test" in { | |
t6.Third must beEqualTo("HELLO YOO!!!") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment