Package org.jostraca.test

Source Code of org.jostraca.test.BasicTemplateAntlrParserTest

/*
* Name:    BasicTemplateAntlrParserTest
* Authors: Richard Rodger
* Release: 0.3
*
* Copyright (c) 2002-2003 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.test;


/* Import << */
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.jostraca.Block;
import org.jostraca.BlockList;
import org.jostraca.BasicTemplateAntlrParser;
import org.jostraca.BasicTemplateAntlrLexer;

import java.io.StringReader;
/* Import >> */


/** <b>Description:</b><br>
*  Test cases for org.jostraca.Block
*/
public class BasicTemplateAntlrParserTest extends TestCase {

  public BasicTemplateAntlrParserTest( String pName ) {
    super( pName );
  }

  public static TestSuite suite() {
    return new TestSuite( BasicTemplateAntlrParserTest.class );
  }

  public static void main( String[] pArgs ) {
    TestRunner.run( suite() );
  }



  public void testParseText() throws Exception {
    String p01 = "text";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_text, p01 ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }

  public void testParseComment() throws Exception {
    String p01 = "<%-- comment --%>";
    BlockList bl01 = new BlockList();

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }

  public void testParseScript() throws Exception {
    String p01 = "<%script%>";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_script, "script" ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }


  public void testParseUsual() throws Exception {
    String p01 = "text1\n<% script1 %>\n<% @d foo %>\ntext2 \ntext3<%-- a comment --%>\n<% script3 %> text4\n";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_text,   "text1\n"   ) );
    bl01.add( new Block( Block.TYPE_script, " script1 " ) );
    bl01.add( new Block( Block.TYPE_text,   "\n"        ) );
    bl01.add( new Block( Block.TYPE_script, " @d foo "  ) );
    bl01.add( new Block( Block.TYPE_text,   "\ntext2 \ntext3" ) );
    bl01.add( new Block( Block.TYPE_text,   "\n"              ) );
    bl01.add( new Block( Block.TYPE_script, " script3 "       ) );
    bl01.add( new Block( Block.TYPE_text,   " text4\n"        ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }


  public void testParseScriptEnds() throws Exception {
    String p01 = "<% script1 %> text1 <% script2 %>";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_script, " script1 " ) );
    bl01.add( new Block( Block.TYPE_text,   " text1 "   ) );
    bl01.add( new Block( Block.TYPE_script, " script2 " ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }


  public void testParseCommentEnds() throws Exception {
    String p01 = "<%-- comment1 --%><% script1 %> text1 <% script2 %><%-- comment2 --%>";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_script, " script1 " ) );
    bl01.add( new Block( Block.TYPE_text,   " text1 "   ) );
    bl01.add( new Block( Block.TYPE_script, " script2 " ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }


  public void testParseCommentInsides() throws Exception {
    String p01 = "<% script1 %> text1 <%--<%foo%>--%> <%--<%--%> <%--%>--%> <% script2 %>";
    BlockList bl01 = new BlockList();
    bl01.add( new Block( Block.TYPE_script, " script1 " ) );
    bl01.add( new Block( Block.TYPE_text,   " text1 "   ) );
    bl01.add( new Block( Block.TYPE_text,   " "   ) );
    bl01.add( new Block( Block.TYPE_text,   " "   ) );
    bl01.add( new Block( Block.TYPE_text,   " "   ) );
    bl01.add( new Block( Block.TYPE_script, " script2 " ) );

    BlockList bl01o = parse( p01 );
    //System.out.println( bl01o );
    assertEquals( bl01, bl01o );
  }


  public BlockList parse( String rText ) throws Exception {
    BasicTemplateAntlrLexer  btal = new BasicTemplateAntlrLexer( new StringReader( rText ) );
    BasicTemplateAntlrParser btap = new BasicTemplateAntlrParser( btal );
    btap.template();
    return btap.getBlockList();
  }

}




TOP

Related Classes of org.jostraca.test.BasicTemplateAntlrParserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.