You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/05/19 13:34:53 UTC
svn commit: r1680254 - in /sis/branches/JDK8/core:
sis-metadata/src/main/java/org/apache/sis/io/wkt/
sis-metadata/src/test/java/org/apache/sis/io/wkt/
sis-referencing/src/test/java/org/apache/sis/referencing/
Author: desruisseaux
Date: Tue May 19 11:34:52 2015
New Revision: 1680254
URL: http://svn.apache.org/r1680254
Log:
Referencing: added more test for WKT element.
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectFactoryTest.java
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java?rev=1680254&r1=1680253&r2=1680254&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8] Tue May 19 11:34:52 2015
@@ -127,15 +127,12 @@ final class Element {
* will require the matching closing bracket at the end of this method. For example if the opening
* bracket was '[', then we will require that the closing bracket is ']' and not ')'.
*/
- if (lower >= length) {
- position.setErrorIndex(lower);
- list = null;
- return;
- }
- final int openingBracket = text.codePointAt(lower);
- final int closingBracket = parser.symbols.matchingBracket(openingBracket);
- if (closingBracket < 0) {
- position.setErrorIndex(lower);
+ final int openingBracket;
+ final int closingBracket;
+ if (lower >= length || (closingBracket = parser.symbols.matchingBracket(
+ openingBracket = text.codePointAt(lower))) < 0)
+ {
+ position.setIndex(lower);
list = null;
return;
}
@@ -151,14 +148,9 @@ final class Element {
*/
list = new LinkedList<>();
final String separator = parser.symbols.trimmedSeparator();
- do {
- if (lower >= length) {
- position.setIndex(offset);
- position.setErrorIndex(lower);
- throw missingCharacter(parser, closingBracket, length);
- }
- final int c = text.codePointAt(lower);
- final int closingQuote = parser.symbols.matchingQuote(c);
+ while (lower < length) {
+ final int firstChar = text.codePointAt(lower);
+ final int closingQuote = parser.symbols.matchingQuote(firstChar);
if (closingQuote >= 0) {
/*
* Try to parse the next element as a quoted string. We will take it as a string if the first non-blank
@@ -166,10 +158,10 @@ final class Element {
* parsed text.
*/
final int n = Character.charCount(closingQuote);
- lower += Character.charCount(c);
+ lower += Character.charCount(firstChar) - n; // This will usually let 'lower' unchanged.
CharSequence content = null;
do {
- final int upper = text.indexOf(closingQuote, lower);
+ final int upper = text.indexOf(closingQuote, lower += n);
if (upper < lower) {
position.setIndex(offset);
position.setErrorIndex(lower);
@@ -191,7 +183,7 @@ final class Element {
lower = upper + n; // After the closing quote.
} while (lower < text.length() && text.codePointAt(lower) == closingQuote);
list.add(content.toString());
- } else if (!Character.isUnicodeIdentifierStart(c)) {
+ } else if (!Character.isUnicodeIdentifierStart(firstChar)) {
/*
* Try to parse the next element as a date or a number. We will attempt such parsing
* if the first non-blank character is not the beginning of an unicode identifier.
@@ -223,21 +215,28 @@ final class Element {
list.add(new Element(parser, text, position));
lower = position.getIndex();
}
+ /*
+ * At this point we finished to parse the component. If we find a separator (usually a coma),
+ * search for another element. Otherwise verify that the closing bracket is present.
+ */
lower = skipLeadingWhitespaces(text, lower, length);
- } while (text.regionMatches(lower, separator, 0, separator.length()));
- /*
- * Verify that the closing bracket is present.
- */
- if (lower < length) {
- final int c = text.codePointAt(lower);
- if (c == closingBracket) {
- position.setIndex(lower + Character.charCount(c));
- return;
+ if (text.regionMatches(lower, separator, 0, separator.length())) {
+ lower = skipLeadingWhitespaces(text, lower + separator.length(), length);
+ } else {
+ if (lower >= length) break;
+ final int c = text.codePointAt(lower);
+ if (c == closingBracket) {
+ position.setIndex(lower + Character.charCount(c));
+ return;
+ }
+ position.setIndex(offset);
+ position.setErrorIndex(lower);
+ throw unparsableString(parser, text, position);
}
}
position.setIndex(offset);
position.setErrorIndex(lower);
- throw unparsableString(parser, text, position);
+ throw missingCharacter(parser, closingBracket, lower);
}
Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java?rev=1680254&r1=1680253&r2=1680254&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/ElementTest.java [UTF-8] Tue May 19 11:34:52 2015
@@ -19,6 +19,8 @@ package org.apache.sis.io.wkt;
import java.util.Locale;
import java.text.ParsePosition;
import java.text.ParseException;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -35,29 +37,92 @@ import static org.junit.Assert.*;
*/
public final strictfp class ElementTest extends TestCase {
/**
- * Tests a {@link Element#pullString(String)}.
+ * A dummy parser to be given to the {@link Element} constructor.
+ */
+ private final Parser parser = new Parser(Symbols.SQUARE_BRACKETS, Locale.ENGLISH) {
+ @Override Object parse(Element element) throws ParseException {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ /**
+ * Parses the given text and ensures that {@link ParsePosition} index is set at to the end of string.
+ */
+ private Element parse(final String text) throws ParseException {
+ final ParsePosition position = new ParsePosition(0);
+ final Element element = new Element(parser, text, position);
+ assertEquals("errorIndex", -1, position.getErrorIndex());
+ assertEquals("index", CharSequences.skipTrailingWhitespaces(text, 0, text.length()), position.getIndex());
+ return element;
+ }
+
+ /**
+ * Tests {@link Element#pullString(String)}.
*
* @throws ParseException if an error occurred during the parsing.
*/
@Test
- public void testString() throws ParseException {
- final ParsePosition position = new ParsePosition(0);
- final Element element = new Element(new ParserMock(), "Datum[\"World Geodetic System 1984\"]", position);
- assertEquals("Datum", element.keyword);
- assertEquals("World Geodetic System 1984", element.pullString("name"));
+ public void testPullString() throws ParseException {
+ Element element = parse("Datum[\"World Geodetic System 1984\"]");
+ assertEquals("keyword", "Datum", element.keyword);
+ assertEquals("value", "World Geodetic System 1984", element.pullString("value"));
+ element.close();
+
+ // Spaces inside quotes should be preserved.
+ element = parse(" Datum [ \" World Geodetic System 1984 \" ] ");
+ assertEquals("keyword", "Datum", element.keyword);
+ assertEquals("value", " World Geodetic System 1984 ", element.pullString("value"));
+ element.close();
+
+ // Consecutive values.
+ element = parse("A[\"B\", \"C\"]");
+ assertEquals("keyword", "A", element.keyword);
+ assertEquals("first", "B", element.pullString("first"));
+ assertEquals("second", "C", element.pullString("second"));
+ element.close();
}
/**
- * A dummy parser for testing purpose.
+ * Tests {@link Element#pullString(String)} with enclosed quotes.
+ * Also opportunistically tests different kinds of quotes.
+ *
+ * @throws ParseException if an error occurred during the parsing.
*/
- private static final class ParserMock extends Parser {
- ParserMock() {
- super(Symbols.SQUARE_BRACKETS, Locale.ENGLISH);
- }
+ @Test
+ @DependsOnMethod("testPullString")
+ public void testEnclosedQuotes() throws ParseException {
+ Element element = parse("A[“text.”]");
+ assertEquals("keyword", "A", element.keyword);
+ assertEquals("value", "text.", element.pullString("value"));
+ element.close();
- @Override
- Object parse(Element element) throws ParseException {
- throw new UnsupportedOperationException();
- }
+ // No need to double the enclosed quotes here.
+ element = parse("A[“text with \"quotes\".”]");
+ assertEquals("keyword", "A", element.keyword);
+ assertEquals("value", "text with \"quotes\".", element.pullString("value"));
+ element.close();
+
+ // Those enclosed quotes need to be doubled.
+ element = parse("A[\"text with \"\"double quotes\"\".\"]");
+ assertEquals("keyword", "A", element.keyword);
+ assertEquals("value", "text with \"double quotes\".", element.pullString("value"));
+ element.close();
+ }
+
+ /**
+ * Tests {@link Element#pullDouble(String)} for many consecutive values,
+ * including usage of exponential notation.
+ *
+ * @throws ParseException if an error occurred during the parsing.
+ */
+ @Test
+ public void testPullDouble() throws ParseException {
+ Element element = parse("B[3.1, 4.2, 5.3E3, 6.4e3]");
+ assertEquals("B", element.keyword);
+ assertEquals("first", 3.1, element.pullDouble("first"), STRICT);
+ assertEquals("second", 4.2, element.pullDouble("second"), STRICT);
+ assertEquals("third", 5300, element.pullDouble("third"), STRICT);
+ assertEquals("forth", 6400, element.pullDouble("forth"), STRICT);
+ element.close();
}
}
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectFactoryTest.java?rev=1680254&r1=1680253&r2=1680254&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectFactoryTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectFactoryTest.java [UTF-8] Tue May 19 11:34:52 2015
@@ -56,10 +56,12 @@ public final strictfp class GeodeticObje
}
@Override
- @Ignore("This tests need the Transverse Mercator projection, which is not yet implemented in SIS.")
+ @Deprecated
+ @Ignore("Replaced by testProjectedWithGeoidalHeight()")
public void testProjected3D() throws FactoryException {
}
+ @Override
@Ignore("This tests need the Transverse Mercator projection, which is not yet implemented in SIS.")
public void testProjectedWithGeoidalHeight() throws FactoryException {
}