}
public void testPythonIndenter() throws Exception {
PythonIndenter pi = new PythonIndenter();
PropertySet mps = new PropertySet();
String tabAsSpaces = " ";
mps.set( PropertyPython.standardIndent, " " );
mps.set( PropertyPython.tabAsSpaces, tabAsSpaces);
mps.set( PropertyPython.nonStatementLineRegExp, "^[ \\t]*(#.*)?$" );
mps.set( PropertyPython.controlFlowRegExp, ":[ \\t]*(#.*)?$" );
mps.set( Property.lang_InsertPrefix, "_py_insert( " );
Section sec = new BasicSection( "sec" );
String in1 = "print 'foo' ";
String out1 = "print 'foo' ";
sec.setContent( in1 );
pi.modify( sec, mps );
//System.out.println( in1 );
//System.out.println( out1 );
//System.out.println( sec.getContent() );
assertTrue( out1.equals( sec.getContent() ) );
String in2 = " print 'foo' ";
String out2 = " print 'foo' ";
sec.setContent( in2 );
pi.modify( sec, mps );
//System.out.println( in2 );
//System.out.println( out2 );
//System.out.println( sec.getContent() );
assertTrue( out2.equals( sec.getContent() ) );
String in3
= "print 'foo'"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"
;
String out3
= "print 'foo'"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"
;
sec.setContent( in3 );
pi.modify( sec, mps );
//System.out.println( in3 );
//System.out.println( out3 );
//System.out.println( sec.getContent() );
assertTrue( out3.equals( sec.getContent() ) );
String in4
= " print 'foo'"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"
;
String out4
= " print 'foo'"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in4 );
pi.modify( sec, mps );
//System.out.println( in4 );
//System.out.println( out4 );
//System.out.println( sec.getContent() );
assertTrue( out4.equals( sec.getContent() ) );
String in4_1
= " print 'foo'"+Standard.NEWLINE
+ " "+Standard.NEWLINE
+ "_py_insert( \"abc\" )"
;
String out4_1
= " print 'foo'"+Standard.NEWLINE
+ " "+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in4_1 );
pi.modify( sec, mps );
//System.out.println( in4_1 );
//System.out.println( out4_1 );
//System.out.println( sec.getContent() );
assertTrue( out4_1.equals( sec.getContent() ) );
String in4_2
= " print 'foo'"+Standard.NEWLINE
+ " # foo"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"
;
String out4_2
= " print 'foo'"+Standard.NEWLINE
+ " # foo"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in4_2 );
pi.modify( sec, mps );
//System.out.println( in4_2 );
//System.out.println( out4_2 );
//System.out.println( sec.getContent() );
assertTrue( out4_2.equals( sec.getContent() ) );
String in5
= "if foo == bar :"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
String out5
= "if foo == bar :"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in5 );
pi.modify( sec, mps );
//System.out.println( in5 );
//System.out.println( out5 );
//System.out.println( sec.getContent() );
assertTrue( out5.equals( sec.getContent() ) );
String in6
= "if foo == bar : "+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
String out6
= "if foo == bar : "+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in6 );
pi.modify( sec, mps );
//System.out.println( in6 );
//System.out.println( out6 );
//System.out.println( sec.getContent() );
assertTrue( out6.equals( sec.getContent() ) );
String in7
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
String out7
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in7 );
pi.modify( sec, mps );
//System.out.println( in7 );
//System.out.println( out7 );
//System.out.println( sec.getContent() );
assertTrue( out7.equals( sec.getContent() ) );
String in8
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
String out8
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
sec.setContent( in8 );
pi.modify( sec, mps );
//System.out.println( in8 );
//System.out.println( out8 );
//System.out.println( sec.getContent() );
assertTrue( out8.equals( sec.getContent() ) );
String in9
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " pass"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
String out9
= "if foo == bar : # fooby"+Standard.NEWLINE
+ " pass"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"
;
sec.setContent( in9 );
pi.modify( sec, mps );
//System.out.println( in9 );
//System.out.println( out9 );
//System.out.println( sec.getContent() );
assertTrue( out9.equals( sec.getContent() ) );
String in10
= " if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
String out10
= " if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
sec.setContent( in10 );
pi.modify( sec, mps );
//System.out.println( in10 );
//System.out.println( out10 );
//System.out.println( sec.getContent() );
assertTrue( out10.equals( sec.getContent() ) );
String in11
= " if foo == bar : # fooby"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
String out11
= " if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ " pass"
;
sec.setContent( in11 );
pi.modify( sec, mps );
//System.out.println( in11 );
//System.out.println( out11 );
//System.out.println( sec.getContent() );
assertTrue( out11.equals( sec.getContent() ) );
String in12
= " if foo == bar : # fooby"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"+Standard.NEWLINE
+ "pass"
;
String out12
= " if foo == bar : # fooby"+Standard.NEWLINE
+ " _py_insert( \"abc\" )"+Standard.NEWLINE
+ "pass"
;
sec.setContent( in12 );
pi.modify( sec, mps );
//System.out.println( in12 );
//System.out.println( out12 );
//System.out.println( sec.getContent() );
assertTrue( out12.equals( sec.getContent() ) );
String in13
= "\tif foo == bar : # fooby"+Standard.NEWLINE
+ "_py_insert( \"abc\" )"+Standard.NEWLINE
+ "pass"
;
String out13
= "\tif foo == bar : # fooby"+Standard.NEWLINE
+ tabAsSpaces+" _py_insert( \"abc\" )"+Standard.NEWLINE
+ "pass"
;
sec.setContent( in13 );
pi.modify( sec, mps );
//System.out.println( in13 );
//System.out.println( out13 );
//System.out.println( sec.getContent() );
assertTrue( out13.equals( sec.getContent() ) );
String in14
= "def list( max ) :"+Standard.NEWLINE
+ ""+Standard.NEWLINE
+ " _py_insert( \"\\nlist\" )"+Standard.NEWLINE
+ "_py_insert( max )"+Standard.NEWLINE
+ "_py_insert( \" = \" )"+Standard.NEWLINE
+ ""+Standard.NEWLINE
+ ""+Standard.NEWLINE
+ " for i in range( 0, max ) :"+Standard.NEWLINE
+ " _py_insert( \"[\" )"+Standard.NEWLINE
+ "_py_insert( i )"+Standard.NEWLINE
+ "_py_insert( \"]\" )"+Standard.NEWLINE
;
String out14
= "def list( max ) :"+Standard.NEWLINE
+ " _py_insert( \"\\nlist\" )"+Standard.NEWLINE
+ " _py_insert( max )"+Standard.NEWLINE
+ " _py_insert( \" = \" )"+Standard.NEWLINE
+ " for i in range( 0, max ) :"+Standard.NEWLINE
+ " _py_insert( \"[\" )"+Standard.NEWLINE
+ " _py_insert( i )"+Standard.NEWLINE
+ " _py_insert( \"]\" )"+Standard.NEWLINE
;
sec = new BasicSection( "declare" );
sec.setContent( in14 );
pi.modify( sec, mps );
//System.out.println( in14 );
//System.out.println( out14 );
//System.out.println( sec.getContent() );
assertTrue( out14.equals( sec.getContent() ) );