-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75b44cf
commit 229dfc4
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package re2s | ||
|
||
import org.scalatest.FunSuite | ||
|
||
class StrconvSuite() extends FunSuite { | ||
private def rune(r: Int) = new StringBuffer().appendCodePoint(r).toString | ||
|
||
private val UNQUOTE_TESTS = Array( | ||
Array("\"\"", ""), | ||
Array("\"a\"", "a"), | ||
Array("\"abc\"", "abc"), | ||
Array("\"☺\"", "☺"), | ||
Array("\"hello world\"", "hello world"), | ||
Array("\"\\xFF\"", "\u00FF"), | ||
Array("\"\\377\"", "\377"), | ||
Array("\"\\u1234\"", "\u1234"), | ||
Array("\"\\U00010111\"", rune(0x10111)), | ||
Array("\"\\U0001011111\"", rune(0x10111) + "11"), | ||
Array("\"\\a\\b\\f\\n\\r\\t\\v\\\\\\\"\"", "\007\b\f\n\r\t\013\\\""), | ||
Array("\"'\"", "'"), | ||
Array("'a'", "a"), | ||
Array("'☹'", "☹"), | ||
Array("'\\a'", "\u0007"), | ||
Array("'\\x10'", "\u0010"), | ||
Array("'\\377'", "\377"), | ||
Array("'\\u1234'", "\u1234"), | ||
Array("'\\U00010111'", rune(0x10111)), | ||
Array("'\\t'", "\t"), | ||
Array("' '", " "), | ||
Array("'\\''", "'"), | ||
Array("'\"'", "\""), | ||
Array("``", ""), | ||
Array("`a`", "a"), | ||
Array("`abc`", "abc"), | ||
Array("`☺`", "☺"), | ||
Array("`hello world`", "hello world"), | ||
Array("`\\xFF`", "\\xFF"), | ||
Array("`\\377`", "\\377"), | ||
Array("`\\`", "\\"), | ||
Array("`\n`", "\n"), | ||
Array("`\t`", "\t"), | ||
Array("` `", " "), // Misquoted strings, should produce an error. | ||
Array("", null), | ||
Array("\"", null), | ||
Array("\"a", null), | ||
Array("\"'", null), | ||
Array("b\"", null), | ||
Array("\"\\\"", null), | ||
Array("'\\'", null), | ||
Array("'ab'", null), | ||
Array("\"\\x1!\"", null), | ||
Array("\"\\U12345678\"", null), | ||
Array("\"\\z\"", null), | ||
Array("`", null), | ||
Array("`xxx", null), | ||
Array("`\"", null), | ||
Array("\"\\'\"", null), | ||
Array("'\\\"'", null), | ||
Array("\"\n\"", null), | ||
Array("\"\\n\n\"", null), | ||
Array("'\n'", null) | ||
) | ||
|
||
test("Unquote") { | ||
for (Array(input, expected) <- UNQUOTE_TESTS) { | ||
if (expected != null) | ||
assert(expected == Strconv.unquote(input), "unquote(%s)".format(input)) | ||
else | ||
try { | ||
Strconv.unquote(input) | ||
fail(String.format("unquote(%s) succeeded unexpectedly", input)) | ||
} catch { | ||
case e: IllegalArgumentException => | ||
/* ok */ | ||
case e: StringIndexOutOfBoundsException => | ||
} | ||
// TODO(adonovan): port and run the quote tests too, backward | ||
} | ||
} | ||
} |