This is an automated email from the ASF dual-hosted git repository.

mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new c9302a0  Fix poor diagnostic. Fix spurious attributeFormDefault.
c9302a0 is described below

commit c9302a03964ef36581ca9217ca3bacd87ba8ea3e
Author: Michael Beckerle <[email protected]>
AuthorDate: Fri Mar 8 15:32:28 2019 -0500

    Fix poor diagnostic. Fix spurious attributeFormDefault.
    
    Fix tests with too-specific diagnostic error checking.
    
    DAFFODIL-2092, DAFFODIL-2084
---
 .../org/apache/daffodil/example/TestJavaAPI.java   |  2 +-
 .../org/apache/daffodil/cookers/Cookers.scala      |  6 +--
 .../apache/daffodil/cookers/EntityReplacer.scala   | 25 ++++-----
 .../org/apache/daffodil/util/SchemaUtils.scala     | 11 ++--
 .../delimiter_properties/DelimiterProperties.tdml  |  4 +-
 .../section23/dfdl_expressions/expressions.tdml    |  6 ++-
 .../runtime_properties/dynamicSeparator.tdml       | 63 ++++++++++++++++++++++
 .../runtime_properties/TestDynamicSeparator.scala  | 39 ++++++++++++++
 8 files changed, 126 insertions(+), 30 deletions(-)

