| @@ -0,0 +1,11 @@ | ||
| /* __ *\ | ||
| ** ________ ___ / / ___ Scala API ** | ||
| ** / __/ __// _ | / / / _ | (c) 2002-2016, LAMP/EPFL ** | ||
| ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
| ** /____/\___/_/ |_/____/_/ | | ** | ||
| ** |/ ** | ||
| \* */ | ||
| package scala | ||
| class enum extends scala.annotation.StaticAnnotation |
| @@ -1,3 +1,4 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| got DEBT | ||
| got FUTURE | ||
| got EQUITY |
| @@ -1,3 +1,4 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| Larry | ||
| Curly | ||
| Moe |
| @@ -1,6 +1,7 @@ | ||
| virtpatmat_unreach_select.scala:10: warning: unreachable code | ||
| case WARNING.id => // unreachable | ||
| ^ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| error: No warnings can be incurred under -Xfatal-warnings. | ||
| one warning found | ||
| two warnings found | ||
| one error found |
| @@ -1,4 +1,5 @@ | ||
| nsc> | ||
| nsc> warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| nsc> | ||
| nsc> |
| @@ -0,0 +1,16 @@ | ||
| warning: there were 8 deprecation warnings (since 2.12.0); re-run with -deprecation for details | ||
| test Test1 was successful | ||
| test Test2 was successful | ||
| test Test3 was successful | ||
| test Test4 was successful | ||
| D1.ValueSet(North, East) | ||
| D2.ValueSet(North, East) | ||
| D1.ValueSet(North, East, West) | ||
| D2.ValueSet(North, East, West) | ||
| List(101) | ||
| List(101) | ||
| D1.ValueSet(North, East) | ||
| D2.ValueSet(North, East) | ||
| WeekDays.ValueSet(Tue, Wed, Thu, Fri) | ||
| @@ -0,0 +1,161 @@ | ||
| //############################################################################ | ||
| // Enumerations | ||
| //############################################################################ | ||
| object Test1 { | ||
| object WeekDays extends Enumeration { | ||
| val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | ||
| } | ||
| def isWorkingDay(d: WeekDays.Value) = | ||
| ! (d == WeekDays.Sat || d == WeekDays.Sun); | ||
| def run: Int = { | ||
| val it = WeekDays.values filter (isWorkingDay); | ||
| it.toList.length | ||
| } | ||
| } | ||
| object Test2 { | ||
| object ThreadState extends Enumeration { | ||
| val New = Value("NEW"); | ||
| val Runnable = Value("RUNNABLE"); | ||
| val Blocked = Value("BLOCKED"); | ||
| val Waiting = Value("WAITING"); | ||
| val TimedWaiting = Value("TIMED_WAITING"); | ||
| val Terminated = Value("TERMINATED"); | ||
| } | ||
| def run: Int = { | ||
| val it = for (s <- ThreadState.values; if s.id != 0) yield s; | ||
| it.toList.length | ||
| } | ||
| } | ||
| object Test3 { | ||
| object Direction extends Enumeration { | ||
| val North = Value("North") | ||
| val South = Value("South") | ||
| val East = Value("East") | ||
| val West = Value("West") | ||
| } | ||
| def run: Int = { | ||
| val it = for (d <- Direction.values; if d.toString() startsWith "N") yield d; | ||
| it.toList.length | ||
| } | ||
| } | ||
| object Test4 { | ||
| object Direction extends Enumeration { | ||
| val North = Value("North") | ||
| val South = Value("South") | ||
| val East = Value("East") | ||
| val West = Value("West") | ||
| } | ||
| def run: Int = { | ||
| val dir = Direction.withName("North") | ||
| assert(dir.toString == "North") | ||
| try { | ||
| Direction.withName("Nord") | ||
| assert(false) | ||
| } catch { | ||
| case e: Exception => /* do nothing */ | ||
| } | ||
| 0 | ||
| } | ||
| } | ||
| object Test5 { | ||
| object D1 extends Enumeration(0) { | ||
| val North, South, East, West = Value; | ||
| } | ||
| object D2 extends Enumeration(-2) { | ||
| val North, South, East, West = Value; | ||
| } | ||
| object WeekDays extends Enumeration { | ||
| val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | ||
| } | ||
| def run { | ||
| val s1 = D1.ValueSet(D1.North, D1.East) | ||
| val s2 = D2.North + D2.East | ||
| println(s1) | ||
| println(s2) | ||
| println(s1 + D1.West) | ||
| println(s2 + D2.West) | ||
| println(s1.toBitMask.map(_.toBinaryString).toList) | ||
| println(s2.toBitMask.map(_.toBinaryString).toList) | ||
| println(D1.ValueSet.fromBitMask(s1.toBitMask)) | ||
| println(D2.ValueSet.fromBitMask(s2.toBitMask)) | ||
| println(WeekDays.values.range(WeekDays.Tue, WeekDays.Sat)) | ||
| } | ||
| } | ||
| object SerializationTest { | ||
| object Types extends Enumeration { val X, Y = Value } | ||
| class A extends java.io.Serializable { val types = Types.values } | ||
| class B extends java.io.Serializable { val types = Set(Types.X, Types.Y) } | ||
| def serialize(obj: AnyRef) = { | ||
| val baos = new java.io.ByteArrayOutputStream() | ||
| val oos = new java.io.ObjectOutputStream(baos) | ||
| oos.writeObject(obj) | ||
| oos.close() | ||
| val bais = new java.io.ByteArrayInputStream(baos.toByteArray) | ||
| val ois = new java.io.ObjectInputStream(bais) | ||
| val prime = ois.readObject() | ||
| ois.close() | ||
| prime | ||
| } | ||
| def run { | ||
| serialize(new B()) | ||
| serialize(new A()) | ||
| } | ||
| } | ||
| //############################################################################ | ||
| // Test code | ||
| object Test { | ||
| def check_success(name: String, closure: => Int, expected: Int): Unit = { | ||
| Console.print("test " + name); | ||
| try { | ||
| val actual: Int = closure; | ||
| if (actual == expected) { | ||
| Console.print(" was successful"); | ||
| } else { | ||
| Console.print(" failed: expected "+ expected +", found "+ actual); | ||
| } | ||
| } catch { | ||
| case exception: Throwable => { | ||
| Console.print(" raised exception " + exception); | ||
| exception.printStackTrace(); | ||
| } | ||
| } | ||
| Console.println; | ||
| } | ||
| def main(args: Array[String]): Unit = { | ||
| check_success("Test1", Test1.run, 5); | ||
| check_success("Test2", Test2.run, 5); | ||
| check_success("Test3", Test3.run, 1); | ||
| check_success("Test4", Test4.run, 0); | ||
| Console.println; | ||
| Test5.run; | ||
| Console.println; | ||
| SerializationTest.run; | ||
| } | ||
| } | ||
| //############################################################################ |
| @@ -1,15 +1,124 @@ | ||
| test Test1 was successful | ||
| test Test2 was successful | ||
| test Test3 was successful | ||
| test Test4 was successful | ||
| D1.ValueSet(North, East) | ||
| D2.ValueSet(North, East) | ||
| D1.ValueSet(North, East, West) | ||
| D2.ValueSet(North, East, West) | ||
| List(101) | ||
| List(101) | ||
| D1.ValueSet(North, East) | ||
| D2.ValueSet(North, East) | ||
| WeekDays.ValueSet(Tue, Wed, Thu, Fri) | ||
| enums.scala:23: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: ConstructorWeek(), Friday, Monday, Thursday, Tuesday, Wednesday | ||
| def isWeekendMissing = this match { | ||
| ^ | ||
| enums.scala:45: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: $anon(), $anon(), $anon(), Friday, MethodWeek(), Monday, Thursday, Tuesday, Wednesday | ||
| def isWeekendMissing = this match { | ||
| ^ | ||
| enums.scala:61: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: $anon(), $anon(), $anon(), ArgNamedWeek(), Friday, Monday, Thursday, Tuesday, Wednesday | ||
| def isWeekendMissing = this match { | ||
| ^ | ||
| enums.scala:77: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: $anon(), $anon(), $anon(), CaseWeek(_), Friday, Monday, Thursday, Tuesday, Wednesday | ||
| def isWeekendCase = this match { | ||
| ^ | ||
| enums.scala:81: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: $anon(), $anon(), $anon(), CaseWeek(_), Friday, Monday, Thursday, Tuesday, Wednesday | ||
| def isWeekendMissing = this match { | ||
| ^ | ||
| enums.scala:163: warning: match may not be exhaustive. | ||
| It would fail on the following inputs: Friday, Monday, Thursday, Tuesday, Wednesday, Week() | ||
| def isWeekendMissing(week: Week) = week match { | ||
| ^ | ||
| ==== enum Empty ==== | ||
| true | ||
| 16401 | ||
| FINAL PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(private Empty(java.lang.String,int)) | ||
| List(public static Empty Empty.valueOf(java.lang.String), public static Empty[] Empty.values()) | ||
| List(private static final Empty[] Empty.$VALUES) | ||
| List() | ||
| ==== enum ReallyEmpty ==== | ||
| true | ||
| 16401 | ||
| FINAL PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(private ReallyEmpty(java.lang.String,int)) | ||
| List(public static ReallyEmpty ReallyEmpty.valueOf(java.lang.String), public static ReallyEmpty[] ReallyEmpty.values()) | ||
| List(private static final ReallyEmpty[] ReallyEmpty.$VALUES) | ||
| List() | ||
| ==== enum Week ==== | ||
| true | ||
| 16401 | ||
| FINAL PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(private Week(java.lang.String,int)) | ||
| List(public static Week Week.valueOf(java.lang.String), public static Week[] Week.values()) | ||
| List(private static final Week[] Week.$VALUES, public static final Week Week.Friday, public static final Week Week.Monday, public static final Week Week.Saturday, public static final Week Week.Sunday, public static final Week Week.Thursday, public static final Week Week.Tuesday, public static final Week Week.Wednesday) | ||
| true | ||
| List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) | ||
| true | ||
| true | ||
| true | ||
| true | ||
| ==== enum ConstructorWeek ==== | ||
| true | ||
| 16401 | ||
| FINAL PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(private ConstructorWeek(java.lang.String,int,boolean)) | ||
| List(public boolean ConstructorWeek.isWeekend(), public boolean ConstructorWeek.isWeekendMissing(), public static ConstructorWeek ConstructorWeek.valueOf(java.lang.String), public static ConstructorWeek[] ConstructorWeek.values()) | ||
| List(private static final ConstructorWeek[] ConstructorWeek.$VALUES, public static final ConstructorWeek ConstructorWeek.Friday, public static final ConstructorWeek ConstructorWeek.Monday, public static final ConstructorWeek ConstructorWeek.Saturday, public static final ConstructorWeek ConstructorWeek.Sunday, public static final ConstructorWeek ConstructorWeek.Thursday, public static final ConstructorWeek ConstructorWeek.Tuesday, public static final ConstructorWeek ConstructorWeek.Wednesday, private final boolean ConstructorWeek.isWeekend) | ||
| true | ||
| List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) | ||
| true | ||
| true | ||
| (List(Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday, Friday)) | ||
| ==== enum MethodWeek ==== | ||
| true | ||
| 16385 | ||
| PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(public MethodWeek(java.lang.String,int)) | ||
| List(public boolean MethodWeek.isGoodDay(), public boolean MethodWeek.isWeekend(), public boolean MethodWeek.isWeekendMissing(), public static MethodWeek MethodWeek.valueOf(java.lang.String), public static MethodWeek[] MethodWeek.values()) | ||
| List(private static final MethodWeek[] MethodWeek.$VALUES, public static final MethodWeek MethodWeek.Friday, public static final MethodWeek MethodWeek.Monday, public static final MethodWeek MethodWeek.Saturday, public static final MethodWeek MethodWeek.Sunday, public static final MethodWeek MethodWeek.Thursday, public static final MethodWeek MethodWeek.Tuesday, public static final MethodWeek MethodWeek.Wednesday) | ||
| true | ||
| List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) | ||
| true | ||
| true | ||
| (List(Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday, Friday)) | ||
| (List(Friday, Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday)) | ||
| ==== enum ArgNamedWeek ==== | ||
| true | ||
| 16385 | ||
| PUBLIC | ||
| class java.lang.Enum | ||
| List() | ||
| List(public ArgNamedWeek(java.lang.String,int,boolean)) | ||
| List(public boolean ArgNamedWeek.isGoodDay(), public boolean ArgNamedWeek.isWeekend(), public boolean ArgNamedWeek.isWeekendMissing(), public static ArgNamedWeek ArgNamedWeek.valueOf(java.lang.String), public static ArgNamedWeek[] ArgNamedWeek.values()) | ||
| List(private static final ArgNamedWeek[] ArgNamedWeek.$VALUES, public static final ArgNamedWeek ArgNamedWeek.Friday, public static final ArgNamedWeek ArgNamedWeek.Monday, public static final ArgNamedWeek ArgNamedWeek.Saturday, public static final ArgNamedWeek ArgNamedWeek.Sunday, public static final ArgNamedWeek ArgNamedWeek.Thursday, public static final ArgNamedWeek ArgNamedWeek.Tuesday, public static final ArgNamedWeek ArgNamedWeek.Wednesday, private final boolean ArgNamedWeek.isWeekend) | ||
| true | ||
| List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) | ||
| true | ||
| true | ||
| (List(Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday, Friday)) | ||
| (List(Friday, Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday)) | ||
| ==== enum CaseWeek ==== | ||
| true | ||
| 16385 | ||
| PUBLIC | ||
| class java.lang.Enum | ||
| List(interface scala.Product, interface scala.Serializable) | ||
| List(public CaseWeek(java.lang.String,int,boolean)) | ||
| List(public static CaseWeek CaseWeek.apply(java.lang.String,int,boolean), public boolean CaseWeek.canEqual(java.lang.Object), public CaseWeek CaseWeek.copy(java.lang.String,int,boolean), public java.lang.String CaseWeek.copy$default$1(), public int CaseWeek.copy$default$2(), public boolean CaseWeek.copy$default$3(), public boolean CaseWeek.isGoodDay(), public boolean CaseWeek.isWeekend(), public boolean CaseWeek.isWeekendCase(), public boolean CaseWeek.isWeekendMissing(), public int CaseWeek.productArity(), public java.lang.Object CaseWeek.productElement(int), public scala.collection.Iterator CaseWeek.productIterator(), public java.lang.String CaseWeek.productPrefix(), public static scala.Option CaseWeek.unapply(CaseWeek), public static CaseWeek CaseWeek.valueOf(java.lang.String), public static CaseWeek[] CaseWeek.values()) | ||
| List(private static final CaseWeek[] CaseWeek.$VALUES, public static final CaseWeek CaseWeek.Friday, public static final CaseWeek CaseWeek.Monday, public static final CaseWeek CaseWeek.Saturday, public static final CaseWeek CaseWeek.Sunday, public static final CaseWeek CaseWeek.Thursday, public static final CaseWeek CaseWeek.Tuesday, public static final CaseWeek CaseWeek.Wednesday, private final boolean CaseWeek.isWeekend, private final java.lang.String CaseWeek.name, private final int CaseWeek.ordinal) | ||
| true | ||
| List(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) | ||
| true | ||
| true | ||
| (List(Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday, Friday)) | ||
| (List(Friday, Saturday, Sunday),List(Monday, Tuesday, Wednesday, Thursday)) |
| @@ -1,161 +1,232 @@ | ||
| //############################################################################ | ||
| // Enumerations | ||
| //############################################################################ | ||
| object Test1 { | ||
| object WeekDays extends Enumeration { | ||
| val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | ||
| } | ||
| @enum class Empty {} | ||
| @enum class ReallyEmpty | ||
| @enum class Week { | ||
| Monday | ||
| Tuesday | ||
| Wednesday | ||
| Thursday | ||
| Friday | ||
| Saturday | ||
| Sunday | ||
| } | ||
| def isWorkingDay(d: WeekDays.Value) = | ||
| ! (d == WeekDays.Sat || d == WeekDays.Sun); | ||
| @enum class ConstructorWeek(val isWeekend: Boolean) { | ||
| Monday(false) | ||
| Tuesday(false) | ||
| Wednesday(false) | ||
| Thursday(false) | ||
| Friday(false) | ||
| Saturday(true) | ||
| Sunday(true) | ||
| def run: Int = { | ||
| val it = WeekDays.values filter (isWorkingDay); | ||
| it.toList.length | ||
| def isWeekendMissing = this match { | ||
| case Saturday | ||
| | ConstructorWeek.Sunday => true | ||
| } | ||
| } | ||
| object Test2 { | ||
| @enum class MethodWeek { | ||
| Monday | ||
| Tuesday | ||
| Wednesday | ||
| Thursday | ||
| Friday { val isGoodDay = true } | ||
| Saturday { def isGoodDay = true } | ||
| Sunday { def isGoodDay = true } | ||
| object ThreadState extends Enumeration { | ||
| val New = Value("NEW"); | ||
| val Runnable = Value("RUNNABLE"); | ||
| val Blocked = Value("BLOCKED"); | ||
| val Waiting = Value("WAITING"); | ||
| val TimedWaiting = Value("TIMED_WAITING"); | ||
| val Terminated = Value("TERMINATED"); | ||
| } | ||
| def isGoodDay: Boolean = false | ||
| def run: Int = { | ||
| val it = for (s <- ThreadState.values; if s.id != 0) yield s; | ||
| it.toList.length | ||
| def isWeekend = this match { | ||
| case Saturday | ||
| | MethodWeek.Sunday => true | ||
| case _ => false | ||
| } | ||
| def isWeekendMissing = this match { | ||
| case Saturday | ||
| | MethodWeek.Sunday => true | ||
| } | ||
| } | ||
| object Test3 { | ||
| @enum class ArgNamedWeek(val isWeekend: Boolean) { | ||
| Monday(false) | ||
| Tuesday(false) | ||
| Wednesday(false) | ||
| Thursday(false) | ||
| Friday(false) { val isGoodDay = true } | ||
| Saturday(true) { def isGoodDay = true } | ||
| Sunday(isWeekend = true) { def isGoodDay = true } | ||
| object Direction extends Enumeration { | ||
| val North = Value("North") | ||
| val South = Value("South") | ||
| val East = Value("East") | ||
| val West = Value("West") | ||
| } | ||
| def run: Int = { | ||
| val it = for (d <- Direction.values; if d.toString() startsWith "N") yield d; | ||
| it.toList.length | ||
| def isGoodDay: Boolean = false | ||
| def isWeekendMissing = this match { | ||
| case Saturday | ||
| | ArgNamedWeek.Sunday => true | ||
| } | ||
| } | ||
| object Test4 { | ||
| @enum case class CaseWeek(isWeekend: Boolean) { | ||
| Monday(false) | ||
| Tuesday(false) | ||
| Wednesday(false) | ||
| Thursday(false) | ||
| Friday(false) { val isGoodDay = true } | ||
| Saturday(true) { def isGoodDay = true } | ||
| Sunday(isWeekend = true) { def isGoodDay = true } | ||
| object Direction extends Enumeration { | ||
| val North = Value("North") | ||
| val South = Value("South") | ||
| val East = Value("East") | ||
| val West = Value("West") | ||
| def isGoodDay: Boolean = false | ||
| def isWeekendCase = this match { | ||
| case Saturday //(true) | ||
| | CaseWeek.Sunday => true | ||
| } | ||
| def run: Int = { | ||
| val dir = Direction.withName("North") | ||
| assert(dir.toString == "North") | ||
| try { | ||
| Direction.withName("Nord") | ||
| assert(false) | ||
| } catch { | ||
| case e: Exception => /* do nothing */ | ||
| } | ||
| 0 | ||
| def isWeekendMissing = this match { | ||
| case Saturday | ||
| | CaseWeek.Sunday => true | ||
| } | ||
| } | ||
| object Test5 { | ||
| /* | ||
| @enum class ArgDefaultWeek(isWeekend: Boolean = false) { | ||
| Monday | ||
| Tuesday | ||
| Wednesday | ||
| Thursday | ||
| Friday | ||
| Saturday(true) | ||
| Sunday(true) | ||
| } | ||
| object D1 extends Enumeration(0) { | ||
| val North, South, East, West = Value; | ||
| object Nested { | ||
| @enum class Week { | ||
| Monday | ||
| Tuesday | ||
| Wednesday | ||
| Thursday | ||
| Friday | ||
| Saturday | ||
| Sunday | ||
| } | ||
| } | ||
| object D2 extends Enumeration(-2) { | ||
| val North, South, East, West = Value; | ||
| class Nested { | ||
| @enum class Week { | ||
| Monday | ||
| Tuesday | ||
| Wednesday | ||
| Thursday | ||
| Friday | ||
| Saturday | ||
| Sunday | ||
| } | ||
| } | ||
| */ | ||
| object WeekDays extends Enumeration { | ||
| val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | ||
| } | ||
| /* | ||
| @enum sealed abstract class EmptyADT | ||
| def run { | ||
| val s1 = D1.ValueSet(D1.North, D1.East) | ||
| val s2 = D2.North + D2.East | ||
| println(s1) | ||
| println(s2) | ||
| println(s1 + D1.West) | ||
| println(s2 + D2.West) | ||
| println(s1.toBitMask.map(_.toBinaryString).toList) | ||
| println(s2.toBitMask.map(_.toBinaryString).toList) | ||
| println(D1.ValueSet.fromBitMask(s1.toBitMask)) | ||
| println(D2.ValueSet.fromBitMask(s2.toBitMask)) | ||
| println(WeekDays.values.range(WeekDays.Tue, WeekDays.Sat)) | ||
| } | ||
| } | ||
| @enum sealed abstract class ADT | ||
| object One extends ADT | ||
| object SerializationTest { | ||
| object Types extends Enumeration { val X, Y = Value } | ||
| class A extends java.io.Serializable { val types = Types.values } | ||
| class B extends java.io.Serializable { val types = Set(Types.X, Types.Y) } | ||
| def serialize(obj: AnyRef) = { | ||
| val baos = new java.io.ByteArrayOutputStream() | ||
| val oos = new java.io.ObjectOutputStream(baos) | ||
| oos.writeObject(obj) | ||
| oos.close() | ||
| val bais = new java.io.ByteArrayInputStream(baos.toByteArray) | ||
| val ois = new java.io.ObjectInputStream(bais) | ||
| val prime = ois.readObject() | ||
| ois.close() | ||
| prime | ||
| } | ||
| @enum sealed abstract class CaseADT | ||
| case object One | ||
| def run { | ||
| serialize(new B()) | ||
| serialize(new A()) | ||
| } | ||
| @enum sealed abstract class NestedADT | ||
| object NestedADT { | ||
| object One | ||
| } | ||
| //############################################################################ | ||
| // Test code | ||
| object Test { | ||
| def check_success(name: String, closure: => Int, expected: Int): Unit = { | ||
| Console.print("test " + name); | ||
| try { | ||
| val actual: Int = closure; | ||
| if (actual == expected) { | ||
| Console.print(" was successful"); | ||
| } else { | ||
| Console.print(" failed: expected "+ expected +", found "+ actual); | ||
| } | ||
| } catch { | ||
| case exception: Throwable => { | ||
| Console.print(" raised exception " + exception); | ||
| exception.printStackTrace(); | ||
| } | ||
| } | ||
| Console.println; | ||
| } | ||
| def main(args: Array[String]): Unit = { | ||
| check_success("Test1", Test1.run, 5); | ||
| check_success("Test2", Test2.run, 5); | ||
| check_success("Test3", Test3.run, 1); | ||
| check_success("Test4", Test4.run, 0); | ||
| Console.println; | ||
| Test5.run; | ||
| Console.println; | ||
| SerializationTest.run; | ||
| @enum sealed abstract class NestedCaseADT | ||
| object NestedCaseADT { | ||
| case object One | ||
| } | ||
| */ | ||
| object Test extends App { | ||
| printEnumInfo(classOf[Empty]) | ||
| println(Empty.values.toList) | ||
| println() | ||
| printEnumInfo(classOf[ReallyEmpty]) | ||
| println(ReallyEmpty.values.toList) | ||
| println() | ||
| printEnumInfo(classOf[Week]) | ||
| println(Week.Monday.getClass.isEnum) | ||
| println(Week.values.toList) | ||
| println(Week.valueOf("Friday") == Week.Friday) | ||
| println(Week.Saturday.compareTo(Week.Sunday) < 0) | ||
| println(isWeekendMissing(Week.Sunday)) | ||
| println(!isWeekendComplete(Week.Thursday)) | ||
| println() | ||
| // warning: match may not be exhaustive. | ||
| // It would fail on the following inputs: Friday, Monday, Tuesday, Wednesday, Week() | ||
| def isWeekendMissing(week: Week) = week match { | ||
| case Week.Saturday | ||
| | Week.Sunday => true | ||
| } | ||
| def isWeekendComplete(week: Week) = week match { | ||
| case Week.Saturday | ||
| | Week.Sunday => true | ||
| case _ => false | ||
| } | ||
| printEnumInfo(classOf[ConstructorWeek]) | ||
| println(ConstructorWeek.Monday.getClass.isEnum) | ||
| println(ConstructorWeek.values.toList) | ||
| println(ConstructorWeek.valueOf("Friday") == ConstructorWeek.Friday) | ||
| println(ConstructorWeek.Saturday.compareTo(ConstructorWeek.Sunday) < 0) | ||
| println(ConstructorWeek.values.toList.partition(_.isWeekend)) | ||
| println() | ||
| printEnumInfo(classOf[MethodWeek]) | ||
| println(MethodWeek.Monday.getClass.isEnum) | ||
| println(MethodWeek.values.toList) | ||
| println(MethodWeek.valueOf("Friday") == MethodWeek.Friday) | ||
| println(MethodWeek.Saturday.compareTo(MethodWeek.Sunday) < 0) | ||
| println(MethodWeek.values.toList.partition(_.isWeekend)) | ||
| println(MethodWeek.values.toList.partition(_.isGoodDay)) | ||
| println() | ||
| printEnumInfo(classOf[ArgNamedWeek]) | ||
| println(ArgNamedWeek.Monday.getClass.isEnum) | ||
| println(ArgNamedWeek.values.toList) | ||
| println(ArgNamedWeek.valueOf("Friday") == ArgNamedWeek.Friday) | ||
| println(ArgNamedWeek.Saturday.compareTo(ArgNamedWeek.Sunday) < 0) | ||
| println(ArgNamedWeek.values.toList.partition(_.isWeekend)) | ||
| println(ArgNamedWeek.values.toList.partition(_.isGoodDay)) | ||
| println() | ||
| printEnumInfo(classOf[CaseWeek]) | ||
| println(CaseWeek.Monday.getClass.isEnum) | ||
| println(CaseWeek.values.toList) | ||
| println(CaseWeek.valueOf("Friday") == CaseWeek.Friday) | ||
| println(CaseWeek.Saturday.compareTo(CaseWeek.Sunday) < 0) | ||
| println(CaseWeek.values.toList.partition(_.isWeekend)) | ||
| println(CaseWeek.values.toList.partition(_.isGoodDay)) | ||
| def modifiersToString(flags: Int): String = { | ||
| import java.lang.reflect.Modifier | ||
| var buf = new StringBuilder | ||
| if (Modifier.isAbstract (flags)) buf ++= "ABSTRACT " | ||
| if (Modifier.isFinal (flags)) buf ++= "FINAL " | ||
| if (Modifier.isInterface(flags)) buf ++= "INTERFACE " | ||
| if (Modifier.isPrivate (flags)) buf ++= "PRIVATE " | ||
| if (Modifier.isProtected(flags)) buf ++= "PROTECTED " | ||
| if (Modifier.isPublic (flags)) buf ++= "PUBLIC " | ||
| if (Modifier.isStatic (flags)) buf ++= "STATIC " | ||
| buf = buf.init | ||
| buf.toString() | ||
| } | ||
| def printEnumInfo(clazz: Class[_ <: Enum[_]]): Unit = { | ||
| println(s"==== enum ${clazz.getSimpleName} ====") | ||
| println(clazz.isEnum) | ||
| println(clazz.getModifiers) | ||
| println(modifiersToString(clazz.getModifiers)) | ||
| println(clazz.getSuperclass) | ||
| println(clazz.getInterfaces.toList) | ||
| println(clazz.getDeclaredConstructors.toList) | ||
| println(clazz.getDeclaredMethods.toList.sortBy(_.getName)) | ||
| println(clazz.getDeclaredFields.toList.sortBy(_.getName)) | ||
| } | ||
| } | ||
| //############################################################################ |
| @@ -0,0 +1 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details |
| @@ -0,0 +1 @@ | ||
| warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details |
| @@ -0,0 +1 @@ | ||
| warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details |
| @@ -1 +1,2 @@ | ||
| warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details | ||
| false |
| @@ -1 +1,2 @@ | ||
| warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details | ||
| Fruit.ValueSet(A, B, C) |
| @@ -1,2 +1,3 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| t.ValueSet(a, b) | ||
| t.ValueSet(a, b) | ||
| t.ValueSet(a, b) |
| @@ -1,4 +1,5 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| List(Mon, Tue, Wed, Thu, Fri, Sat, Sun) | ||
| Mon | ||
| Tue | ||
| Mon | ||
| Mon |
| @@ -1,3 +1,4 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| minus | ||
| zero | ||
| plus | ||
| plus |
| @@ -1 +1,2 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| foo |
| @@ -1,2 +1,3 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details | ||
| true | ||
| true |
| @@ -0,0 +1 @@ | ||
| warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details |
| @@ -0,0 +1 @@ | ||
| warning: there was one deprecation warning (since 2.12.0); re-run with -deprecation for details |