OWL-Varun commented on code in PR #799:
URL: https://github.com/apache/daffodil/pull/799#discussion_r896873352


##########
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:
   Gotcha I understand what you are saying now.



-- 
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