diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-11-28 13:11:48 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2014-12-05 12:13:31 -0800 |
commit | be553aaa5a765b1d1511688d58f01ec675549412 (patch) | |
tree | bbaf5500619b08c55a35a296db36962822d3a7a7 /test/files/run/literals.scala | |
parent | 028420cd80a2cf1127790fdd28088f6db575e8dd (diff) | |
download | scala-be553aaa5a765b1d1511688d58f01ec675549412.tar.gz scala-be553aaa5a765b1d1511688d58f01ec675549412.tar.bz2 scala-be553aaa5a765b1d1511688d58f01ec675549412.zip |
SI-9015 Reject 0x and minor parser cleanup
Only print error results. Show deprecated forms.
Test for rejected literals and clean up parser
There was no negative test for what constitutes a legal literal.
The ultimate goal is for the test to report all errors in
one compilation.
This commit follows up the removal of "1." syntax to simplify
number parsing. It removes previous paulp code to contain the
erstwhile complexity.
Leading zero is not immediately put to the buffer. Instead,
the empty buffer is handled on evaluation. In particular, an
empty buffer due to `0x` is a syntax error.
The message for obsolete octal syntax is nuanced and deferred
until evaluation by the parser, which is slightly simpler to
reason about.
Improve comment on usage of base
The slice-and-dicey usage of base deserves a better
comment. The difference is that `intVal` sees an empty
char buffer for input `"0"`.
Diffstat (limited to 'test/files/run/literals.scala')
-rw-r--r-- | test/files/run/literals.scala | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/test/files/run/literals.scala b/test/files/run/literals.scala index 5f23e6b492..13fda05876 100644 --- a/test/files/run/literals.scala +++ b/test/files/run/literals.scala @@ -14,21 +14,16 @@ object Test { def \u03b1\u03b1(that: GGG) = i + that.i } - def check_success[a](name: String, closure: => a, expected: a) { - print("test " + name) - try { - val actual: a = closure - if (actual == expected) { - print(" was successful"); - } else { - print(" failed: expected "+ expected +", found "+ actual); + def check_success[A](name: String, closure: => A, expected: A) { + val res: Option[String] = + try { + val actual: A = closure + if (actual == expected) None //print(" was successful") + else Some(s" failed: expected $expected, found $actual") + } catch { + case exception: Throwable => Some(s" raised exception $exception") } - } catch { - case exception: Throwable => { - print(" raised exception " + exception); - } - } - println + for (e <- res) println(s"test $name $e") } def main(args: Array[String]) { @@ -37,15 +32,14 @@ object Test { check_success("'\\u005f' == '_'", '\u005f', '_') check_success("65.asInstanceOf[Char] == 'A'", 65.asInstanceOf[Char], 'A') check_success("\"\\141\\142\" == \"ab\"", "\141\142", "ab") - check_success("\"\\0x61\\0x62\".trim() == \"x61\\0x62\"", "\0x61\0x62".substring(1), "x61\0x62") - - println + //check_success("\"\\0x61\\0x62\".trim() == \"x61\\0x62\"", "\0x61\0x62".substring(1), "x61\0x62") + check_success(""""\0x61\0x62".getBytes == Array(0, 120, ...)""", + "\0x61\0x62".getBytes(io.Codec.UTF8.charSet) sameElements Array[Byte](0, 120, 54, 49, 0, 120, 54, 50), + true) // boolean check_success("(65 : Byte) == 'A'", (65: Byte) == 'A', true) // contrib #176 - println - // int check_success("0X01 == 1", 0X01, 1) check_success("0x01 == 1", 0x01, 1) @@ -67,8 +61,6 @@ object Test { check_success("0x80000000 == -2147483648", 0x80000000, -2147483648) check_success("0xffffffff == -1", 0xffffffff, -1) - println - // long check_success("1l == 1L", 1l, 1L) check_success("1L == 1l", 1L, 1l) @@ -81,8 +73,6 @@ object Test { check_success("0xffffffffffffffffL == -1L", 0xffffffffffffffffL, -1L) - println - // see JLS at address: // http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#230798 @@ -97,8 +87,6 @@ object Test { check_success("1.asInstanceOf[Float] == 1.0", 1.asInstanceOf[Float], 1.0f) check_success("1l.asInstanceOf[Float] == 1.0", 1l.asInstanceOf[Float], 1.0f) - println - // double check_success("1e1 == 10.0", 1e1, 10.0) check_success(".3 == 0.3", .3, 0.3) @@ -112,7 +100,6 @@ object Test { check_success("1.asInstanceOf[Double] == 1.0", 1.asInstanceOf[Double], 1.0) check_success("1l.asInstanceOf[Double] == 1.0", 1l.asInstanceOf[Double], 1.0) - println check_success("\"\".length()", "\u001a".length(), 1) val ggg = GGG(1) \u03b1\u03b1 GGG(2) |