From 65753433c3a34105a7c66588b0ee7de7732bff9e Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Mon, 8 Jul 2019 11:39:45 -0700 Subject: [PATCH] remove long-deprecated scala.util.parsing.json fixes #221 --- README.md | 2 +- .../scala/util/parsing/combinator/t4929.scala | 41 --- .../scala/scala/util/parsing/json/JSON.scala | 100 ------ .../scala/scala/util/parsing/json/Lexer.scala | 92 ------ .../scala/util/parsing/json/Parser.scala | 149 --------- .../scala/util/parsing/json/package.scala | 20 -- .../util/parsing/combinator/JsonTest.scala | 305 ------------------ .../util/parsing/combinator/UnitTestIO.scala | 31 -- 8 files changed, 1 insertion(+), 739 deletions(-) delete mode 100644 jvm/src/test/scala/scala/util/parsing/combinator/t4929.scala delete mode 100644 shared/src/main/scala/scala/util/parsing/json/JSON.scala delete mode 100644 shared/src/main/scala/scala/util/parsing/json/Lexer.scala delete mode 100644 shared/src/main/scala/scala/util/parsing/json/Parser.scala delete mode 100644 shared/src/main/scala/scala/util/parsing/json/package.scala delete mode 100644 shared/src/test/scala/scala/util/parsing/combinator/JsonTest.scala delete mode 100644 shared/src/test/scala/scala/util/parsing/combinator/UnitTestIO.scala diff --git a/README.md b/README.md index f79d3e24..75ceca31 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ As of Scala 2.11, this library is a separate jar that can be omitted from Scala * [Current API](https://javadoc.io/page/org.scala-lang.modules/scala-parser-combinators_2.12/latest/scala/util/parsing/combinator/index.html) * The [Getting Started](docs/Getting_Started.md) guide * A more complicated example, [Building a lexer and parser with Scala's Parser Combinators](https://enear.github.io/2016/03/31/parser-combinators/) - * "Combinator Parsing", chapter 33 of [_Programming in Scala, Third Edition_](http://www.artima.com/shop/programming_in_scala), shows how to use this library to parse arithmetic expressions and JSON. The second half of the chapter examines how the library is implemented. + * "Combinator Parsing", chapter 33 of [_Programming in Scala, Third Edition_](http://www.artima.com/shop/programming_in_scala), shows how to apply this library to e.g. parsing of arithmetic expressions. The second half of the chapter examines how the library is implemented. ## Adding an sbt dependency To depend on scala-parser-combinators in sbt, add something like this to your build.sbt: diff --git a/jvm/src/test/scala/scala/util/parsing/combinator/t4929.scala b/jvm/src/test/scala/scala/util/parsing/combinator/t4929.scala deleted file mode 100644 index f0bd3158..00000000 --- a/jvm/src/test/scala/scala/util/parsing/combinator/t4929.scala +++ /dev/null @@ -1,41 +0,0 @@ -import scala.util.parsing.json._ -import java.util.concurrent._ -import collection.JavaConverters._ - -import org.junit.Test - -class t4929 { - - val LIMIT = 2000 - val THREAD_COUNT = 20 - val count = new java.util.concurrent.atomic.AtomicInteger(0) - - val begin = new CountDownLatch(THREAD_COUNT) - val finish = new CountDownLatch(THREAD_COUNT) - - val errors = new ConcurrentLinkedQueue[Throwable] - - @Test - def test: Unit = { - (1 to THREAD_COUNT) foreach { i => - val thread = new Thread { - override def run(): Unit = { - begin.await(1, TimeUnit.SECONDS) - try { - while (count.getAndIncrement() < LIMIT && errors.isEmpty) { - JSON.parseFull("""{"foo": [1,2,3,4]}""") - } - } catch { - case t: Throwable => errors.add(t) - } - - finish.await(10, TimeUnit.SECONDS) - } - } - - thread.setDaemon(true) - thread.start() - } - errors.asScala foreach { throw(_) } - } -} diff --git a/shared/src/main/scala/scala/util/parsing/json/JSON.scala b/shared/src/main/scala/scala/util/parsing/json/JSON.scala deleted file mode 100644 index 9e7fee3d..00000000 --- a/shared/src/main/scala/scala/util/parsing/json/JSON.scala +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala -package util.parsing.json - -/** - * This object provides a simple interface to the JSON parser class. - * The default conversion for numerics is into a double. If you wish to - * override this behavior at the global level, you can set the - * `globalNumberParser` property to your own `(String => Any)` function. - * If you only want to override at the per-thread level then you can set - * the `perThreadNumberParser` property to your function. For example: - * {{{ - * val myConversionFunc = {input : String => BigDecimal(input)} - * - * // Global override - * JSON.globalNumberParser = myConversionFunc - * - * // Per-thread override - * JSON.perThreadNumberParser = myConversionFunc - * }}} - * - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -object JSON extends Parser { - - /** - * This method converts ''raw'' results back into the original form. - */ - private def unRaw (in : Any) : Any = in match { - case JSONObject(obj) => obj.map({ case (k,v) => (k,unRaw(v))}).toList - case JSONArray(list) => list.map(unRaw) - case x => x - } - - /** - * Parse the given `JSON` string and return a list of elements. If the - * string is a `JSON` object it will be a `JSONObject`. If it's a `JSON` - * array it will be a `JSONArray`. - * - * @param input the given `JSON` string. - * @return an optional `JSONType` element. - */ - def parseRaw(input : String) : Option[JSONType] = - phrase(root)(new lexical.Scanner(input)) match { - case Success(result, _) => Some(result) - case _ => None - } - - /** - * Parse the given `JSON` string and return either a `List[Any]` - * if the `JSON` string specifies an `Array`, or a - * `Map[String,Any]` if the `JSON` string specifies an object. - * - * @param input the given `JSON` string. - * @return an optional list or map. - */ - def parseFull(input: String): Option[Any] = - parseRaw(input) match { - case Some(data) => Some(resolveType(data)) - case None => None - } - - /** - * A utility method to resolve a parsed `JSON` list into objects or - * arrays. See the `parse` method for details. - */ - def resolveType(input: Any): Any = input match { - case JSONObject(data) => data.transform { - case (k,v) => resolveType(v) - } - case JSONArray(data) => data.map(resolveType) - case x => x - } - - /** - * The global (VM) default function for converting a string to a numeric value. - */ - def globalNumberParser_=(f: NumericParser): Unit = { defaultNumberParser = f } - def globalNumberParser : NumericParser = defaultNumberParser - - /** - * Defines the function used to convert a numeric string literal into a - * numeric format on a per-thread basis. Use `globalNumberParser` for a - * global override. - */ - def perThreadNumberParser_=(f : NumericParser): Unit = { numberParser.set(f) } - def perThreadNumberParser : NumericParser = numberParser.get() -} diff --git a/shared/src/main/scala/scala/util/parsing/json/Lexer.scala b/shared/src/main/scala/scala/util/parsing/json/Lexer.scala deleted file mode 100644 index cd18ac75..00000000 --- a/shared/src/main/scala/scala/util/parsing/json/Lexer.scala +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala -package util.parsing.json - -import scala.util.parsing.combinator._ -import scala.util.parsing.combinator.lexical._ -import scala.util.parsing.input.CharArrayReader.EofCh - -/** - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -class Lexer extends StdLexical with ImplicitConversions { - - override def token: Parser[Token] = - //( '\"' ~ rep(charSeq | letter) ~ '\"' ^^ lift(StringLit) - ( string ^^ StringLit - | number ~ letter ^^ { case n ~ l => ErrorToken("Invalid number format : " + n + l) } - | '-' ~> whitespace ~ number ~ letter ^^ { case ws ~ num ~ l => ErrorToken("Invalid number format : -" + num + l) } - | '-' ~> whitespace ~ number ^^ { case ws ~ num => NumericLit("-" + num) } - | number ^^ NumericLit - | EofCh ^^^ EOF - | delim - | '\"' ~> failure("Unterminated string") - | rep(letter) ^^ checkKeyword - | failure("Illegal character") - ) - - def checkKeyword(xs : List[Any]) = { - val strRep = xs mkString "" - if (reserved contains strRep) Keyword(strRep) else ErrorToken("Not a keyword: " + strRep) - } - - /** A string is a collection of zero or more Unicode characters, wrapped in - * double quotes, using backslash escapes (cf. http://www.json.org/). - */ - def string = '\"' ~> rep(charSeq | chrExcept('\"', '\n', EofCh)) <~ '\"' ^^ { _ mkString "" } - - override def whitespace = rep(whitespaceChar) - - def number = intPart ~ opt(fracPart) ~ opt(expPart) ^^ { case i ~ f ~ e => - i + optString(".", f) + optString("", e) - } - def intPart = zero | intList - def intList = nonzero ~ rep(digit) ^^ {case x ~ y => (x :: y) mkString ""} - def fracPart = '.' ~> rep(digit) ^^ { _ mkString "" } - def expPart = exponent ~ opt(sign) ~ rep1(digit) ^^ { case e ~ s ~ d => - e + optString("", s) + d.mkString("") - } - - private def optString[A](pre: String, a: Option[A]) = a match { - case Some(x) => pre + x.toString - case None => "" - } - - def zero: Parser[String] = '0' ^^^ "0" - def nonzero = elem("nonzero digit", d => d.isDigit && d != '0') - def exponent = elem("exponent character", d => d == 'e' || d == 'E') - def sign = elem("sign character", d => d == '-' || d == '+') - - def charSeq: Parser[String] = - ('\\' ~ '\"' ^^^ "\"" - |'\\' ~ '\\' ^^^ "\\" - |'\\' ~ '/' ^^^ "/" - |'\\' ~ 'b' ^^^ "\b" - |'\\' ~ 'f' ^^^ "\f" - |'\\' ~ 'n' ^^^ "\n" - |'\\' ~ 'r' ^^^ "\r" - |'\\' ~ 't' ^^^ "\t" - |'\\' ~> 'u' ~> unicodeBlock) - - val hexDigits = Set[Char]() ++ "0123456789abcdefABCDEF".toArray - def hexDigit = elem("hex digit", hexDigits.contains(_)) - - private def unicodeBlock = hexDigit ~ hexDigit ~ hexDigit ~ hexDigit ^^ { - case a ~ b ~ c ~ d => - new String(Array(Integer.parseInt(List(a, b, c, d) mkString "", 16)), 0, 1) - } - - //private def lift[T](f: String => T)(xs: List[Any]): T = f(xs mkString "") -} diff --git a/shared/src/main/scala/scala/util/parsing/json/Parser.scala b/shared/src/main/scala/scala/util/parsing/json/Parser.scala deleted file mode 100644 index 63965bbe..00000000 --- a/shared/src/main/scala/scala/util/parsing/json/Parser.scala +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala -package util.parsing.json - -import scala.util.parsing.combinator._ -import scala.util.parsing.combinator.syntactical._ - -/** - * A marker class for the JSON result types. - * - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -sealed abstract class JSONType { - /** - * This version of toString allows you to provide your own value - * formatter. - */ - def toString (formatter : JSONFormat.ValueFormatter) : String - - /** - * Returns a String representation of this JSON value - * using the JSONFormat.defaultFormatter. - */ - override def toString = toString(JSONFormat.defaultFormatter) -} - -/** - * This object defines functions that are used when converting JSONType - * values into String representations. Mostly this is concerned with - * proper quoting of strings. - * - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -object JSONFormat { - /** - * This type defines a function that can be used to - * format values into JSON format. - */ - type ValueFormatter = Any => String - - /** - * The default formatter used by the library. You can - * provide your own with the toString calls on - * JSONObject and JSONArray instances. - */ - val defaultFormatter : ValueFormatter = (x : Any) => x match { - case s : String => "\"" + quoteString(s) + "\"" - case jo : JSONObject => jo.toString(defaultFormatter) - case ja : JSONArray => ja.toString(defaultFormatter) - case other => other.toString - } - - /** - * This function can be used to properly quote Strings - * for JSON output. - */ - def quoteString (s : String) : String = - s.map { - case '"' => "\\\"" - case '\\' => "\\\\" - case '/' => "\\/" - case '\b' => "\\b" - case '\f' => "\\f" - case '\n' => "\\n" - case '\r' => "\\r" - case '\t' => "\\t" - /* We'll unicode escape any control characters. These include: - * 0x0 -> 0x1f : ASCII Control (C0 Control Codes) - * 0x7f : ASCII DELETE - * 0x80 -> 0x9f : C1 Control Codes - * - * Per RFC4627, section 2.5, we're not technically required to - * encode the C1 codes, but we do to be safe. - */ - case c if ((c >= '\u0000' && c <= '\u001f') || (c >= '\u007f' && c <= '\u009f')) => "\\u%04x".format(c.toInt) - case c => c - }.mkString -} - -/** - * Represents a JSON Object (map). - * - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -case class JSONObject (obj : Map[String,Any]) extends JSONType { - def toString (formatter : JSONFormat.ValueFormatter) = - "{" + obj.map({ case (k,v) => formatter(k.toString) + " : " + formatter(v) }).mkString(", ") + "}" -} - -/** - * Represents a JSON Array (list). - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -case class JSONArray (list : List[Any]) extends JSONType { - def toString (formatter : JSONFormat.ValueFormatter) = - "[" + list.map(formatter).mkString(", ") + "]" -} - -/** - * The main JSON Parser. - * - * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org"> - */ -@deprecated("Use The Scala Library Index to find alternatives: https://index.scala-lang.org/", "1.0.6") -class Parser extends StdTokenParsers with ImplicitConversions { - // Fill in abstract defs - type Tokens = Lexer - val lexical = new Tokens - - // Configure lexical parsing - lexical.reserved ++= List("true", "false", "null") - lexical.delimiters ++= List("{", "}", "[", "]", ":", ",") - - /** Type signature for functions that can parse numeric literals */ - type NumericParser = String => Any - - // Global default number parsing function - protected var defaultNumberParser : NumericParser = {_.toDouble} - - // Per-thread default number parsing function - protected val numberParser = new ThreadLocal[NumericParser]() { - override def initialValue() = defaultNumberParser - } - - // Define the grammar - def root = jsonObj | jsonArray - def jsonObj = "{" ~> repsep(objEntry, ",") <~ "}" ^^ { case vals : List[_] => JSONObject(Map(vals : _*)) } - def jsonArray = "[" ~> repsep(value, ",") <~ "]" ^^ { case vals : List[_] => JSONArray(vals) } - def objEntry = stringVal ~ (":" ~> value) ^^ { case x ~ y => (x, y) } - def value: Parser[Any] = (jsonObj | jsonArray | number | "true" ^^^ true | "false" ^^^ false | "null" ^^^ null | stringVal) - def stringVal = accept("string", { case lexical.StringLit(n) => n} ) - def number = accept("number", { case lexical.NumericLit(n) => numberParser.get.apply(n)} ) -} - diff --git a/shared/src/main/scala/scala/util/parsing/json/package.scala b/shared/src/main/scala/scala/util/parsing/json/package.scala deleted file mode 100644 index 98cf4a9d..00000000 --- a/shared/src/main/scala/scala/util/parsing/json/package.scala +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Scala (https://www.scala-lang.org) - * - * Copyright EPFL and Lightbend, Inc. - * - * Licensed under Apache License 2.0 - * (http://www.apache.org/licenses/LICENSE-2.0). - * - * See the NOTICE file distributed with this work for - * additional information regarding copyright ownership. - */ - -package scala.util.parsing - -/** - * This package was never intended for production use; it's really more of a code sample demonstrating how to use parser combinators. - * - * Use [[https://index.scala-lang.org/ The Scala Library Index]] to find alternative JSON parsing libraries. - */ -package object json {} \ No newline at end of file diff --git a/shared/src/test/scala/scala/util/parsing/combinator/JsonTest.scala b/shared/src/test/scala/scala/util/parsing/combinator/JsonTest.scala deleted file mode 100644 index 225d5317..00000000 --- a/shared/src/test/scala/scala/util/parsing/combinator/JsonTest.scala +++ /dev/null @@ -1,305 +0,0 @@ -import scala.util.parsing.json._ -import scala.collection.immutable.TreeMap - -import org.junit.Test -import org.junit.Assert.{assertEquals, assertTrue} - -class JsonTest { - /* This method converts parsed JSON back into real JSON notation with objects in - * sorted-key order. Not required by the spec, but it allows us to do a stable - * toString comparison. */ - def jsonToString(in : Any) : String = in match { - case l : List[_] => "[" + l.map(jsonToString).mkString(", ") + "]" - case m : Map[String @unchecked,_] => "{" + m.iterator.toList - .sortWith({ (x,y) => x._1 < y._1 }) - .map({ case (k,v) => "\"" + k + "\": " + jsonToString(v) }) - .mkString(", ") + "}" - case s : String => "\"" + s + "\"" - case x => x.toString - } - - /* - * This method takes input JSON values and sorts keys on objects. - */ - def sortJSON(in : Any) : Any = in match { - case l : List[_] => l.map(sortJSON) - case m : Map[String @unchecked,_] => TreeMap(m.mapValues(sortJSON).iterator.toSeq : _*) - // For the object versions, sort their contents, ugly casts and all... - case JSONObject(data) => JSONObject(sortJSON(data).asInstanceOf[Map[String,Any]]) - case JSONArray(data) => JSONArray(sortJSON(data).asInstanceOf[List[Any]]) - case x => x - } - - // For this one, just parsing should be considered a pass - def printJSON(given : String) : Unit = - assertTrue("Parse failed for \"%s\"".format(given), (JSON parseRaw given).isDefined) - - // For this usage, do a raw parse (to JSONObject/JSONArray) - def printJSON(given : String, expected : JSONType): Unit = { - printJSON(given, JSON.parseRaw, expected) - } - - // For this usage, do a raw parse (to JSONType and subclasses) - def printJSONFull(given : String, expected : Any): Unit = { - printJSON(given, JSON.parseFull, expected) - } - - // For this usage, do configurable parsing so that you can do raw if desired - def printJSON[T](given : String, parser : String => T, expected : Any): Unit = { - parser(given) match { - case None => assertTrue("Parse failed for \"%s\"".format(given), false) - case Some(parsed) => if (parsed != expected) { - val eStr = sortJSON(expected).toString - val pStr = sortJSON(parsed).toString - assertTrue(stringDiff(eStr,pStr), false) - } - } - } - - def stringDiff (expected : String, actual : String): String = { - if (expected != actual) { - // Figure out where the Strings differ and generate a marker - val mismatchPosition = expected.toList.zip(actual.toList).indexWhere({case (x,y) => x != y}) match { - case -1 => Math.min(expected.length, actual.length) - case x => x - } - val reason = (" " * mismatchPosition) + "^" - "Expected: %s\nGot : %s \n %s".format(expected, actual, reason) - - } else { - "Passed compare: " + actual - } - } - - // The library should differentiate between lower case "l" and number "1" (ticket #136) - @Test - def testEllVsOne: Unit = { - printJSON("{\"name\" : \"value\"}", JSONObject(Map("name" -> "value"))) - printJSON("{\"name\" : \"va1ue\"}", JSONObject(Map("name" -> "va1ue"))) - printJSON("{\"name\" : { \"name1\" : \"va1ue1\", \"name2\" : \"va1ue2\" } }", - JSONObject(Map("name" -> JSONObject(Map("name1" -> "va1ue1", "name2" -> "va1ue2"))))) - } - - // Unicode escapes should be handled properly - @Test - def testEscapes: Unit = - printJSON("{\"name\" : \"\\u0022\"}") - - // The library should return a map for JSON objects (ticket #873) - @Test - def testMap: Unit = - printJSONFull("{\"function\" : \"add_symbol\"}", Map("function" -> "add_symbol")) - - // The library should recurse into arrays to find objects (ticket #2207) - @Test - def testObjectsInArrays: Unit = - printJSON("[{\"a\" : \"team\"},{\"b\" : 52}]", JSONArray(List(JSONObject(Map("a" -> "team")), JSONObject(Map("b" -> 52.0))))) - - - // The library should differentiate between empty maps and lists (ticket #3284) - @Test - def testEmptyMapsVsLists: Unit = { - printJSONFull("{}", Map()) - printJSONFull("[]", List()) - } - - // Lists should be returned in the same order as specified - @Test - def testListOrder: Unit = - printJSON("[4,1,3,2,6,5,8,7]", JSONArray(List[Double](4,1,3,2,6,5,8,7))) - - // Additional tests - @Test - def testAdditional: Unit = - printJSON("{\"age\": 0}") - - // The library should do a proper toString representation using default and custom renderers (ticket #3605) - @Test - def testDefaultAndCustomRenderers: Unit = { - assertEquals("{\"name\" : \"va1ue\"}", JSONObject(Map("name" -> "va1ue")).toString()) - assertEquals("{\"name\" : {\"name1\" : \"va1ue1\", \"name2\" : \"va1ue2\"}}", - JSONObject(Map("name" -> JSONObject(TreeMap("name1" -> "va1ue1", "name2" -> "va1ue2")))).toString()) - - val expected = - if (1.0.toString == "1") "[4, 1, 3, 2, 6, 5, 8, 7]" - else "[4.0, 1.0, 3.0, 2.0, 6.0, 5.0, 8.0, 7.0]" - assertEquals(expected, JSONArray(List[Double](4,1,3,2,6,5,8,7)).toString()) - } - - // A test method that escapes all characters in strings - def escapeEverything (in : Any) : String = in match { - case s : String => "\"" + s.map(c => "\\u%04x".format(c : Int)).mkString + "\"" - case jo : JSONObject => jo.toString(escapeEverything _) - case ja : JSONArray => ja.toString(escapeEverything _) - case other => other.toString - } - - @Test - def testEscapeEverything: Unit = - assertEquals("{\"\\u006e\\u0061\\u006d\\u0065\" : \"\\u0076\\u0061\\u006c\"}", JSONObject(Map("name" -> "val")).toString(escapeEverything _)) - - - // from http://en.wikipedia.org/wiki/JSON - val sample1 = """ -{ - "firstName": "John", - "lastName": "Smith", - "address": { - "streetAddress": "21 2nd Street", - "city": "New York", - "state": "NY", - "postalCode": 10021 - }, - "phoneNumbers": [ - "212 732-1234", - "646 123-4567" - ] -}""" - - // Should be equivalent to: - val sample1Obj = Map( - "firstName" -> "John", - "lastName" -> "Smith", - "address" -> Map( - "streetAddress" -> "21 2nd Street", - "city" -> "New York", - "state" -> "NY", - "postalCode" -> 10021 - ), - "phoneNumbers"-> List( - "212 732-1234", - "646 123-4567" - ) - ) - - @Test - def testSample1: Unit = - printJSONFull(sample1, sample1Obj) - - // from http://www.developer.com/lang/jscript/article.php/3596836 - val sample2 = """ -{ - "fullname": "Sean Kelly", - "org": "SK Consulting", - "emailaddrs": [ - {"type": "work", "value": "kelly@seankelly.biz"}, - {"type": "home", "pref": 1, "value": "kelly@seankelly.tv"} - ], - "telephones": [ - {"type": "work", "pref": 1, "value": "+1 214 555 1212"}, - {"type": "fax", "value": "+1 214 555 1213"}, - {"type": "mobile", "value": "+1 214 555 1214"} - ], - "addresses": [ - {"type": "work", "format": "us", - "value": "1234 Main StnSpringfield, TX 78080-1216"}, - {"type": "home", "format": "us", - "value": "5678 Main StnSpringfield, TX 78080-1316"} - ], - "urls": [ - {"type": "work", "value": "http://seankelly.biz/"}, - {"type": "home", "value": "http://seankelly.tv/"} - ] -}""" - - @Test - def testSampl2: Unit = - printJSON(sample2) - - // from http://json.org/example.html - val sample3 = """ -{"web-app": { - "servlet": [ - { - "servlet-name": "cofaxCDS", - "servlet-class": "org.cofax.cds.CDSServlet", - "init-param": { - "configGlossary:installationAt": "Philadelphia, PA", - "configGlossary:adminEmail": "ksm@pobox.com", - "configGlossary:poweredBy": "Cofax", - "configGlossary:poweredByIcon": "/images/cofax.gif", - "configGlossary:staticPath": "/content/static", - "templateProcessorClass": "org.cofax.WysiwygTemplate", - "templateLoaderClass": "org.cofax.FilesTemplateLoader", - "templatePath": "templates", - "templateOverridePath": "", - "defaultListTemplate": "listTemplate.htm", - "defaultFileTemplate": "articleTemplate.htm", - "useJSP": false, - "jspListTemplate": "listTemplate.jsp", - "jspFileTemplate": "articleTemplate.jsp", - "cachePackageTagsTrack": 200, - "cachePackageTagsStore": 200, - "cachePackageTagsRefresh": 60, - "cacheTemplatesTrack": 100, - "cacheTemplatesStore": 50, - "cacheTemplatesRefresh": 15, - "cachePagesTrack": 200, - "cachePagesStore": 100, - "cachePagesRefresh": 10, - "cachePagesDirtyRead": 10, - "searchEngineListTemplate": "forSearchEnginesList.htm", - "searchEngineFileTemplate": "forSearchEngines.htm", - "searchEngineRobotsDb": "WEB-INF/robots.db", - "useDataStore": true, - "dataStoreClass": "org.cofax.SqlDataStore", - "redirectionClass": "org.cofax.SqlRedirection", - "dataStoreName": "cofax", - "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", - "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", - "dataStoreUser": "sa", - "dataStorePassword": "dataStoreTestQuery", - "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", - "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", - "dataStoreInitConns": 10, - "dataStoreMaxConns": 100, - "dataStoreConnUsageLimit": 100, - "dataStoreLogLevel": "debug", - "maxUrlLength": 500}}, - { - "servlet-name": "cofaxEmail", - "servlet-class": "org.cofax.cds.EmailServlet", - "init-param": { - "mailHost": "mail1", - "mailHostOverride": "mail2"}}, - { - "servlet-name": "cofaxAdmin", - "servlet-class": "org.cofax.cds.AdminServlet"}, - - { - "servlet-name": "fileServlet", - "servlet-class": "org.cofax.cds.FileServlet"}, - { - "servlet-name": "cofaxTools", - "servlet-class": "org.cofax.cms.CofaxToolsServlet", - "init-param": { - "templatePath": "toolstemplates/", - "log": 1, - "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", - "logMaxSize": "", - "dataLog": 1, - "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", - "dataLogMaxSize": "", - "removePageCache": "/content/admin/remove?cache=pages&id=", - "removeTemplateCache": "/content/admin/remove?cache=templates&id=", - "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", - "lookInContext": 1, - "adminGroupID": 4, - "betaServer": true}}], - "servlet-mapping": { - "cofaxCDS": "/", - "cofaxEmail": "/cofaxutil/aemail/*", - "cofaxAdmin": "/admin/*", - "fileServlet": "/static/*", - "cofaxTools": "/tools/*"}, - - "taglib": { - "taglib-uri": "cofax.tld", - "taglib-location": "/WEB-INF/tlds/cofax.tld"} - } -}""" - - @Test - def testSample3 = - printJSON(sample3) -} diff --git a/shared/src/test/scala/scala/util/parsing/combinator/UnitTestIO.scala b/shared/src/test/scala/scala/util/parsing/combinator/UnitTestIO.scala deleted file mode 100644 index 10387eb4..00000000 --- a/shared/src/test/scala/scala/util/parsing/combinator/UnitTestIO.scala +++ /dev/null @@ -1,31 +0,0 @@ -import org.junit.Test -import org.junit.Assert.assertEquals - -class UnitTestIO { - - @Test - def testUTF8: Unit = { - def decode(ch: Int) = new String(Array(ch), 0, 1).getBytes("UTF-8") - - assert(new String( decode(0x004D), "utf8") == new String(Array(0x004D.asInstanceOf[Char]))) - assert(new String( decode(0x0430), "utf8") == new String(Array(0x0430.asInstanceOf[Char]))) - assert(new String( decode(0x4E8C), "utf8") == new String(Array(0x4E8C.asInstanceOf[Char]))) - assert(new String(decode(0x10302), "utf8") == new String(Array(0xD800.asInstanceOf[Char], - 0xDF02.asInstanceOf[Char]))) - // a client - val test = "{\"a\":\"\\u0022\"}" - val expected = "a" -> "\"" - - val parsed = scala.util.parsing.json.JSON.parseFull(test) - assertEquals(Some(Map(expected)), parsed) - } - - @Test - def testSource: Unit = { - val s = "Here is a test string" - val f = io.Source.fromBytes(s.getBytes("utf-8")) - val b = new collection.mutable.ArrayBuffer[Char]() - b ++= f - assertEquals(new String(b.toArray), s) - } -}