diff options
Diffstat (limited to 'test/junit/scala/util')
-rw-r--r-- | test/junit/scala/util/SystemPropertiesTest.scala | 27 | ||||
-rw-r--r-- | test/junit/scala/util/control/ExceptionTest.scala | 42 | ||||
-rw-r--r-- | test/junit/scala/util/matching/RegexTest.scala | 64 |
3 files changed, 133 insertions, 0 deletions
diff --git a/test/junit/scala/util/SystemPropertiesTest.scala b/test/junit/scala/util/SystemPropertiesTest.scala new file mode 100644 index 0000000000..38e830eb88 --- /dev/null +++ b/test/junit/scala/util/SystemPropertiesTest.scala @@ -0,0 +1,27 @@ +package scala.util + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +@RunWith(classOf[JUnit4]) +class SystemPropertiesTest { + @Test + def filterAll(): Unit = { + val isEmpty = sys.props.filter(_ => false).size == 0 + assertTrue("A filter matching nothing should produce an empty result", isEmpty) + } + + @Test + def filterNone(): Unit = { + val isUnchanged = sys.props.filter(_ => true) == sys.props + assertTrue("A filter matching everything should not change the result", isUnchanged) + } + + @Test + def empty(): Unit = { + val hasSize0 = sys.props.empty.size == 0 + assertTrue("SystemProperties.empty should have size of 0", hasSize0) + } +} diff --git a/test/junit/scala/util/control/ExceptionTest.scala b/test/junit/scala/util/control/ExceptionTest.scala new file mode 100644 index 0000000000..5211d31839 --- /dev/null +++ b/test/junit/scala/util/control/ExceptionTest.scala @@ -0,0 +1,42 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2016-2016, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.util + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +import scala.collection.mutable.ListBuffer + +import scala.util.control.Exception._ + +@RunWith(classOf[JUnit4]) +class ExceptionTest { + + @Test + def andFinally(): Unit = { + + locally { + val audit = ListBuffer[Int]() + val katch = nonFatalCatch[Unit].andFinally(audit append 1) + val result = katch(10) + assertEquals(result, 10) + assertEquals(audit.toList, 1 :: Nil) + } + + locally { + val audit = ListBuffer[Int]() + val katch = nonFatalCatch[Unit].andFinally(audit append 1).andFinally(audit append 2) + val result = katch(20) + assertEquals(result, 20) + assertEquals(audit.toList, 1 :: 2 :: Nil) + } + } +}
\ No newline at end of file diff --git a/test/junit/scala/util/matching/RegexTest.scala b/test/junit/scala/util/matching/RegexTest.scala index 5b13397d6a..06d0445e1c 100644 --- a/test/junit/scala/util/matching/RegexTest.scala +++ b/test/junit/scala/util/matching/RegexTest.scala @@ -6,6 +6,8 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import scala.tools.testing.AssertUtil._ + @RunWith(classOf[JUnit4]) class RegexTest { @Test def t8022CharSequence(): Unit = { @@ -44,4 +46,66 @@ class RegexTest { } assertEquals(List((1,2),(3,4),(5,6)), z) } + + @Test def `SI-9666: use inline group names`(): Unit = { + val r = new Regex("a(?<Bee>b*)c") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertFalse(ms.hasNext) + } + + @Test def `SI-9666: use explicit group names`(): Unit = { + val r = new Regex("a(b*)c", "Bee") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertFalse(ms.hasNext) + } + + @Test def `SI-9666: fall back to explicit group names`(): Unit = { + val r = new Regex("a(?<Bar>b*)c", "Bee") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertEquals("bbb", ms group "Bar") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertEquals("b", ms group "Bar") + assertFalse(ms.hasNext) + } + + //type NoGroup = NoSuchElementException + type NoGroup = IllegalArgumentException + + @Test def `SI-9666: throw on bad name`(): Unit = { + assertThrows[NoGroup] { + val r = new Regex("a(?<Bar>b*)c") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + assertThrows[NoGroup] { + val r = new Regex("a(?<Bar>b*)c", "Bar") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + assertThrows[NoGroup] { + val r = new Regex("a(b*)c", "Bar") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + } } |