1 package com.puppycrawl.tools.checkstyle; 2 3 import com.puppycrawl.tools.checkstyle.checks.AbstractOption; 4 import com.puppycrawl.tools.checkstyle.checks.blocks.BlockOption; 5 import com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyOption; 6 import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyOption; 7 import com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapOption; 8 import com.puppycrawl.tools.checkstyle.checks.whitespace.PadOption; 9 import junit.framework.TestCase; 10 11 15 public class OptionTest extends TestCase { 16 17 public void testBlockOption() 18 { 19 BlockOption stmtOpt = BlockOption.STMT; 20 assertEquals("STMT", "stmt", stmtOpt.toString()); 21 BlockOption textOpt = BlockOption.TEXT; 22 assertEquals("TEXT", "text", textOpt.toString()); 23 BlockOption stmtDecode = (BlockOption)(stmtOpt.decode("stmt")); 24 assertTrue("STMT decode", stmtOpt == stmtDecode); 25 BlockOption textDecode = (BlockOption)(stmtOpt.decode("text")); 26 assertTrue("TEXT decode", textOpt == textDecode); 27 } 28 29 public void testLeftCurlyOption() 30 { 31 LeftCurlyOption eolOpt = LeftCurlyOption.EOL; 32 assertEquals("EOL", "eol", eolOpt.toString()); 33 LeftCurlyOption nlOpt = LeftCurlyOption.NL; 34 assertEquals("NL", "nl", nlOpt.toString()); 35 LeftCurlyOption nlowOpt = LeftCurlyOption.NLOW; 36 assertEquals("NLOW", "nlow", nlowOpt.toString()); 37 LeftCurlyOption eolDecode = (LeftCurlyOption)(eolOpt.decode("eol")); 38 assertTrue("EOL decode", eolOpt == eolDecode); 39 LeftCurlyOption nlDecode = (LeftCurlyOption)(nlOpt.decode("nl")); 40 assertTrue("NL decode", nlOpt == nlDecode); 41 LeftCurlyOption nlowDecode = (LeftCurlyOption)(nlowOpt.decode("nlow")); 42 assertTrue("NL decode", nlowOpt == nlowDecode); 43 } 44 45 public void testOperatorWrapOption() 46 { 47 OperatorWrapOption eolOpt = OperatorWrapOption.EOL; 48 assertEquals("EOL", "eol", eolOpt.toString()); 49 OperatorWrapOption nlOpt = OperatorWrapOption.NL; 50 assertEquals("NL", "nl", nlOpt.toString()); 51 OperatorWrapOption eolDecode = (OperatorWrapOption)(eolOpt.decode("eol")); 52 assertTrue("EOL decode", eolOpt == eolDecode); 53 OperatorWrapOption nlDecode = (OperatorWrapOption)(nlOpt.decode("nl")); 54 assertTrue("NL decode", nlOpt == nlDecode); 55 } 56 57 public void testPadOption() 58 { 59 PadOption nospaceOpt = PadOption.NOSPACE; 60 assertEquals("NOSPACE", "nospace", nospaceOpt.toString()); 61 PadOption spaceOpt = PadOption.SPACE; 62 assertEquals("SPACE", "space", spaceOpt.toString()); 63 PadOption nospaceDecode = (PadOption)(nospaceOpt.decode("nospace")); 64 assertTrue("NOSPACE decode", nospaceOpt == nospaceDecode); 65 PadOption spaceDecode = (PadOption)(spaceOpt.decode("space")); 66 assertTrue("SPACE decode", spaceOpt == spaceDecode); 67 } 68 69 public void testRightCurlyOption() 70 { 71 RightCurlyOption aloneOpt = RightCurlyOption.ALONE; 72 assertEquals("ALONE", "alone", aloneOpt.toString()); 73 RightCurlyOption sameOpt = RightCurlyOption.SAME; 74 assertEquals("SAME", "same", sameOpt.toString()); 75 RightCurlyOption aloneDecode = (RightCurlyOption)(aloneOpt.decode("alone")); 76 assertTrue("ALONE decode", aloneOpt == aloneDecode); 77 RightCurlyOption sameDecode = (RightCurlyOption)(sameOpt.decode("same")); 78 assertTrue("SAME decode", sameOpt == sameDecode); 79 } 80 81 public void testEqualKeys() 82 { 83 LeftCurlyOption eolLeftCurl = LeftCurlyOption.EOL; 84 LeftCurlyOption eolLeftCurlDecode = 85 (LeftCurlyOption)(eolLeftCurl.decode("eol")); 86 OperatorWrapOption eolOpWrap = OperatorWrapOption.EOL; 87 OperatorWrapOption eolOpWrapDecode = 88 (OperatorWrapOption)(eolOpWrap.decode("eol")); 89 assertTrue("eol", 90 (AbstractOption)eolLeftCurlDecode 91 != (AbstractOption)eolOpWrapDecode); 92 93 LeftCurlyOption nlLeftCurl = LeftCurlyOption.NL; 94 LeftCurlyOption nlLeftCurlDecode = 95 (LeftCurlyOption)(nlLeftCurl.decode("nl")); 96 OperatorWrapOption nlOpWrap = OperatorWrapOption.NL; 97 OperatorWrapOption nlOpWrapDecode = 98 (OperatorWrapOption)(nlOpWrap.decode("eol")); 99 assertTrue("nl", 100 (AbstractOption)nlLeftCurlDecode 101 != (AbstractOption)nlOpWrapDecode); 102 } 103 } 104 | Popular Tags |