You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/11/24 22:09:22 UTC

jena git commit: Tests for JENA-1076. Improve comments.

Repository: jena
Updated Branches:
  refs/heads/master 21c61b48f -> 90c04b1ac


Tests for JENA-1076.  Improve comments.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/90c04b1a
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/90c04b1a
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/90c04b1a

Branch: refs/heads/master
Commit: 90c04b1acb21c970d99b6c6a66e1512591de7ed1
Parents: 21c61b4
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Nov 24 21:09:03 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Nov 24 21:09:03 2015 +0000

----------------------------------------------------------------------
 .../java/org/apache/jena/util/SplitIRI.java     | 69 ++++++++++----------
 .../org/apache/jena/util/TestSplitIRI_TTL.java  | 54 ++++++++-------
 2 files changed, 64 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/90c04b1a/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java b/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
index e179855..8987c7f 100644
--- a/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
+++ b/jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
@@ -116,36 +116,27 @@ public class SplitIRI
         return isPN_LOCAL_ESC(ch) ; 
     }
     
-    public static boolean /*RiotChars.*/isPN_LOCAL_ESC(char ch) {
-        switch (ch) {
-            case '\\': case '_':  case '~': case '.': case '-': case '!': case '$':
-            case '&':  case '\'': case '(': case ')': case '*': case '+': case ',':
-            case ';':  case '=':  case '/': case '?': case '#': case '@': case '%':
-                return true ;
-            default:
-                return false ;
-        }
-    }
     
-    /* From the RDf 1.1 Turtle specification:
-[136s]  PrefixedName    ::=     PNAME_LN | PNAME_NS
-Productions for terminals
-
-
-[163s]  PN_CHARS_BASE   ::=     [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
-[164s]  PN_CHARS_U  ::=     PN_CHARS_BASE | '_'
-[166s]  PN_CHARS    ::=     PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
-[167s]  PN_PREFIX   ::=     PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)?
-
-[168s]  PN_LOCAL    ::=     (PN_CHARS_U | ':' | [0-9] | PLX) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX))?
-[169s]  PLX     ::=     PERCENT | PN_LOCAL_ESC
-[170s]  PERCENT     ::=     '%' HEX HEX
-[171s]  HEX     ::=     [0-9] | [A-F] | [a-f]
-[172s]  PN_LOCAL_ESC    ::=     '\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
+    // @formatter:off
+    /* From the RDF 1.1 Turtle specification:
+        [136s]  PrefixedName    ::=     PNAME_LN | PNAME_NS
+        Productions for terminals
+        
+        [163s]  PN_CHARS_BASE   ::=     [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
+        [164s]  PN_CHARS_U  ::=     PN_CHARS_BASE | '_'
+        [166s]  PN_CHARS    ::=     PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
+        [167s]  PN_PREFIX   ::=     PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)?
+        
+        [168s]  PN_LOCAL    ::=     (PN_CHARS_U | ':' | [0-9] | PLX) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX))?
+        [169s]  PLX     ::=     PERCENT | PN_LOCAL_ESC
+        [170s]  PERCENT     ::=     '%' HEX HEX
+        [171s]  HEX     ::=     [0-9] | [A-F] | [a-f]
+        [172s]  PN_LOCAL_ESC    ::=     '\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
 */
+    // @formatter:on
 
     /** Find the URI split point, return the index into the string that is the
-     * first character of a legal Turtle local name.   
+     *  first character of a legal Turtle local name.   
      * <p>
      * This is a pragmatic choice, not just finding the maximal point.
      * For example, with escaping '/' can be included but that means 
@@ -163,17 +154,13 @@ Productions for terminals
         // Fast track.  Still need to check validity of the prefix part.
         int idx1 = uri.lastIndexOf('#') ;
         // Not so simple - \/ in local names 
-        int idx2 = 
-            isURN ? uri.lastIndexOf(':') : uri.lastIndexOf('/') ;
+        int idx2 = isURN ? uri.lastIndexOf(':') : uri.lastIndexOf('/') ;
 
         // If absolute.
         int idx3 = uri.indexOf(':') ; 
     
-        // Special case.
-        // A final "." makes it illegal Turtle. 
-        if ( uri.endsWith(".") ) {
-            
-        }
+        // Note: local names can't end in "." in Turtle.
+        // This is handled by escape_PN_LOCAL_ESC which will escape it as "\."
         
         // Test the discovered local part.
         // Limit is exclusive.
@@ -233,7 +220,10 @@ Productions for terminals
         }
      
      */
