View Javadoc

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