View Javadoc

    1   package net.sourceforge.pmd.cpd;
    2
    3   import java.io.IOException;
    4
    5   import net.sourceforge.pmd.PMD;
    6   import net.sourceforge.pmd.cpd.RubyTokenizer;
    7   import net.sourceforge.pmd.cpd.SourceCode;
    8   import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
    9
    10  import org.junit.Before;
    11  import org.junit.Test;
    12
    13
    14
    15  public class RubyTokenizerTest extends AbstractTokenizerTest {
    16
    17  	@Before
    18  	@Override
    19  	public void buildTokenizer() {
    20  		this.tokenizer = new RubyTokenizer();
    21  		this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), "server.rb"));
    22  	}
    23
    24  	@Override
    25  	public String getSampleCode() {
    26  		 return "require \"socket\"" + PMD.EOL +
    27  		 "" + PMD.EOL +
    28  		 "gs = TCPServer.open(0)" + PMD.EOL +
    29  		 "addr = gs.addr" + PMD.EOL +
    30  		 "addr.shift" + PMD.EOL +
    31  		 "" + PMD.EOL +
    32  		 "while true" + PMD.EOL +
    33  		 "  ns = gs.accept" + PMD.EOL +
    34  		 "  print(ns, \" is accepted\")" + PMD.EOL +
    35  		 "  Thread.start do" + PMD.EOL +
    36  		 "    s = ns                      # save to dynamic variable" + PMD.EOL +
    37  		 "    while s.gets" + PMD.EOL +
    38  		 "      s.write($_)" + PMD.EOL +
    39  		 "    end" + PMD.EOL +
    40  		 "    print(s, \" is " + PMD.EOL +
    41  		 "               gone" + PMD.EOL +
    42  		 "                       and" + PMD.EOL +
    43  		 "                               dead\")" + PMD.EOL +
    44  		 "    s.close" + PMD.EOL +
    45  		 "  end" + PMD.EOL +
    46  		 "end" + PMD.EOL;
    47  	 }
    48
    49  	@Test
    50  	public void tokenizeTest() throws IOException {
    51  		this.expectedTokenCount = 30;
    52  		super.tokenizeTest();
    53  	}
    54
    55      public static junit.framework.Test suite() {
    56          return new junit.framework.JUnit4TestAdapter(RubyTokenizerTest.class);
    57      }
    58  }