summaryrefslogtreecommitdiff
path: root/test/files/run/lazy-exprs.scala
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2007-06-27 14:26:47 +0000
committerIulian Dragos <jaguarul@gmail.com>2007-06-27 14:26:47 +0000
commitb4b91dcb58b5804f7ec1513e8f4d1e4534fd8018 (patch)
tree758a2817dd728101980c7ffc3f206d484ad77ba0 /test/files/run/lazy-exprs.scala
parenta1ec75c2642396a83854510ba7e88d8a302a67fd (diff)
downloadscala-b4b91dcb58b5804f7ec1513e8f4d1e4534fd8018.tar.gz
scala-b4b91dcb58b5804f7ec1513e8f4d1e4534fd8018.tar.bz2
scala-b4b91dcb58b5804f7ec1513e8f4d1e4534fd8018.zip
Merged lazy values branch to trunk.
Diffstat (limited to 'test/files/run/lazy-exprs.scala')
-rw-r--r--test/files/run/lazy-exprs.scala84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/files/run/lazy-exprs.scala b/test/files/run/lazy-exprs.scala
new file mode 100644
index 0000000000..307915bcac
--- /dev/null
+++ b/test/files/run/lazy-exprs.scala
@@ -0,0 +1,84 @@
+object TestExpressions {
+
+ def patmatchScrut {
+ lazy val z1: Option[String] = { println("forced <z1>"); Some("lazy z1") }
+
+ val res = z1 match {
+ case Some(msg) => msg
+ case None => "failed"
+ }
+ print("lazy val in scrutinee: ")
+ if (res == "lazy z1")
+ println("ok")
+ else
+ println("failed")
+ }
+
+ def patmatchCase {
+ val t: Option[String] = Some("test")
+ val res = t match {
+ case Some(msg) =>
+ lazy val z1 = { println("forced <z1>"); "lazy z1" }
+ z1
+
+ case None => "failed"
+ }
+ print("lazy val in case: ")
+ if (res == "lazy z1")
+ println("ok")
+ else
+ println("failed")
+ }
+
+
+ def patmatchPat {
+ lazy val Z1 = { println("forced <z1>"); "lazy Z1" }
+ print("lazy val in case: ")
+ val t: Option[String] = Some("lazy Z1")
+ t match {
+ case Some(Z1) =>
+ println("ok")
+
+ case None =>
+ println("failed")
+ }
+ }
+
+ def ifcond {
+ lazy val z1 = { println("forced <z1>"); "lazy z1" }
+ print("lazy val in if condition: ")
+ if (z1 == "lazy z1")
+ println("ok")
+ else
+ println("failed")
+ }
+
+
+ lazy val LazyField = { println("forced LazyField"); "LazyField" }
+
+ def testPatMatchField {
+ print("lazy val in pattern: ")
+ val t: Option[String] = Some("LazyField")
+ t match {
+ case Some(LazyField) =>
+ println("ok")
+
+ case None =>
+ println("failed")
+ }
+ }
+
+ def test {
+ patmatchScrut
+ patmatchCase
+ patmatchPat
+ ifcond
+ testPatMatchField
+ }
+}
+
+
+object Test extends Application {
+
+ TestExpressions.test
+}