Merge pull request #4057 from shubheksha/refactor-test-compareLocations

refactor(ES6): compareLocations.test.js
This commit is contained in:
Sean Larkin 2017-01-21 10:03:05 -06:00 committed by GitHub
commit a01eeb6af0
1 changed files with 59 additions and 74 deletions

View File

@ -1,6 +1,8 @@
var should = require("should"); "use strict";
var compareLocations = require("../lib/compareLocations");
var createLocation = function(overides) { const should = require("should");
const compareLocations = require("../lib/compareLocations");
const createLocation = function(overides) {
return Object.assign({ return Object.assign({
line: 10, line: 10,
column: 5, column: 5,
@ -8,26 +10,23 @@ var createLocation = function(overides) {
}, overides); }, overides);
}; };
describe('compareLocations', function() { describe("compareLocations", () => {
describe('string location comparison', function() { describe("string location comparison", () => {
it('returns -1 when the first string comes before the second string', function() { it("returns -1 when the first string comes before the second string", () =>
compareLocations('alpha', 'beta').should.be.exactly(-1); compareLocations("alpha", "beta").should.be.exactly(-1));
it("returns 1 when the first string comes after the second string", () =>
compareLocations("beta", "alpha").should.be.exactly(1));
it("returns 0 when the first string is the same as the second string", () =>
compareLocations("charlie", "charlie").should.be.exactly(0));
}); });
it('returns 1 when the first string comes after the second string', function() { describe("object location comparison", () => {
compareLocations('beta', 'alpha').should.be.exactly(1); let a, b;
});
it('returns 0 when the first string is the same as the second string', function() { describe("location line number", () => {
compareLocations('charlie', 'charlie').should.be.exactly(0); beforeEach(() => {
});
});
describe('object location comparison', function() {
var a, b;
describe('location line number', function() {
beforeEach(function() {
a = createLocation({ a = createLocation({
line: 10 line: 10
}); });
@ -36,17 +35,15 @@ describe('compareLocations', function() {
}); });
}); });
it('returns -1 when the first location line number comes before the second location line number', function() { it("returns -1 when the first location line number comes before the second location line number", () =>
compareLocations(a, b).should.be.exactly(-1); compareLocations(a, b).should.be.exactly(-1));
it("returns 1 when the first location line number comes after the second location line number", () =>
compareLocations(b, a).should.be.exactly(1));
}); });
it('returns 1 when the first location line number comes after the second location line number', function() { describe("location column number", () => {
compareLocations(b, a).should.be.exactly(1); beforeEach(() => {
});
});
describe('location column number', function() {
beforeEach(function() {
a = createLocation({ a = createLocation({
column: 10 column: 10
}); });
@ -55,17 +52,15 @@ describe('compareLocations', function() {
}); });
}); });
it('returns -1 when the first location column number comes before the second location column number', function() { it("returns -1 when the first location column number comes before the second location column number", () =>
compareLocations(a, b).should.be.exactly(-1); compareLocations(a, b).should.be.exactly(-1));
it("returns 1 when the first location column number comes after the second location column number", () =>
compareLocations(b, a).should.be.exactly(1));
}); });
it('returns 1 when the first location column number comes after the second location column number', function() { describe("location index number", () => {
compareLocations(b, a).should.be.exactly(1); beforeEach(() => {
});
});
describe('location index number', function() {
beforeEach(function() {
a = createLocation({ a = createLocation({
index: 10 index: 10
}); });
@ -74,28 +69,26 @@ describe('compareLocations', function() {
}); });
}); });
it('returns -1 when the first location index number comes before the second location index number', function() { it("returns -1 when the first location index number comes before the second location index number", () =>
compareLocations(a, b).should.be.exactly(-1); compareLocations(a, b).should.be.exactly(-1));
it("returns 1 when the first location index number comes after the second location index number", () =>
compareLocations(b, a).should.be.exactly(1));
}); });
it('returns 1 when the first location index number comes after the second location index number', function() { describe("same location", () => {
compareLocations(b, a).should.be.exactly(1); beforeEach(() => {
});
});
describe('same location', function() {
beforeEach(function() {
a = createLocation(); a = createLocation();
b = createLocation(); b = createLocation();
}); });
it('returns 0', function() { it("returns 0", () => {
compareLocations(a, b).should.be.exactly(0); compareLocations(a, b).should.be.exactly(0);
}); });
}); });
describe('start location set', function() { describe("start location set", () => {
beforeEach(function() { beforeEach(() => {
a = { a = {
start: createLocation({ start: createLocation({
line: 10 line: 10
@ -108,45 +101,37 @@ describe('compareLocations', function() {
}; };
}); });
it('returns -1 when the first location line number comes before the second location line number', function() { it("returns -1 when the first location line number comes before the second location line number", () =>
compareLocations(a, b).should.be.exactly(-1); compareLocations(a, b).should.be.exactly(-1));
});
it('returns 1 when the first location line number comes after the second location line number', function() { it("returns 1 when the first location line number comes after the second location line number", () =>
compareLocations(b, a).should.be.exactly(1); compareLocations(b, a).should.be.exactly(1));
});
}); });
}); });
describe('string and object location comparison', function() { describe("string and object location comparison", () => {
it('returns 1 when the first parameter is a string and the second parameter is an object', function() { it("returns 1 when the first parameter is a string and the second parameter is an object", () =>
compareLocations('alpha', createLocation()).should.be.exactly(1); compareLocations("alpha", createLocation()).should.be.exactly(1));
it("returns -1 when the first parameter is an object and the second parameter is a string", () =>
compareLocations(createLocation(), "alpha").should.be.exactly(-1));
}); });
it('returns -1 when the first parameter is an object and the second parameter is a string', function() { describe("unknown location type comparison", () => {
compareLocations(createLocation(), 'alpha').should.be.exactly(-1); it("returns 0 when the first parameter is an object and the second parameter is a number", () =>
}); compareLocations(createLocation(), 123).should.be.exactly(0));
});
describe('unknown location type comparison', function() { it("returns undefined when the first parameter is a number and the second parameter is an object", () =>
it('returns 0 when the first parameter is an object and the second parameter is a number', function() { should(compareLocations(123, createLocation())).be.undefined());
compareLocations(createLocation(), 123).should.be.exactly(0);
});
it('returns undefined when the first parameter is a number and the second parameter is an object', function() { it("returns 0 when the first parameter is a string and the second parameter is a number", () =>
should(compareLocations(123, createLocation())).be.undefined(); compareLocations("alpha", 123).should.be.exactly(0));
});
it('returns 0 when the first parameter is a string and the second parameter is a number', function() { it("returns undefined when the first parameter is a number and the second parameter is a string", () =>
compareLocations('alpha', 123).should.be.exactly(0); should(compareLocations(123, "alpha")).be.undefined());
});
it('returns undefined when the first parameter is a number and the second parameter is a string', function() { it("returns undefined when both the first parameter and the second parameter is a number", () =>
should(compareLocations(123, 'alpha')).be.undefined(); should(compareLocations(123, 456)).be.undefined());
});
it('returns undefined when both the first parameter and the second parameter is a number', function() {
should(compareLocations(123, 456)).be.undefined();
});
}); });
}); });