1 package com.puppycrawl.tools.checkstyle.checks.whitespace; 2 3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; 4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration; 5 6 public class WhitespaceAroundTest 7 extends BaseCheckTestCase 8 { 9 DefaultConfiguration checkConfig; 10 11 public void setUp() 12 { 13 checkConfig = createCheckConfig(WhitespaceAroundCheck.class); 14 } 15 16 public void testIt() 17 throws Exception 18 { 19 final String [] expected = { 20 "16:22: '=' is not preceded with whitespace.", 21 "16:23: '=' is not followed by whitespace.", 22 "18:24: '=' is not followed by whitespace.", 23 "26:14: '=' is not preceded with whitespace.", 24 "27:10: '=' is not preceded with whitespace.", 25 "27:11: '=' is not followed by whitespace.", 26 "28:10: '+=' is not preceded with whitespace.", 27 "28:12: '+=' is not followed by whitespace.", 28 "29:13: '-=' is not followed by whitespace.", 29 "37:21: 'synchronized' is not followed by whitespace.", 30 "39:12: 'try' is not followed by whitespace.", 31 "39:12: '{' is not preceded with whitespace.", 32 "41:14: 'catch' is not followed by whitespace.", 33 "41:34: '{' is not preceded with whitespace.", 34 "58:11: 'if' is not followed by whitespace.", 35 "76:19: 'return' is not followed by whitespace.", 36 "97:29: '?' is not preceded with whitespace.", 37 "97:30: '?' is not followed by whitespace.", 38 "97:34: ':' is not preceded with whitespace.", 39 "97:35: ':' is not followed by whitespace.", 40 "98:15: '==' is not preceded with whitespace.", 41 "98:17: '==' is not followed by whitespace.", 42 "104:20: '*' is not followed by whitespace.", 43 "104:21: '*' is not preceded with whitespace.", 44 "119:18: '%' is not preceded with whitespace.", 45 "120:20: '%' is not followed by whitespace.", 46 "121:18: '%' is not preceded with whitespace.", 47 "121:19: '%' is not followed by whitespace.", 48 "123:18: '/' is not preceded with whitespace.", 49 "124:20: '/' is not followed by whitespace.", 50 "125:18: '/' is not preceded with whitespace.", 51 "125:19: '/' is not followed by whitespace.", 52 "153:15: 'assert' is not followed by whitespace.", 53 "156:20: ':' is not preceded with whitespace.", 54 "156:21: ':' is not followed by whitespace.", 55 }; 56 verify(checkConfig, getPath("InputWhitespace.java"), expected); 57 } 58 59 public void testIt2() 60 throws Exception 61 { 62 final String [] expected = { 63 "153:27: '=' is not followed by whitespace.", 64 "154:27: '=' is not followed by whitespace.", 65 "155:27: '=' is not followed by whitespace.", 66 "156:27: '=' is not followed by whitespace.", 67 "157:27: '=' is not followed by whitespace.", 68 "158:27: '=' is not followed by whitespace.", 69 }; 70 verify(checkConfig, getPath("InputSimple.java"), expected); 71 } 72 73 public void testIt3() 74 throws Exception 75 { 76 final String [] expected = { 77 "41:14: 'while' is not followed by whitespace.", 78 "58:12: 'for' is not followed by whitespace.", 79 "115:27: '{' is not followed by whitespace.", 82 "115:27: '}' is not preceded with whitespace.", 83 "118:40: '{' is not followed by whitespace.", 84 "118:40: '}' is not preceded with whitespace.", 85 }; 86 verify(checkConfig, getPath("InputBraces.java"), expected); 87 } 88 89 public void testIt4() 90 throws Exception 91 { 92 checkConfig.addAttribute("allowEmptyMethods", "true"); 93 checkConfig.addAttribute("allowEmptyConstructors", "true"); 94 final String [] expected = { 95 "41:14: 'while' is not followed by whitespace.", 96 "58:12: 'for' is not followed by whitespace.", 97 }; 98 verify(checkConfig, getPath("InputBraces.java"), expected); 99 } 100 101 public void testGenericsTokensAreFlagged() 102 throws Exception 103 { 104 final String [] expected = { 105 "6:27: '<' is not preceded with whitespace.", 106 "6:28: '<' is not followed by whitespace.", 107 "6:51: '<' is not preceded with whitespace.", 108 "6:52: '<' is not followed by whitespace.", 109 "6:52: '?' is not preceded with whitespace.", 110 "6:53: '>' is not preceded with whitespace.", 111 "6:53: '?' is not followed by whitespace.", 112 "6:54: '>' is not followed by whitespace.", 113 "6:67: '&' is not preceded with whitespace.", 114 "6:68: '&' is not followed by whitespace.", 115 "6:69: '>' is not preceded with whitespace.", 116 }; 117 verify(checkConfig, getPath("InputGenerics.java"), expected); 118 } 119 120 public void test1322879() throws Exception 121 { 122 final String [] expected = { 123 }; 124 verify(checkConfig, getPath("whitespace/InputWhitespaceAround.java"), 125 expected); 126 } 127 } 128 | Popular Tags |