grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] Testcase fails


From: Per Cederberg
Subject: Re: [Grammatica-users] Testcase fails
Date: Sat, 20 Mar 2004 02:13:04 +0100

On Fri, 2004-03-19 at 23:22, Stefan Ukena wrote:
> Hi Per,
> 
> thanks for your quick response. Actually I have tried that myself (and
> just did so again). This is what I got (I found a solution though, see
> below):
> 
> junit.framework.AssertionFailedError: on line: 5, expected: '
> NUMBER(1007): "1", line: 1, col: 1
>   Ex', found: '        NUMBER(1007): "1", line: 1, col: 1
> '

Aha! I understand... Seems my code was more broken than I first
thought. Using the same index for both strings is bound to create
problems like this. Here's the second attempt at fixing the 
problem. I think I've done a more profound (and hopefully correct)
solution this time:

--- test/src/java/net/percederberg/grammatica/test/ParserTestCase.java  
(revision 34)
+++ test/src/java/net/percederberg/grammatica/test/ParserTestCase.java  
(revision 35)
@@ -132,23 +132,31 @@
      * @param result         the result obtained
      */
     private void validateLines(String expected, String result) {
-        int  line = 1;
-        int  pos;
+        int     line = 1;
+        String  expectLine;
+        String  resultLine;
+        int     pos;
  
-        pos = result.indexOf('\n');
-        while (pos > 0) {
-            if (expected.length() < pos) {
-                break;
+        while (expected.length() > 0 || result.length() > 0) {
+            pos = expected.indexOf('\n');
+            if (pos >= 0) {
+                expectLine = expected.substring(0, pos);
+                expected = expected.substring(pos + 1);
+            } else {
+                expectLine = expected;
+                expected = "";
             }
-            validateLine(line,
-                         expected.substring(0, pos),
-                         result.substring(0, pos));
-            expected = expected.substring(pos + 1);
-            result = result.substring(pos + 1);
             pos = result.indexOf('\n');
+            if (pos >= 0) {
+                resultLine = result.substring(0, pos);
+                result = result.substring(pos + 1);
+            } else {
+                resultLine = result;
+                result = "";
+            }
+            validateLine(line, expectLine, resultLine);
             line++;
         }
-        validateLine(line, expected, result);
     }
      

I'll update CVS HEAD with these fixes in a moment.

Cheers,

/Per






reply via email to

[Prev in Thread] Current Thread [Next in Thread]