{"size": 2482, "ext": "js", "max_stars_repo_path": "tests/lib/rules/no-ternary.js", "max_stars_repo_name": "brianloveswords/eslint", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/lib/rules/no-ternary.js", "max_issues_repo_name": "brianloveswords/eslint", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/lib/rules/no-ternary.js", "max_forks_repo_name": "brianloveswords/eslint", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.8205128205, "max_line_length": 80, "alphanum_fraction": 0.4621273167}
/**
 * @fileoverview Tests for no-ternary.
 * @author Ian Christian Myers
 */

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var vows = require("vows"),
    assert = require("assert"),
    eslint = require("../../../lib/eslint");

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------

var RULE_ID = "no-ternary";

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

vows.describe(RULE_ID).addBatch({

    "when evaluating ternary assignment": {

        topic: "var foo = true ? thing : stuff;",

        "should report a violation": function(topic) {

            var config = { rules: {} };
            config.rules[RULE_ID] = 1;

            var messages = eslint.verify(topic, config);
            assert.equal(messages.length, 1);
            assert.equal(messages[0].ruleId, RULE_ID);
            assert.equal(messages[0].message, "Ternary operator used.");
            assert.include(messages[0].node.type, "ConditionalExpression");
        }
    },

    "when evaluating ternary function call": {

        topic: "true ? thing() : stuff();",

        "should report a violation": function(topic) {

            var config = { rules: {} };
            config.rules[RULE_ID] = 1;

            var messages = eslint.verify(topic, config);
            assert.equal(messages.length, 1);
            assert.equal(messages[0].ruleId, RULE_ID);
            assert.equal(messages[0].message, "Ternary operator used.");
            assert.include(messages[0].node.type, "ConditionalExpression");
        }
    },

    "when evaluating ternary return statement": {

        topic: "function foo(bar) { return bar ? baz : qux; }",

        "should report a violation": function(topic) {

            var config = { rules: {} };
            config.rules[RULE_ID] = 1;

            var messages = eslint.verify(topic, config);
            assert.equal(messages.length, 1);
            assert.equal(messages[0].ruleId, RULE_ID);
            assert.equal(messages[0].message, "Ternary operator used.");
            assert.include(messages[0].node.type, "ConditionalExpression");
        }
    }

}).export(module);
