stevedlawrence commented on code in PR #799:
URL: https://github.com/apache/daffodil/pull/799#discussion_r896867627


##########
daffodil-tdml-lib/src/test/scala/org/apache/daffodil/tdml/UnitTestTDMLRunner.scala:
##########
@@ -490,4 +490,355 @@ class UnitTestTDMLRunner {
     assertTrue(dataElem ne null)
     runner.reset
   }
-}
+
+  @Test def testCommentBit(): Unit = {
+    val xml = <document bitOrder="LSBFirst"><documentPart type="bits">00000010 
//this is a label111</documentPart></document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("00000010", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitWithNewLine(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">01 01 11 //flagByte1
+                                        1 //bool2</documentPart>
+              </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("0101111", firstPart.bitDigits)
+  }
+
+    @Test def testCommentBitJustComments(): Unit = {
+      val xml = <document bitOrder="LSBFirst">
+                  <documentPart type="bits">
+                  // this doc part contains no bits
+                  // at all. It is just comments.
+                  // 101010101
+                  </documentPart>
+                </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitNoLineEnding(): Unit = {
+    val xml = <document bitOrder="LSBFirst"><documentPart type="bits">01011010 
// just a comment here no line ending </documentPart>
+              </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("01011010", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitBothCommentFormatsNewLine(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0100110110 /*C0mment 01011111 _01*/11
+100111//D1fferent sty1e c0mment</documentPart>
+              </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("010011011011100111", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitBothCommentFormats(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0100110110 /*C0mment 01011111 
_01*/100111//D1fferent sty1e c0mment</documentPart>
+              </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("0100110110100111", firstPart.bitDigits)
+  }
+
+  @Test def testBitBadCommentFormatException(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0100110110 C0mment 01011111 
_01100*/111//D1fferent sty1e c0mment</documentPart>
+              </document>
+    val exc = intercept[TDMLException] {
+      val doc = new Document(xml, null)
+      doc.documentParts.collect { case x: BitsDocumentPart => x }
+      val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+      val firstPart = dp(0).bitDigits
+    }
+    assertTrue(exc.getMessage().contains("Improper formatting of /* */ style 
comment"))
+  }
+
+  @Test def testCommentBitNoWarningCharacters(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">01|01|00
+                                        (10).[01]</documentPart></document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("0101001001", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitNoWarningCharactersWithInvalid(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">01|01|00 !!
+                                        (10).[01]</documentPart></document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("0101001001", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitNonGreedy(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0101 /*Data 1*/ 0101 /*Data 
2*/</documentPart></document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("01010101", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitNonGreedyNewLine(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0101 /*Data 1
+                                              Explanation*/
+                                        0101 /*Data 2
+                                              Explanation*/
+              </documentPart>
+              </document>
+    val doc = new Document(xml, null)
+    val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+    val firstPart = dp(0)
+    assertEquals("01010101", firstPart.bitDigits)
+  }
+
+  @Test def testCommentBitCarriageReturn(): Unit = {
+    val xml = <document bitOrder="LSBFirst">
+              <documentPart type="bits">0101 /*Data
+                                             Explanation*/
+                                        0101 /*Data 2&#13;Explanation*/
+              </documentPart>
+              </document>
+    val exc = intercept[Exception] {
+      val doc = new Document(xml, null)
+      doc.documentParts.collect { case x: BitsDocumentPart => x }
+      val dp = doc.documentParts.collect { case x: BitsDocumentPart => x }
+      val firstPart = dp(0).bitDigits
+    }
+    assertTrue(exc.getMessage().contains("Invariant broken"))

Review Comment:
   I think we assumed that `\r` could never exist in Scala-XML Nodes. In normal 
XML, all CR should be converted to LF, but I guess that's not the case with 
Scala Nodes and `&#13;`, so that assumption was wrong.
   
   This assumption was necessary when we used `\n` in a regex, but we've since 
switched to DOTALL which matches both `\n` and `\r`, so I don't think it really 
matters anymore (in that case).
   
   However, we do have `\n` in the `noWarn` character list but not `\r`, so we 
will create a warning if `\r` is used like in this test, which we probably 
don't want. So I suggest that we remove that invariant and add `\r` to that 
noWarn list so we don't log a warning if it exists and it will be removed just 
like other invalid characters like `\n`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to