001 package org.hackystat.telemetry.analyzer.language.parser; 002 003 import junit.framework.TestCase; 004 005 import org.hackystat.telemetry.analyzer.language.parser.impl.TokenMgrError; 006 007 /** 008 * Test suite for <code>ParsingException</code>. 009 * 010 * @author (Cedric) Qin Zhang 011 * @version $Id: TestParsingException.java,v 1.1.1.1 2005/10/20 23:56:49 johnson 012 * Exp $ 013 */ 014 public class TestParsingException extends TestCase { 015 016 /** 017 * Test case. 018 */ 019 public void testAll() { 020 String defs = "streams MyStreamsA = {\"desc\", MyReducerA )};"; 021 // 1234567890A234567890<== encountered =, expecting ( 022 try { 023 TelemetryLanguageParser.parse(defs); 024 fail("An expected exception not raised."); 025 } 026 catch (ParsingException ex) { 027 assertEquals(1, ex.getErrorLineNumber()); 028 assertEquals(20, ex.getErrorColumnNumber()); 029 } 030 } 031 032 /** 033 * Tests whether we can extract line and column numbers from 034 * <code>TokenMgrError</code>. 035 */ 036 public void testWithTokenMgrError() { 037 // test 1 038 String msg = " Lexical error at line 2, column 53. Encountered:...(12) "; 039 TokenMgrError tokenError = new TokenMgrError(msg, 0); // 0 is Lexical Error 040 ParsingException parsingException = new ParsingException(tokenError); 041 assertEquals(2, parsingException.getErrorLineNumber()); 042 assertEquals(53, parsingException.getErrorColumnNumber()); 043 044 // test 2 045 msg = " Lexical error. Encountered:...(12) "; 046 tokenError = new TokenMgrError(msg, 0); // 0 is Lexical Error 047 parsingException = new ParsingException(tokenError); 048 assertEquals(-1, parsingException.getErrorLineNumber()); 049 assertEquals(-1, parsingException.getErrorColumnNumber()); 050 } 051 }