-    /** Split point, according to XML rules. */
+    /** Split point, according to XML qname rules.
+     * This is the longest NCName at the end of the uri.
+     * See {@link Util#splitNamespaceXML}.
+     */
     public static int splitXML(String string) { return Util.splitNamespaceXML(string) ; }
 
     /** Namespace, according to XML qname rules.
@@ -253,6 +243,17 @@ Productions for terminals
     // Extracted from RiotChars
     // When/if RIOT becomes accessible to this code, then refactor 
     
+    private static boolean /*RiotChars.*/isPN_LOCAL_ESC(char ch) {
+        switch (ch) {
+            case '\\': case '_':  case '~': case '.': case '-': case '!': case '$':
+            case '&':  case '\'': case '(': case ')': case '*': case '+': case ',':
+            case ';':  case '=':  case '/': case '?': case '#': case '@': case '%':
+                return true ;
+            default:
+                return false ;
+        }
+    }
+
     /** ASCII 0-9 */
     private static boolean isDigit(int ch) {
         return range(ch, '0', '9') ;

http://git-wip-us.apache.org/repos/asf/jena/blob/90c04b1a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
index a698e6e..d3d5a7e 100644
--- a/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
+++ b/jena-core/src/test/java/org/apache/jena/util/TestSplitIRI_TTL.java
@@ -52,7 +52,6 @@ public class TestSplitIRI_TTL {
     
     // Bizarre but legal URIs
     @Test public void split_weird_1() { testPrefixLocalname("abc:def",       "abc:", "def" ) ; }
-    
 
     // Turtle details.
     // "." leading dot is not legal.
@@ -71,18 +70,16 @@ public class TestSplitIRI_TTL {
     
     // Turtle details, including escaping.
     // Test for PrefixLocalnameEsc
-    @Test public void split_ttl_esc_01() { testPrefixLocalnameEsc("http://example/id=89",  "id\\=89"   ) ; }
-    @Test public void split_ttl_esc_02() { testPrefixLocalnameEsc("http://example/a,b",  "a\\,b"   ) ; }
+    @Test public void split_ttl_esc_01() { testPrefixLocalnameEsc("http://example/id=89",  "http://example/", "id\\=89"   ) ; }
+    @Test public void split_ttl_esc_02() { testPrefixLocalnameEsc("http://example/a,b",  "http://example/", "a\\,b"   ) ; }
     // Trailing '.'
-    @Test public void split_ttl_esc_033() { testPrefixLocalnameEsc("http://example/2.3.", "2.3\\."     ) ; }
+    @Test public void split_ttl_esc_03() { testPrefixLocalnameEsc("http://example/2.3.", "http://example/", "2.3\\."     ) ; }
     
     // URNs split differently.
     @Test public void split_urn_01() { testPrefixLocalname("urn:foo:bar",                   "urn:foo:",              "bar"       ) ; }
 
     // Anti-tests
     @Test public void split_51() { testPrefixLocalnameNot("http://example/foo#bar:baz", "http://example/foo#bar", "baz"     ) ; }
-
-    
     
     private void testSplit(String string, int expected) {
         int i = splitpoint(string) ;
@@ -114,36 +111,43 @@ public class TestSplitIRI_TTL {
         String msg = string ;
         if ( i != -1 ) {
             // Better error message.
-            String ns = namespace(string) ;
-            String ln = localname(string) ;
+            String ns = namespaceTTL(string) ;
+            String ln = localnameTTL(string) ;
             msg = "Unexpected split of '"+string+"' into ("+ns+", "+ln+") [index="+i+"]" ;
         }
         Assert.assertEquals(msg, -1, i) ;
     }
     
-    private void testPrefixLocalname(String string, String expectedPrefix, String expectedLocalname) {
-        String ns = namespace(string) ;
-        String ln = localname(string) ;
-
-        if ( expectedPrefix != null )
-            Assert.assertEquals(expectedPrefix, ns);
-        if ( expectedLocalname != null )
-            Assert.assertEquals(expectedLocalname, ln);
-        if (  expectedPrefix != null && expectedLocalname != null ) {
-            String x = ns+ln ;
+    // Don't worry about local name escaping.
+    private void testPrefixLocalname(String string, String expectedNamespace, String expectedLocalname) {
+        String actualNamespace = namespace(string) ;
+        String actualLocalName = localname(string) ;
+        checkPrefixLocalname(string,
+                             expectedNamespace, actualNamespace,
+                             expectedLocalname, actualLocalName) ;
+        if ( expectedNamespace != null && expectedLocalname != null ) {
+            String x = actualNamespace+actualLocalName ;
             Assert.assertEquals(string, x) ;
         }
     }
 
-    private void testPrefixLocalnameEsc(String string, String expectedLocalname) {
-      String ln = localnameTTL(string) ;
-      Assert.assertEquals(expectedLocalname, ln);
-  }
+    // Do worry about local name escaping.
+    private void testPrefixLocalnameEsc(String string, String expectedNamespace, String expectedLocalname) {
+        checkPrefixLocalname(string,
+                             expectedNamespace, namespaceTTL(string),
+                             expectedLocalname, localnameTTL(string)) ;
+    }
+    
+    private void checkPrefixLocalname(String string,
+                                      String expectedNamespace, String actualNamespace, 
+                                      String expectedLocalname, String actualLocalName) {
+        if ( expectedNamespace != null )
+            Assert.assertEquals(expectedNamespace, actualNamespace);
+        if ( expectedLocalname != null )
+            Assert.assertEquals(expectedLocalname, actualLocalName);
+    }
 
     private void testPrefixLocalnameNot(String string, String expectedPrefix, String expectedLocalname) {
-//      Node n = NodeFactory.createURI(string) ;
-//      String ns = n.getNameSpace() ;
-//      String ln = n.getLocalName() ;
         String ns = namespace(string) ;
         String ln = localname(string) ;