Add tests

This commit is contained in:
Clément Fournier
2018-08-13 01:09:48 +02:00
parent e4566ea17a
commit 7bc0305835

View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data
xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>Test property defaults</description>
<expected-problems>4</expected-problems>
<expected-messages>
<message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The constant name 'BOLGaaa_FIELD' doesn't match '[A-Z][A-Z_0-9]*'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLGaaa_FIELD;
}
]]></code>
</test-code>
<test-code>
<description>Test default field property</description>
<rule-property name="defaultFieldPattern">[A-Z][A-Z0-9]+</rule-property>
<expected-problems>3</expected-problems>
<expected-messages>
<message>The field name 'Foo' doesn't match '[A-Z][A-Z0-9]+'</message>
<message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLG_FIELD;
}
]]></code>
</test-code>
<test-code>
<description>Test final field property</description>
<rule-property name="finalFieldPattern">[A-Z][A-Z0-9]+</rule-property>
<expected-problems>3</expected-problems>
<expected-messages>
<message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The final field name 'Hoo' doesn't match '[A-Z][A-Z0-9]+'</message>
<message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLG_FIELD;
}
]]></code>
</test-code>
<test-code>
<description>Test static field property</description>
<rule-property name="staticFieldPattern">[A-Z][A-Z0-9]+</rule-property>
<expected-problems>3</expected-problems>
<expected-messages>
<message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The static field name 'Bar' doesn't match '[A-Z][A-Z0-9]+'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLG_FIELD;
}
]]></code>
</test-code>
<test-code>
<description>Test constant field property</description>
<rule-property name="constantPattern">cons_[A-Z][A-Z0-9]+</rule-property>
<expected-problems>4</expected-problems>
<expected-messages>
<message>The field name 'Foo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The final field name 'Hoo' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The static field name 'Bar' doesn't match '[a-z][a-zA-Z0-9]*'</message>
<message>The constant name 'BOLG_FIELD' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLG_FIELD;
}
]]></code>
</test-code>
<test-code>
<description>Test enum constant property</description>
<rule-property name="enumConstantPattern">cons_[A-Z][A-Z0-9]+</rule-property>
<expected-problems>2</expected-problems>
<expected-messages>
<message>The enum constant name 'NET' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
<message>The enum constant name 'ORG' doesn't match 'cons_[A-Z][A-Z0-9]+'</message>
</expected-messages>
<code><![CDATA[
public class Bar {
enum AnEnum {
ORG, NET, cons_COM;
}
}
]]></code>
</test-code>
<test-code>
<description>Interface fields should be treated like constants</description>
<expected-problems>3</expected-problems>
<expected-messages>
<message>The constant name 'Foo' doesn't match '[A-Z][A-Z_0-9]*'</message>
<message>The constant name 'Hoo' doesn't match '[A-Z][A-Z_0-9]*'</message>
<message>The constant name 'Bar' doesn't match '[A-Z][A-Z_0-9]*'</message>
</expected-messages>
<code><![CDATA[
public interface Bar {
int Foo;
final int Hoo;
static int Bar;
static final int BOLG_FIELD;
}
]]></code>
</test-code>
</test-data>