/**
* @fileoverview Tests for checkstyle reporter.
* @author Ian Christian Myers
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("chai").assert,
formatter = require("../../../../lib/cli-engine/formatters/checkstyle");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("formatter:checkstyle", () => {
describe("when passed a single message", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 2,
line: 5,
column: 10,
ruleId: "foo"
}]
}];
it("should return a string in the format filename: line x, col y, Error - z for errors", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
it("should return a string in the format filename: line x, col y, Warning - z for warnings", () => {
code[0].messages[0].severity = 1;
const result = formatter(code);
assert.strictEqual(result, "");
});
});
describe("when passed a message with XML control characters", () => {
const code = [{
filePath: "<>&\"'.js",
messages: [{
fatal: true,
message: "Unexpected <>&\"'\b\t\n\f\r牛逼.",
line: "<",
column: ">",
ruleId: "foo"
}]
}];
it("should return a string in the format filename: line x, col y, Error - z", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
});
describe("when passed a fatal error message", () => {
const code = [{
filePath: "foo.js",
messages: [{
fatal: true,
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}];
it("should return a string in the format filename: line x, col y, Error - z", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
});
describe("when passed multiple messages", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 2,
line: 5,
column: 10,
ruleId: "foo"
}, {
message: "Unexpected bar.",
severity: 1,
line: 6,
column: 11,
ruleId: "bar"
}]
}];
it("should return a string with multiple entries", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
});
describe("when passed multiple files with 1 message each", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 2,
line: 5,
column: 10,
ruleId: "foo"
}]
}, {
filePath: "bar.js",
messages: [{
message: "Unexpected bar.",
severity: 1,
line: 6,
column: 11,
ruleId: "bar"
}]
}];
it("should return a string with multiple entries", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
});
describe("when passing single message without rule id", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 2,
line: 5,
column: 10
}]
}];
it("should return a string in the format filename: line x, col y, Error - z for errors", () => {
const result = formatter(code);
assert.strictEqual(result, "");
});
});
});