diff --git 
a/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java 
b/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
index f28a815..0fc8e8b 100644
--- a/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
+++ b/daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java
@@ -98,7 +98,7 @@ public class TestJavaAPI {
              * For more information, see https://github.com/sbt/sbt/issues/163
              */
             @Override
-            protected Class resolveClass(java.io.ObjectStreamClass desc) 
throws IOException, ClassNotFoundException {
+            protected Class<?> resolveClass(java.io.ObjectStreamClass desc) 
throws IOException, ClassNotFoundException {
                 try {
                     return Class.forName(desc.getName(), false, 
getClass().getClassLoader());
                 } catch (ClassNotFoundException e) {
diff --git 
a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/Cookers.scala 
b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/Cookers.scala
index ad3dfdc..4d64933 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/Cookers.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/Cookers.scala
@@ -55,13 +55,13 @@ object ExtraEscapedCharactersCooker extends 
ListOfSingleCharacterLiteralNoCharCl
 
 object FillByteCooker extends 
SingleCharacterLiteralNoCharClassEntitiesWithByteEntities()
 
-object InitiatorCooker extends DelimiterCooker()
+object InitiatorCooker extends DelimiterCooker("initiator")
 
-object TerminatorCooker extends DelimiterCooker()
+object TerminatorCooker extends DelimiterCooker("terminator")
 
 object TerminatorCookerNoES extends DelimiterCookerNoES("terminator")
 
-object SeparatorCooker extends DelimiterCookerNoES(null)
+object SeparatorCooker extends DelimiterCookerNoES("separator")
 
 object TextStandardDecimalSeparatorCooker extends 
ListOfSingleCharacterLiteralNoCharClassEntitiesNoByteEntities()
 
diff --git 
a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala 
b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
index cabb318..13e492a 100644
--- 
a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
+++ 
b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
@@ -47,8 +47,7 @@ final class EntityReplacer {
   val dfdlCharClassEntityName = "NL|WSP|WSP\\*|WSP\\+|ES"
 
   val entityCharacterUnicode: List[(String, String, Matcher)] =
-    List(
-      ("NUL", "\u0000", Pattern.compile("%" + "NUL" + ";", 
Pattern.MULTILINE).matcher("")),
+    List(("NUL", "\u0000", Pattern.compile("%" + "NUL" + ";", 
Pattern.MULTILINE).matcher("")),
       ("SOH", "\u0001", Pattern.compile("%" + "SOH" + ";", 
Pattern.MULTILINE).matcher("")),
       ("STX", "\u0002", Pattern.compile("%" + "STX" + ";", 
Pattern.MULTILINE).matcher("")),
       ("ETX", "\u0003", Pattern.compile("%" + "ETX" + ";", 
Pattern.MULTILINE).matcher("")),
@@ -87,8 +86,7 @@ final class EntityReplacer {
       ("LS", "\u2028", Pattern.compile("%" + "LS" + ";", 
Pattern.MULTILINE).matcher("")))
 
   val charClassReplacements: List[(String, String, Matcher)] =
-    List(
-      ("WSP", "\u0020", Pattern.compile("%" + "WSP" + ";", 
Pattern.MULTILINE).matcher("")),
+    List(("WSP", "\u0020", Pattern.compile("%" + "WSP" + ";", 
Pattern.MULTILINE).matcher("")),
       ("WSP*", "", Pattern.compile("%" + "WSP\\*" + ";", 
Pattern.MULTILINE).matcher("")),
       ("WSP+", "\u0020", Pattern.compile("%" + "WSP\\+" + ";", 
Pattern.MULTILINE).matcher("")),
       ("ES", "", Pattern.compile("%" + "ES" + ";", 
Pattern.MULTILINE).matcher("")))
@@ -490,8 +488,7 @@ abstract class UpperCaseToken(propNameArg: String = null)
  *
  *  This is the kind of string literal you can use within an expression.
  */
-sealed abstract class StringLiteralBase(
-  propNameArg: String,
+sealed abstract class StringLiteralBase(propNameArg: String,
   protected val allowByteEntities: Boolean)
   extends AutoPropNameBase(propNameArg)
   with StringLiteralCookerMixin {
@@ -642,8 +639,7 @@ sealed abstract class AutoPropNameBase(propNameArg: String) 
extends Serializable
     if (propNameArg eq null) autoPropName else propNameArg
 }
 
-sealed abstract class ListOfStringLiteralBase(
-  propNameArg: String,
+sealed abstract class ListOfStringLiteralBase(propNameArg: String,
   protected val allowByteEntities: Boolean)
   extends AutoPropNameBase(propNameArg)
   with ListStringLiteralCookerMixin {
@@ -652,7 +648,11 @@ sealed abstract class ListOfStringLiteralBase(
 
   protected def cook(raw: String, context: ThrowsSDE, forUnparse: Boolean): 
List[String] = {
     if (raw.length != 0 && (raw.head.isWhitespace || raw.last.isWhitespace)) {
-      context.SDE("The property '%s' cannot start or end with the string \" 
\", did you mean to use '%%SP;' instead?", propNameArg)
+      val ws = if (raw.head.isWhitespace) raw.head else raw.last
+      val wsVisible = Misc.remapCodepointToVisibleGlyph(ws.toChar).toChar
+      val hexCodePoint = "%04x".format(ws.toInt)
+      context.SDE("The property '%s' cannot start or end with the string 
\"%s\"(Unicode hex code point U+%s), or consist entirely of whitespace."
+        + "\nDid you mean to use character entities like '%%SP;' or '%%NL;' to 
indicate whitespace in the data format instead?", propNameArg, wsVisible, 
hexCodePoint)
     }
 
     val rawList = raw.split("\\s+").toList
@@ -815,7 +815,7 @@ class DelimiterCookerNoES(pn: String) extends 
ListOfString1OrMoreLiteral(pn, tru
     }
 }
 
-class DelimiterCooker(pn: String = null) extends ListOfStringLiteralBase(pn, 
true) {
+class DelimiterCooker(pn: String) extends ListOfStringLiteralBase(pn, true) {
   private val constantCooker = new ListOfStringLiteral(propName, true) // zero 
length allowed
   private val runtimeCooker = new ListOfString1OrMoreLiteral(propName, true)
 
@@ -831,8 +831,3 @@ class DelimiterCooker(pn: String = null) extends 
ListOfStringLiteralBase(pn, tru
   override protected def oneLiteralCooker: StringLiteralBase = 
Assert.usageError("not to be used.")
   override protected def cook(raw: String, context: ThrowsSDE, forUnparse: 
Boolean): List[String] = Assert.usageError("not to be used")
 }
-
-/**
- * For generic cases where the code is handling many kinds of delimiters
- */
-object DelimiterCooker extends DelimiterCooker(null) // TODO: Deprecate and 
fix places using this.
diff --git 
a/daffodil-lib/src/main/scala/org/apache/daffodil/util/SchemaUtils.scala 
b/daffodil-lib/src/main/scala/org/apache/daffodil/util/SchemaUtils.scala
index fd02c5e..cd9ef17 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/util/SchemaUtils.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/util/SchemaUtils.scala
@@ -40,15 +40,13 @@ object SchemaUtils {
    * Constructs a DFDL schema more conveniently than having to specify all 
those xmlns attributes.
    */
 
-  def dfdlTestSchemaUnqualified(
-    includeImports: Seq[Node],
+  def dfdlTestSchemaUnqualified(includeImports: Seq[Node],
     topLevelAnnotations: Seq[Node],
     contentElements: Seq[Node],
     fileName: String = ""): Elem =
     dfdlTestSchema(includeImports, topLevelAnnotations, contentElements, 
fileName = fileName, elementFormDefault = "unqualified")
 
-  def dfdlTestSchemaWithTarget(
-    includeImports: Seq[Node],
+  def dfdlTestSchemaWithTarget(includeImports: Seq[Node],
     topLevelAnnotations: Seq[Node],
     contentElements: Seq[Node],
     theTargetNS: String,
@@ -70,8 +68,7 @@ object SchemaUtils {
    * as those were aggravating a xerces bug that we might as well avoid.
    * This also makes these much more readable.
    */
-  def dfdlTestSchema(
-    includeImports: Seq[Node],
+  def dfdlTestSchema(includeImports: Seq[Node],
     topLevelAnnotations: Seq[Node],
     contentElements: Seq[Node],
     schemaScope: NamespaceBinding = TopScope, // from the defineSchema node
@@ -97,7 +94,7 @@ object SchemaUtils {
     scope = XMLUtils.combineScopes("ex", targetNamespace, scope)
 
     val schemaNode =
-      <xs:schema elementFormDefault={ elementFormDefault } 
attributeFormDefault="unqualified">
+      <xs:schema elementFormDefault={ elementFormDefault }>
         {
           includeImports
         }
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
index ea4eb93..b5cf2ac 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
@@ -397,7 +397,7 @@
     <tdml:errors>
       <tdml:error>Schema Definition Error</tdml:error>
       <tdml:error>cannot start or end</tdml:error>
-      <tdml:error>use '%SP;' instead</tdml:error>
+      <tdml:error>'%SP;'</tdml:error>
     </tdml:errors>
   </tdml:parserTestCase>
 
@@ -412,7 +412,7 @@
     <tdml:errors>
       <tdml:error>Schema Definition Error</tdml:error>
       <tdml:error>cannot start or end</tdml:error>
-      <tdml:error>use '%SP;' instead</tdml:error>
+      <tdml:error>'%SP;'</tdml:error>
     </tdml:errors>
   </tdml:parserTestCase>
 
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
index 92db02f..8414ce4 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
@@ -1678,7 +1678,8 @@
     <tdml:errors>
       <tdml:error>Schema Definition Error</tdml:error>
       <tdml:error>property 'initiator'</tdml:error>
-      <tdml:error>cannot start or end with the string " "</tdml:error>
+      <tdml:error>cannot start or end with the string</tdml:error>
+      <tdml:error>U+0020</tdml:error>
     </tdml:errors>
   </tdml:parserTestCase>
 
@@ -1723,7 +1724,8 @@
     <tdml:errors>
       <tdml:error>Schema Definition Error</tdml:error>
       <tdml:error>property 'initiator'</tdml:error>
-      <tdml:error>cannot start or end with the string " "</tdml:error>
+      <tdml:error>cannot start or end with the string</tdml:error>
+      <tdml:error>U+0020</tdml:error>
     </tdml:errors>
   </tdml:parserTestCase>
 
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section23/runtime_properties/dynamicSeparator.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/runtime_properties/dynamicSeparator.tdml
new file mode 100644
index 0000000..70f9e58
--- /dev/null
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section23/runtime_properties/dynamicSeparator.tdml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<tdml:testSuite 
+  xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"; 
+  xmlns:xs="http://www.w3.org/2001/XMLSchema";
+  xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"; 
+  xmlns:tns="http://example.com"; 
+  xmlns:ex="http://example.com";
+  xmlns:fn="http://www.w3.org/2005/xpath-functions";
+  defaultRoundTrip="onePass">
+
+  <tdml:defineSchema name="s" elementFormDefault="unqualified">
+
+    <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
+
+    <dfdl:format ref="ex:GeneralFormat" 
+      representation="text"
+      lengthKind="delimited" 
+      encoding="ASCII"  />
+
+  <xs:element name="r">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="sep" type="xs:string" dfdl:lengthKind="explicit"
+          dfdl:length="1" dfdl:lengthUnits="characters" />
+        <xs:sequence dfdl:separator='{./sep}'>
+          <xs:element name="a" type="xs:string" />
+          <xs:element name="b" type="xs:string" />
+        </xs:sequence>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+
+  </tdml:defineSchema>
+  
+  <tdml:parserTestCase name="dynSepAllWhitespace" root="r" model="s"
+    description="Shows that when separator is all whitespace characters, that 
we get a good diagnostic">
+    <tdml:document>
+      <tdml:documentPart type="byte">0a</tdml:documentPart>
+    </tdml:document>
+    <tdml:errors>
+      <tdml:error>Schema Definition Error</tdml:error><!-- at runtime -->
+      <tdml:error>The property 'separator'</tdml:error>
+      <tdml:error>U+000a</tdml:error>
+    </tdml:errors>
+  </tdml:parserTestCase>
+
+</tdml:testSuite>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section23/runtime_properties/TestDynamicSeparator.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section23/runtime_properties/TestDynamicSeparator.scala
new file mode 100644
index 0000000..68adbd4
--- /dev/null
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section23/runtime_properties/TestDynamicSeparator.scala
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.section23.runtime_properties
+
+import org.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+
+object TestDynamicSeparator {
+
+  val testDir = "org/apache/daffodil/section23/runtime_properties/"
+  val runner = Runner(testDir, "dynamicSeparator.tdml")
+
+  @AfterClass def shutdown = {
+    runner.reset
+  }
+}
+
+class TestDynamicSeparator {
+  import TestDynamicSeparator._
+
+  // DAFFODIL-2092
+  @Test def test_dynSepAllWhitespace() { 
runner.runOneTest("dynSepAllWhitespace") }
+}

Reply via email to