22
33const should = require ( "should" ) ;
44const compareLocations = require ( "../lib/compareLocations" ) ;
5- const createLocation = function ( overides ) {
5+ const createPosition = function ( overides ) {
66 return Object . assign ( {
77 line : 10 ,
8- column : 5 ,
9- index : 3
8+ column : 5
109 } , overides ) ;
1110} ;
1211
12+ const createLocation = function ( start , end , index ) {
13+ return {
14+ start : createPosition ( start ) ,
15+ end : createPosition ( end ) ,
16+ index : index || 3
17+ } ;
18+ } ;
19+
1320describe ( "compareLocations" , ( ) => {
1421 describe ( "string location comparison" , ( ) => {
1522 it ( "returns -1 when the first string comes before the second string" , ( ) =>
@@ -35,8 +42,9 @@ describe("compareLocations", () => {
3542 } ) ;
3643 } ) ;
3744
38- it ( "returns -1 when the first location line number comes before the second location line number" , ( ) =>
39- compareLocations ( a , b ) . should . be . exactly ( - 1 ) ) ;
45+ it ( "returns -1 when the first location line number comes before the second location line number" , ( ) => {
46+ return compareLocations ( a , b ) . should . be . exactly ( - 1 )
47+ } ) ;
4048
4149 it ( "returns 1 when the first location line number comes after the second location line number" , ( ) =>
4250 compareLocations ( b , a ) . should . be . exactly ( 1 ) ) ;
@@ -61,12 +69,8 @@ describe("compareLocations", () => {
6169
6270 describe ( "location index number" , ( ) => {
6371 beforeEach ( ( ) => {
64- a = createLocation ( {
65- index : 10
66- } ) ;
67- b = createLocation ( {
68- index : 20
69- } ) ;
72+ a = createLocation ( null , null , 10 ) ;
73+ b = createLocation ( null , null , 20 ) ;
7074 } ) ;
7175
7276 it ( "returns -1 when the first location index number comes before the second location index number" , ( ) =>
@@ -86,27 +90,6 @@ describe("compareLocations", () => {
8690 compareLocations ( a , b ) . should . be . exactly ( 0 ) ;
8791 } ) ;
8892 } ) ;
89-
90- describe ( "start location set" , ( ) => {
91- beforeEach ( ( ) => {
92- a = {
93- start : createLocation ( {
94- line : 10
95- } )
96- } ;
97- b = {
98- start : createLocation ( {
99- line : 20
100- } )
101- } ;
102- } ) ;
103-
104- it ( "returns -1 when the first location line number comes before the second location line number" , ( ) =>
105- compareLocations ( a , b ) . should . be . exactly ( - 1 ) ) ;
106-
107- it ( "returns 1 when the first location line number comes after the second location line number" , ( ) =>
108- compareLocations ( b , a ) . should . be . exactly ( 1 ) ) ;
109- } ) ;
11093 } ) ;
11194
11295 describe ( "string and object location comparison" , ( ) => {
0 commit comments