From b4b91dcb58b5804f7ec1513e8f4d1e4534fd8018 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 27 Jun 2007 14:26:47 +0000 Subject: Merged lazy values branch to trunk. --- test/files/run/lazy-exprs.scala | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 test/files/run/lazy-exprs.scala (limited to 'test/files/run/lazy-exprs.scala') 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 "); 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 "); "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 "); "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 "); "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 +} -- cgit v1.2.3