[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Grammatica-users] Testcase fails
From: |
Stefan Ukena |
Subject: |
Re: [Grammatica-users] Testcase fails |
Date: |
Fri, 19 Mar 2004 23:22:02 +0100 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 |
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
'
at junit.framework.Assert.fail(Assert.java:47)
at
net.percederberg.grammatica.test.ParserTestCase.validateLine(ParserTestCase.java:164)
at
net.percederberg.grammatica.test.ParserTestCase.validateLines(ParserTestCase.java:143)
at
net.percederberg.grammatica.test.ParserTestCase.validateTree(ParserTestCase.java:124)
at
net.percederberg.grammatica.test.ParserTestCase.parse(ParserTestCase.java:74)
at
net.percederberg.grammatica.test.TestArithmeticParser.testValidInput(TestArithmeticParser.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
Variables from the debugger:
expected= " NUMBER(1007): "1", line: 1, col: 1\n Ex"
result= " NUMBER(1007): "1", line: 1, col: 1\r"
Per Cederberg wrote:
> Now, doing so on Windows will of course break things
> due to the classical newline problem -- "\r\n" (on Windows) and
> "\n" (on Linux/Unix).
I was wondering about that, so I figured it would be best to use
System.getProperty("line.separator") in the test-case and it does work
that way. This is what I did:
Created a new field in ParserTestCase
public final static String NEWLINE =
System.getProperty("line.separator");
And then used that in the test-case as a new<line character:
private static final String VALID_OUTPUT =
"Expression(2001)" + ParserTestCase.NEWLINE +
" Term(2003)" + ParserTestCase.NEWLINE +
" Factor(2005)" + ParserTestCase.NEWLINE +
" Atom(2006)" + ParserTestCase.NEWLINE +
" NUMBER(1007): \"1\", line: 1, col: 1" +
ParserTestCase.NEWLINE +
" ExpressionRest(2002)" + ParserTestCase.NEWLINE +
" ADD(1001): \"+\", line: 1, col: 3" + ParserTestCase.NEWLINE +
" Expression(2001)" + ParserTestCase.NEWLINE +
" Term(2003)" + ParserTestCase.NEWLINE +
" Factor(2005)" + ParserTestCase.NEWLINE +
" Atom(2006)" + ParserTestCase.NEWLINE +
" NUMBER(1007): \"2\", line: 1, col: 5" +
ParserTestCase.NEWLINE +
" TermRest(2004)" + ParserTestCase.NEWLINE +
" MUL(1003): \"*\", line: 1, col: 6" +
ParserTestCase.NEWLINE +
" Term(2003)" + ParserTestCase.NEWLINE +
" Factor(2005)" + ParserTestCase.NEWLINE +
" Atom(2006)" + ParserTestCase.NEWLINE +
" IDENTIFIER(1008): \"a\", line: 1, col: 7" +
ParserTestCase.NEWLINE +
" ExpressionRest(2002)" + ParserTestCase.NEWLINE +
" ADD(1001): \"+\", line: 2, col: 2" +
ParserTestCase.NEWLINE +
" Expression(2001)" + ParserTestCase.NEWLINE +
" Term(2003)" + ParserTestCase.NEWLINE +
" Factor(2005)" + ParserTestCase.NEWLINE +
" Atom(2006)" + ParserTestCase.NEWLINE +
" NUMBER(1007): \"345\", line: 2, col: 4" +
ParserTestCase.NEWLINE;
Thanks again for the help! I'll be back asking more questions when I'll
start writing my first grammar ;-)
Stefan