From 90acdfa6cbf9e0c2388fbdd732aeaabe0a34f238 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Tue, 17 Jan 2017 21:47:54 +0530 Subject: [PATCH] refactor(ES6): compareLocations.test.js --- test/compareLocations.test.js | 133 +++++++++++++++------------------- 1 file changed, 59 insertions(+), 74 deletions(-) diff --git a/test/compareLocations.test.js b/test/compareLocations.test.js index 5dff9fa58..de7ad605f 100644 --- a/test/compareLocations.test.js +++ b/test/compareLocations.test.js @@ -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', function() { - compareLocations('beta', 'alpha').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', function() { - compareLocations('charlie', 'charlie').should.be.exactly(0); - }); + it("returns 0 when the first string is the same as the second string", () => + compareLocations("charlie", "charlie").should.be.exactly(0)); }); - describe('object location comparison', function() { - var a, b; + describe("object location comparison", () => { + let 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', 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('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', function() { - compareLocations(b, a).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)); }); - 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', function() { - compareLocations(b, a).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)); }); - 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', function() { - compareLocations(createLocation(), 'alpha').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)); }); - 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); - }); + 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)); - 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 undefined when the first parameter is a number and the second parameter is an object", () => + should(compareLocations(123, createLocation())).be.undefined()); - 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 0 when the first parameter is a string and the second parameter is a number", () => + compareLocations("alpha", 123).should.be.exactly(0)); - 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 the first parameter is a number and the second parameter is a string", () => + 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(); - }); }); });