Code Search for Developers
 
 
  

Prog2Test.groovy from Groovy Eclipse Monkey at Krugle


Show Prog2Test.groovy syntax highlighted

package chap1;
class Prog2Test extends GroovyTestCase  
{
    
    def prog2 = new Prog2()

	void testInterpretNumExp()
	{
	    def value = prog2.interpretExpression( num( 13 ) )
	    assert value instanceof IntAndTable
	    assert value.table.isEmpty()
	    assert value.returnValue == 13
	}
    void testInterpretIdExp()
    {
        def value = prog2.interpretExpression( idExp( 'James' ) )
	    assert value instanceof IntAndTable
	    assert !value.table.isEmpty()
	    assert value.table.containsKey( 'James' )
	    assert value.table.James == 0
	    assert value.returnValue == 0
    }
    void testInterpretSimpleOpExp()
    {
        def value = prog2.interpretExpression( add( num( 5 ), num( 8 ) ) )
        assert value instanceof IntAndTable
	    assert value.table.isEmpty()
	    assert value.returnValue == 13
    }
    void testInterpretSimpleAssignStm()
    {
        def value = prog2.interpretStatement( assign( 'a', num( 13 ) ) )
        assert value instanceof Map
        assert !value.isEmpty()
        assert value.containsKey( 'a' )
        assert value.a == 13
    }
    void testInterpretSimpleCompoundStm()
    {
        def value = prog2.interpretStatement( compound( assign( 'a', num( 13 ) ), 
                							  			assign( 'b', add( idExp( 'a' ), num( 8 ) ) ) ) )
        assert value instanceof Map
        assert !value.isEmpty()
        assert value.containsKey( 'a' )
        assert value.a == 13
        assert value.containsKey( 'b' )
        assert value.b == 21
    }
    void testWholeShebang()
    {
        def value = prog2.interpretStatement( compound( assign( 'a', add( num( 5 ), num( 3 ) ) ), 
  			  								  		    compound( assign( 'b', eseqExp( printStm( pairExpList( idExp( 'a' ), lastExpList( sub( idExp( 'a' ), num( 1 ) ) ) ) ), 
				 		  																times( num( 10 ), idExp( 'a' ) ) ) ), 
																  printStm( lastExpList( idExp( 'b' ) ) ) ) ) )
		assert value instanceof Map
		assert !value.isEmpty()
		assert value.containsKey( 'a' )
		assert value.a == 8
		assert value.containsKey( 'b' )
		assert value.b == 80
		println "value: ${value}"
		assert value.__output__ == "8 7\n80\n"
    }
    Object invokeMethod( final String name, final Object args )
    {
		return ConstructorsCategory.invokeMethod( name, args )
    }
}



See more files for this project here

Groovy Eclipse Monkey

Groovy Monkey is a Utility for Eclipse that enables you to create scripts in Groovy, Beanshell, Python or Ruby to run directly in Eclipse. This tool can be used to Eclipse API exploration, automation scripts, and rapid plugin prototyping.

Project homepage: http://sourceforge.net/projects/groovy-monkey
Programming language(s): Groovy,Java,XML
License: other

  AllTests.java
  AssignStm.groovy
  CompoundStm.groovy
  ConstructorsCategory.groovy
  EseqExp.groovy
  Exp.groovy
  ExpList.groovy
  IdExp.groovy
  IntAndTable.groovy
  LastExpList.groovy
  NumExp.groovy
  OpExp.groovy
  Ops.java
  PairExpList.groovy
  PrintStm.groovy
  Prog1.groovy
  Prog2.groovy
  Prog2Test.groovy
  Stm.groovy