diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-05-23 16:48:15 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-05-23 18:55:40 +0200 |
commit | e61e59f739d889549993afdd743cbaf71a95c45e (patch) | |
tree | 8b390944a546f0c29de4076a028dd8a6c76bedc7 /tests/run/valueclasses-constr.scala | |
parent | 942c41b1bdc6db60d530eee70d9dba68acfb54e6 (diff) | |
download | dotty-e61e59f739d889549993afdd743cbaf71a95c45e.tar.gz dotty-e61e59f739d889549993afdd743cbaf71a95c45e.tar.bz2 dotty-e61e59f739d889549993afdd743cbaf71a95c45e.zip |
Add some run tests related to value classes
Diffstat (limited to 'tests/run/valueclasses-constr.scala')
-rw-r--r-- | tests/run/valueclasses-constr.scala | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/run/valueclasses-constr.scala b/tests/run/valueclasses-constr.scala new file mode 100644 index 000000000..73ac29435 --- /dev/null +++ b/tests/run/valueclasses-constr.scala @@ -0,0 +1,79 @@ +package test1 { + object TOD { + final val SecondsPerDay = 86400 + + def apply(seconds: Int) = { + val n = seconds % SecondsPerDay + new TOD(if (n >= 0) n else n + SecondsPerDay) + } + } + + final class TOD (val secondsOfDay: Int) extends AnyVal { + def hours = secondsOfDay / 3600 + def minutes = (secondsOfDay / 60) % 60 + def seconds = secondsOfDay % 60 + + override def toString = "%02d:%02d:%02d".format(hours, minutes, seconds) + } +} +package test2 { + object TOD { + final val SecondsPerDay = 86400 + + def apply(seconds: Int) = { + val n = seconds % SecondsPerDay + new TOD(if (n >= 0) n else n + SecondsPerDay) + } + } + + final class TOD private[test2] (val secondsOfDay: Int) extends AnyVal { + def hours = secondsOfDay / 3600 + def minutes = (secondsOfDay / 60) % 60 + def seconds = secondsOfDay % 60 + + override def toString = "%02d:%02d:%02d".format(hours, minutes, seconds) + } + + object Client { + def newTOD(x: Int) = new TOD(x) + } +} + +package test3 { + object TOD { + final val SecondsPerDay = 86400 + + def apply(seconds: Int) = { + val n = seconds % SecondsPerDay + new TOD(if (n >= 0) n else n + SecondsPerDay) + } + } + + final class TOD private (val secondsOfDay: Int) extends AnyVal { + def hours = secondsOfDay / 3600 + def minutes = (secondsOfDay / 60) % 60 + def seconds = secondsOfDay % 60 + + override def toString = "%02d:%02d:%02d".format(hours, minutes, seconds) + } +} + +object Test extends dotty.runtime.LegacyApp { + + val y1: test1.TOD = new test1.TOD(1000) + val y2: test2.TOD = test2.Client.newTOD(1000) + val x1: test1.TOD = test1.TOD(1000) + val x2: test2.TOD = test2.TOD(1000) + val x3: test3.TOD = test3.TOD(1000) + println(y1.minutes) + println(y1) + println(y2.minutes) + println(y2) + println(x1.minutes) + println(x1) + println(x2.minutes) + println(x2) + println(x3.minutes) + println(x3) +} + |