Convert ObjC tests

This commit is contained in:
Clément Fournier
2020-06-13 23:44:34 +02:00
parent 60d028a282
commit 15d6515278
10 changed files with 1122 additions and 110 deletions

View File

@ -80,10 +80,20 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -4,34 +4,41 @@
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
public class ObjectiveCTokenizerTest extends AbstractTokenizerTest {
public class ObjectiveCTokenizerTest extends CpdTextComparisonTest {
private static final String FILENAME = "AFHTTPRequestOperation.m";
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new ObjectiveCTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
public ObjectiveCTokenizerTest() {
super(".m");
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME), StandardCharsets.UTF_8);
protected String getResourcePrefix() {
return "../lang/objc/cpd/testdata";
}
@Override
public Tokenizer newTokenizer(Properties properties) {
return new ObjectiveCTokenizer();
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = 884;
super.tokenizeTest();
public void testLongSample() {
doTest("big_sample");
}
@Test
public void testUnicodeEscape() {
doTest("unicodeEscapeInString");
}
@Test
public void testUnicodeCharInIdent() {
doTest("unicodeCharInIdent");
}
}

View File

@ -1,38 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
//Tests if the ObjectiveC tokenizer supports UTF-8 escapes in string literals
public class UTF8EscapesInStringLiteralObjCTokenizerTest extends AbstractTokenizerTest {
private static final String FILENAME = "FileWithUTF8EscapeInStringLiteral.m";
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new ObjectiveCTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME), StandardCharsets.UTF_8);
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = 45;
super.tokenizeTest();
}
}

View File

@ -1,55 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
//Tests if the ObjectiveC tokenizer supports identifiers with unicode characters
public class UnicodeObjectiveCTokenizerTest extends AbstractTokenizerTest {
private static final String FILENAME = "NCClient.m";
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new ObjectiveCTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME), StandardCharsets.UTF_8);
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = 10;
super.tokenizeTest();
}
@Test
public void testIgnoreBetweenSpecialComments() throws IOException {
SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(
"// CPD-OFF" + PMD.EOL
+ "static SecCertificateRef gNСServerLogonCertificate;" + PMD.EOL
+ "// CPD-ON" + PMD.EOL
+ "@end" + PMD.EOL
));
Tokens tokens = new Tokens();
tokenizer.tokenize(sourceCode, tokens);
TokenEntry.getEOF();
assertEquals(2, tokens.size()); // 2 tokens: "@end" + EOF
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[@] 1 1
[import] 2 7
[UIKit] 9 13
[;] 14 14
L4
[static] 1 6
[SecCertificateRef] 8 24
[gNСServerLogonCertificate] 26 50
[;] 51 51
L6
[@end] 1 4
EOF

View File

@ -0,0 +1,52 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[@property] 1 9
[(] 11 11
[nonatomic] 12 20
[,] 21 21
[strong] 23 28
[)] 29 29
[UIButton] 31 38
[*] 40 40
[copyrightsButton] 41 56
[;] 57 57
L3
[-] 1 1
[(] 3 3
[void] 4 7
[)] 8 8
[setupCopyrightsButton] 9 29
[{] 31 31
L4
[self] 5 8
[.] 9 9
[copyrightsButton] 10 25
[=] 27 27
[\[] 29 29
[\[] 30 30
[UIButton] 31 38
[alloc] 40 44
[\]] 45 45
[initWithFrame] 47 59
[:] 60 60
[CGRectZero] 61 70
[\]] 71 71
[;] 72 72
L5
[\[] 5 5
[self] 6 9
[.] 10 10
[copyrightsButton] 11 26
[setTitle] 28 35
[:] 36 36
[@"\\u00a9"] 37 45
[forState] 47 54
[:] 55 55
[UIControlStateNormal] 56 75
[\]] 76 76
[;] 77 77
L6
[}] 1 1
L8
[@end] 1 4
EOF