diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-08-25 10:15:04 -0700 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2014-09-05 20:27:59 +0200 |
commit | 7655a70489f565a5a7a165f893b4a1e44c3cb2b8 (patch) | |
tree | 9a2a54ae5802211c5444006ffea06aef497bbe3b /test | |
parent | b562d965dc30bb1fdd9433a6675bfe8e38b8c667 (diff) | |
download | scala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.tar.gz scala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.tar.bz2 scala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.zip |
Use Enumeration for MultiChoiceSetting
This is pretty easy, since a ValueSet is a BitSet.
When the setting is updated, recompute the current
set of values, which is cheap and succinct.
Checking a flag is also easy and fast.
Choices in MultiChoiceSettings may enable other choices.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/tools/nsc/settings/SettingsTest.scala | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index a0e015be32..0b8029326e 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -96,7 +96,7 @@ class SettingsTest { // make sure that lint.contains and lint.value.contains are consistent def t(s: MutableSettings, v: String) = { val r = s.lint.contains(v) - assertSame(r, s.lint.value.contains(v)) + assertSame(r, s.lint.value.contains((s.LintWarnings withName v).asInstanceOf[s.lint.domain.Value])) r } @@ -118,4 +118,48 @@ class SettingsTest { assertFalse(check("-Ywarn-adapted-args:false", "-Xlint:_,-adapted-args")(_.warnAdaptedArgs)) assertTrue(check("-Ywarn-adapted-args:false", "-Xlint:_,adapted-args")(_.warnAdaptedArgs)) } + + @Test def expandingMultichoice(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a") + val b = Choice("b") + val c = Choice("c") + val d = Choice("d") + + val ab = Choice("ab", expandsTo = List(a, b)) + val ac = Choice("ac", expandsTo = List(a, c)) + val uber = Choice("uber", expandsTo = List(ab, d)) + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("ac"))) + + def check(args: String*)(t: s.MultiChoiceSetting[mChoices.type] => Boolean): Boolean = { + m.clear() + val (ok, rest) = s.processArguments(args.toList, processAll = true) + assert(rest.isEmpty) + t(m) + } + + import mChoices._ + + assertTrue(check("-m")(_.value == Set(a,c))) + assertTrue(check("-m:a,-b,c")(_.value == Set(a,c))) + + // expanding options don't end up in the value set, only the terminal ones + assertTrue(check("-m:ab,ac")(_.value == Set(a,b,c))) + assertTrue(check("-m:_")(_.value == Set(a,b,c,d))) + assertTrue(check("-m:uber,ac")(_.value == Set(a,b,c,d))) // recursive expansion of uber + + // explicit nays + assertTrue(check("-m:_,-b")(_.value == Set(a,c,d))) + assertTrue(check("-m:b,_,-b")(_.value == Set(a,b,c,d))) + assertTrue(check("-m:ac,-c")(_.value == Set(a))) + assertTrue(check("-m:ac,-a,-c")(_.value == Set())) + assertTrue(check("-m:-d,ac")(_.value == Set(a,c))) + assertTrue(check("-m:-b,ac,uber")(_.value == Set(a,c,d))) + + assertThrows[IllegalArgumentException](check("-m:-_")(_ => true), _ contains "'-_' is not a valid choice") + assertThrows[IllegalArgumentException](check("-m:a,b,-ab")(_ => true), _ contains "'ab' cannot be negated") + assertThrows[IllegalArgumentException](check("-m:a,ac,-uber,uber")(_ => true), _ contains "'uber' cannot be negated") + } } |