1+ package ;
2+
3+ import checkstyle .checks .EmptyBlockCheck ;
4+
5+ class EmptyBlockCheckTest extends CheckTestCase {
6+
7+ public function testCorrectEmptyBlock () {
8+ var check = new EmptyBlockCheck ();
9+ assertMsg (check , EmptyBlockTests .TEST , ' ' );
10+ assertMsg (check , EmptyBlockTests .TEST2 , ' ' );
11+ assertMsg (check , EmptyBlockTests .TEST3 , ' ' );
12+ assertMsg (check , EmptyBlockTests .TEST5 , ' ' );
13+ }
14+
15+ public function testWrongEmptyBlock () {
16+ var check = new EmptyBlockCheck ();
17+ assertMsg (check , EmptyBlockTests .TEST1 , ' Empty block should be written as {}' );
18+ assertMsg (check , EmptyBlockTests .TEST4 , ' Empty block should be written as {}' );
19+ assertMsg (check , EmptyBlockTests .TEST6 , ' Empty block should be written as {}' );
20+ }
21+
22+ public function testOptionText () {
23+ var check = new EmptyBlockCheck ();
24+ check .option = EmptyBlockCheck .TEXT ;
25+
26+ assertMsg (check , EmptyBlockTests .TEST , ' Empty block should contain a comment' );
27+ assertMsg (check , EmptyBlockTests .TEST1 , ' Empty block should contain a comment' );
28+ assertMsg (check , EmptyBlockTests .TEST2 , ' ' );
29+ assertMsg (check , EmptyBlockTests .TEST3 , ' Empty block should contain a comment' );
30+ assertMsg (check , EmptyBlockTests .TEST4 , ' Empty block should contain a comment' );
31+ assertMsg (check , EmptyBlockTests .TEST5 , ' ' );
32+ }
33+ }
34+
35+ class EmptyBlockTests {
36+ public static inline var TEST : String = "
37+ class Test {
38+ public function new() {}
39+ }" ;
40+
41+ public static inline var TEST1 : String = "
42+ class Test {
43+ public function new(){
44+
45+ }
46+ }" ;
47+
48+ public static inline var TEST2 : String =
49+ " class Test {
50+ public function new() {
51+ // comment
52+ }
53+ }" ;
54+
55+ public static inline var TEST3 : String =
56+ " class Test {
57+ public function new() {
58+ var a = {};
59+ }
60+ }" ;
61+
62+ public static inline var TEST4 : String = "
63+ class Test {
64+ public function new() {
65+ var a = {
66+ };
67+ }
68+ }" ;
69+
70+ public static inline var TEST5 : String = "
71+ class Test {
72+ public function new() {
73+ var a = {
74+ // comment
75+ };
76+ }
77+ }" ;
78+
79+ public static inline var TEST6 : String = "
80+ class Test {
81+ public function new() {
82+ }
83+ }" ;
84+ }
0 commit comments