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");
var compareLocations = require("../lib/compareLocations");
var createLocation = function(overides) {
"use strict";
const should = require("should");
const compareLocations = require("../lib/compareLocations");
const createLocation = function(overides) {
return Object.assign({
line: 10,
column: 5,
@ -8,26 +10,23 @@ var createLocation = function(overides) {
}, overides);
};
describe('compareLocations', function() {
describe('string location comparison', function() {
it('returns -1 when the first string comes before the second string', function() {
compareLocations('alpha', 'beta').should.be.exactly(-1);
describe("compareLocations", () => {
describe("string location comparison", () => {
it("returns -1 when the first string comes before the second string", () =>
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() {
compareLocations('beta', 'alpha').should.be.exactly(1);
});
describe("object location comparison", () => {
let a, b;
it('returns 0 when the first string is the same as the second string', function() {
compareLocations('charlie', 'charlie').should.be.exactly(0);
});
});
describe('object location comparison', function() {
var a, b;
describe('location line number', function() {
beforeEach(function() {
describe("location line number", () => {
beforeEach(() => {
a = createLocation({
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() {
compareLocations(a, b).should.be.exactly(-1);
it("returns -1 when the first location line number comes before the second location line number", () =>
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() {
compareLocations(b, a).should.be.exactly(1);
});
});
describe('location column number', function() {
beforeEach(function() {
describe("location column number", () => {
beforeEach(() => {
a = createLocation({
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() {
compareLocations(a, b).should.be.exactly(-1);
it("returns -1 when the first location column number comes before the second location column number", () =>
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() {
compareLocations(b, a).should.be.exactly(1);
});
});
describe('location index number', function() {
beforeEach(function() {
describe("location index number", () => {
beforeEach(() => {
a = createLocation({
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() {
compareLocations(a, b).should.be.exactly(-1);
it("returns -1 when the first location index number comes before the second location index number", () =>
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() {
compareLocations(b, a).should.be.exactly(1);
});
});
describe('same location', function() {
beforeEach(function() {
describe("same location", () => {
beforeEach(() => {
a = createLocation();
b = createLocation();
});
it('returns 0', function() {
it("returns 0", () => {
compareLocations(a, b).should.be.exactly(0);
});
});
describe('start location set', function() {
beforeEach(function() {
describe("start location set", () => {
beforeEach(() => {
a = {
start: createLocation({
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() {
compareLocations(a, b).should.be.exactly(-1);
});
it("returns -1 when the first location line number comes before the second location line number", () =>
compareLocations(a, b).should.be.exactly(-1));
it('returns 1 when the first location line number comes after the second location line number', function() {
compareLocations(b, a).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));
});
});
describe('string and object location comparison', function() {
it('returns 1 when the first parameter is a string and the second parameter is an object', function() {
compareLocations('alpha', createLocation()).should.be.exactly(1);
describe("string and object location comparison", () => {
it("returns 1 when the first parameter is a string and the second parameter is an object", () =>
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() {
compareLocations(createLocation(), 'alpha').should.be.exactly(-1);
});
});
describe("unknown location type comparison", () => {
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 0 when the first parameter is an object and the second parameter is a number', function() {
compareLocations(createLocation(), 123).should.be.exactly(0);
});
it("returns undefined when the first parameter is a number and the second parameter is an object", () =>
should(compareLocations(123, createLocation())).be.undefined());
it('returns undefined when the first parameter is a number and the second parameter is an object', function() {
should(compareLocations(123, createLocation())).be.undefined();
});
it("returns 0 when the first parameter is a string and the second parameter is a number", () =>
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() {
compareLocations('alpha', 123).should.be.exactly(0);
});
it("returns undefined when the first parameter is a number and the second parameter is a string", () =>
should(compareLocations(123, "alpha")).be.undefined());
it('returns undefined when the first parameter is a number and the second parameter is a string', function() {
should(compareLocations(123, 'alpha')).be.undefined();
});
it("returns undefined when both the first parameter and the second parameter is a number", () =>
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();
});
});
});