From bd81c7817afb515aa36c930d0a84ab3e8bc604b8 Mon Sep 17 00:00:00 2001 From: Pablissimo Date: Sun, 25 Jan 2015 20:27:31 +0000 Subject: [PATCH] Finishing off tests for TsRulesDefinition --- .../sonar/TsRulesDefinitionTest.java | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/src/test/java/com/pablissimo/sonar/TsRulesDefinitionTest.java b/src/test/java/com/pablissimo/sonar/TsRulesDefinitionTest.java index 2a4a45d..fe5d3f1 100644 --- a/src/test/java/com/pablissimo/sonar/TsRulesDefinitionTest.java +++ b/src/test/java/com/pablissimo/sonar/TsRulesDefinitionTest.java @@ -255,7 +255,171 @@ public void ConfiguresNoUnusedExpressionRule() { Rule rule = getRule(TsRulesDefinition.RULE_NO_UNUSED_EXPRESSION); assertEquals(Severity.MAJOR, rule.severity()); } + + @Test + public void ConfiguresNoUnusedVariableRule() { + Rule rule = getRule(TsRulesDefinition.RULE_NO_UNUSED_VARIABLE); + assertEquals(Severity.MAJOR, rule.severity()); + + RulesDefinition.Param checkParametersParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_PARAMETERS); + assertEquals(RuleParamType.BOOLEAN, checkParametersParam.type()); + assertEquals("false", checkParametersParam.defaultValue()); + } + + @Test + public void ConfiguresOneLineRule() { + Rule rule = getRule(TsRulesDefinition.RULE_ONE_LINE); + assertEquals(Severity.MINOR, rule.severity()); + + RulesDefinition.Param checkCatchParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_CATCH); + assertEquals(RuleParamType.BOOLEAN, checkCatchParam.type()); + assertEquals("true", checkCatchParam.defaultValue()); + + RulesDefinition.Param checkElseParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_ELSE); + assertEquals(RuleParamType.BOOLEAN, checkElseParam.type()); + assertEquals("true", checkElseParam.defaultValue()); + + RulesDefinition.Param checkOpenBraceParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_OPEN_BRACE); + assertEquals(RuleParamType.BOOLEAN, checkOpenBraceParam.type()); + assertEquals("true", checkOpenBraceParam.defaultValue()); + + RulesDefinition.Param checkWhitespaceParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_WHITESPACE); + assertEquals(RuleParamType.BOOLEAN, checkWhitespaceParam.type()); + assertEquals("true", checkWhitespaceParam.defaultValue()); + } + + @Test + public void ConfiguresQuoteMarkRule() { + Rule rule = getRule(TsRulesDefinition.RULE_QUOTEMARK); + assertEquals(Severity.MAJOR, rule.severity()); + + RulesDefinition.Param checkCatchParam = getParam(rule, TsRulesDefinition.RULE_PARAM_QUOTE_MARK); + assertEquals(2, checkCatchParam.type().values().size()); + assertTrue(checkCatchParam.type().values().contains("single")); + assertTrue(checkCatchParam.type().values().contains("double")); + assertEquals("double", checkCatchParam.defaultValue()); + } + + @Test + public void ConfiguresRadixRule() { + Rule rule = getRule(TsRulesDefinition.RULE_RADIX); + assertEquals(Severity.CRITICAL, rule.severity()); + } + + @Test + public void ConfiguresSemicolonRule() { + Rule rule = getRule(TsRulesDefinition.RULE_SEMICOLON); + assertEquals(Severity.MAJOR, rule.severity()); + } + + @Test + public void ConfiguresTypedefRule() { + Rule rule = getRule(TsRulesDefinition.RULE_TYPEDEF); + assertEquals(Severity.MAJOR, rule.severity()); + + RulesDefinition.Param callSignatureParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CALL_SIGNATURE); + assertEquals(RuleParamType.BOOLEAN, callSignatureParam.type()); + assertEquals("true", callSignatureParam.defaultValue()); + + RulesDefinition.Param paramIndexSignatureParam = getParam(rule, TsRulesDefinition.RULE_PARAM_INDEX_SIGNATURE); + assertEquals(RuleParamType.BOOLEAN, paramIndexSignatureParam.type()); + assertEquals("true", paramIndexSignatureParam.defaultValue()); + + RulesDefinition.Param parameterParam = getParam(rule, TsRulesDefinition.RULE_PARAM_PARAMETER); + assertEquals(RuleParamType.BOOLEAN, parameterParam.type()); + assertEquals("true", parameterParam.defaultValue()); + RulesDefinition.Param propertySignatureParam = getParam(rule, TsRulesDefinition.RULE_PARAM_PROPERTY_SIGNATURE); + assertEquals(RuleParamType.BOOLEAN, propertySignatureParam.type()); + assertEquals("true", propertySignatureParam.defaultValue()); + + RulesDefinition.Param variableDeclaratorParam = getParam(rule, TsRulesDefinition.RULE_PARAM_VARIABLE_DECLARATOR); + assertEquals(RuleParamType.BOOLEAN, variableDeclaratorParam.type()); + assertEquals("true", variableDeclaratorParam.defaultValue()); + + RulesDefinition.Param memberVariableDeclaratorParam = getParam(rule, TsRulesDefinition.RULE_PARAM_MEMBER_VARIABLE_DECLARACTOR); + assertEquals(RuleParamType.BOOLEAN, memberVariableDeclaratorParam.type()); + assertEquals("true", memberVariableDeclaratorParam.defaultValue()); + } + + @Test + public void ConfiguresTypedefWhitespaceRule() { + Rule rule = getRule(TsRulesDefinition.RULE_TYPEDEF_WHITESPACE); + assertEquals(Severity.MINOR, rule.severity()); + + RulesDefinition.Param callSignatureParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CALL_SIGNATURE); + assertEquals(2, callSignatureParam.type().values().size()); + assertTrue(callSignatureParam.type().values().contains("space")); + assertTrue(callSignatureParam.type().values().contains("noSpace")); + assertEquals("noSpace", callSignatureParam.defaultValue()); + + RulesDefinition.Param catchClauseParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CATCH_CLAUSE); + assertEquals(2, catchClauseParam.type().values().size()); + assertTrue(catchClauseParam.type().values().contains("space")); + assertTrue(catchClauseParam.type().values().contains("noSpace")); + assertEquals("noSpace", catchClauseParam.defaultValue()); + + RulesDefinition.Param indexSignatureParam = getParam(rule, TsRulesDefinition.RULE_PARAM_INDEX_SIGNATURE); + assertEquals(2, indexSignatureParam.type().values().size()); + assertTrue(indexSignatureParam.type().values().contains("space")); + assertTrue(indexSignatureParam.type().values().contains("noSpace")); + assertEquals("space", indexSignatureParam.defaultValue()); + } + + @Test + public void ConfiguresUseStrictRule() { + Rule rule = getRule(TsRulesDefinition.RULE_USE_STRICT); + assertEquals(Severity.CRITICAL, rule.severity()); + + RulesDefinition.Param checkModuleParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_MODULE); + assertEquals(RuleParamType.BOOLEAN, checkModuleParam.type()); + assertEquals("true", checkModuleParam.defaultValue()); + + RulesDefinition.Param checkFunctionParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_FUNCTION); + assertEquals(RuleParamType.BOOLEAN, checkFunctionParam.type()); + assertEquals("true", checkFunctionParam.defaultValue()); + } + + @Test + public void ConfiguresVariableNameRule() { + Rule rule = getRule(TsRulesDefinition.RULE_VARIABLE_NAME); + assertEquals(Severity.MAJOR, rule.severity()); + + RulesDefinition.Param allowLeadingUnderscoreParam = getParam(rule, TsRulesDefinition.RULE_PARAM_ALLOW_LEADING_UNDERSCORE); + assertEquals(RuleParamType.BOOLEAN, allowLeadingUnderscoreParam.type()); + assertEquals("true", allowLeadingUnderscoreParam.defaultValue()); + } + + @Test + public void ConfiguresWhitespaceRule() { + Rule rule = getRule(TsRulesDefinition.RULE_WHITESPACE); + assertEquals(Severity.MINOR, rule.severity()); + + RulesDefinition.Param checkBranchParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_BRANCH); + assertEquals(RuleParamType.BOOLEAN, checkBranchParam.type()); + assertEquals("true", checkBranchParam.defaultValue()); + + RulesDefinition.Param checkDeclParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_DECL); + assertEquals(RuleParamType.BOOLEAN, checkDeclParam.type()); + assertEquals("true", checkDeclParam.defaultValue()); + + RulesDefinition.Param checkOperatorParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_OPERATOR); + assertEquals(RuleParamType.BOOLEAN, checkOperatorParam.type()); + assertEquals("true", checkOperatorParam.defaultValue()); + + RulesDefinition.Param checkSeparatorParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_SEPARATOR); + assertEquals(RuleParamType.BOOLEAN, checkSeparatorParam.type()); + assertEquals("true", checkSeparatorParam.defaultValue()); + + RulesDefinition.Param checkTypeParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_TYPE); + assertEquals(RuleParamType.BOOLEAN, checkTypeParam.type()); + assertEquals("true", checkTypeParam.defaultValue()); + + RulesDefinition.Param checkTypeCastParam = getParam(rule, TsRulesDefinition.RULE_PARAM_CHECK_TYPECAST); + assertEquals(RuleParamType.BOOLEAN, checkTypeCastParam.type()); + assertEquals("true", checkTypeCastParam.defaultValue()); + } + private Rule getRule(String name) { this.definition.define(context); return this.context.repository(TsRulesDefinition.REPOSITORY_NAME).rule(name);