Exemple #1
0
def test_ParseBuildStep_process():

    step = ParseBuildStep()

    tokens = Iterable2TokenStream( (
        make_token( "print", PepperLexer.SYMBOL, 4, 1 ),
        make_token( "(",     PepperLexer.LPAREN, 4, 6 ),
        make_token( "Hello", PepperLexer.STRING, 4, 8 ),
        make_token( ")",     PepperLexer.RPAREN, 4, 15 ),
        make_token( "\n",    PepperLexer.NEWLINE, 4, 16 ),
        ) )

    values = list( step.process( tokens ) )

    assert_equal( len( values ), 1 )

    fncall = values[0]
    assert_equal( fncall.__class__, PepFunctionCall )
    assert_equal( fncall.func_name, "print" )
    func = fncall.func
    assert_equal( func.__class__, PepSymbol )
    assert_equal( func.symbol_name, "print" )
    args = fncall.args
    assert_equal( len( args ), 1 )
    hwstr = args[0]
    assert_equal( hwstr.__class__, PepString )
    assert_equal( hwstr.value, "Hello" )
Exemple #2
0
def test_ParseBuildStep_read_from_file():

    step = ParseBuildStep()

    in_fl = StringIO( """

    # Comment
    PepFunctionCall( PepSymbol( "print" ), ( PepString( "Hello, world!" ), ) ) #com
    """ )

    values = list( step.read_from_file( in_fl ) )

    assert_equal( len( values ), 1 )

    fncall = values[0]
    assert_equal( fncall.__class__, PepFunctionCall )
    assert_equal( fncall.func_name, "print" )
    func = fncall.func
    assert_equal( func.__class__, PepSymbol )
    assert_equal( func.symbol_name, "print" )
    args = fncall.args
    assert_equal( len( args ), 1 )
    hwstr = args[0]
    assert_equal( hwstr.__class__, PepString )
    assert_equal( hwstr.value, "Hello, world!" )
Exemple #3
0
def test_ParseBuildStep_write_to_file():

    step = ParseBuildStep()

    parsetree = [
        PepFunctionCall( PepSymbol( 'print' ), (
            PepString( 'Hello,' ),
            ) ),
        PepFunctionCall( PepSymbol( 'print' ), (
            PepString( 'world!' ),
            ) ),
        ]

    out_fl = StringIO()

    step.write_to_file( parsetree, out_fl )

    assert_equal( out_fl.getvalue(),
        """PepFunctionCall(PepSymbol('print'),(PepString('Hello,'),))
PepFunctionCall(PepSymbol('print'),(PepString('world!'),))
""" )