2c0ef5fe30f75c757fbaf7a64f1e21658b5c3c5ef9051a22ab36f093f70c072203657028bbbbcb19df8ab686bd6987b0594094da9dc729d855e054bee7d772 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. describe('Walkontable.CellRange', function () {
  2. describe('getAll', function () {
  3. it('should get all cells in range', function () {
  4. var from = new Walkontable.CellCoords(1, 1);
  5. var to = new Walkontable.CellCoords(3, 3);
  6. var range = new Walkontable.CellRange(from, from, to);
  7. var all = range.getAll();
  8. expect(all.length).toBe(9);
  9. expect(all[0].row).toBe(from.row);
  10. expect(all[0].col).toBe(from.col);
  11. expect(all[1].row).toBe(1);
  12. expect(all[1].col).toBe(2);
  13. expect(all[8].row).toBe(to.row);
  14. expect(all[8].col).toBe(to.col);
  15. });
  16. it('should get all cells in range (reverse order)', function () {
  17. var from = new Walkontable.CellCoords(3, 3);
  18. var to = new Walkontable.CellCoords(1, 1);
  19. var range = new Walkontable.CellRange(from, from, to);
  20. var all = range.getAll();
  21. expect(all.length).toBe(9);
  22. expect(all[0].row).toBe(to.row);
  23. expect(all[0].col).toBe(to.col);
  24. expect(all[1].row).toBe(1);
  25. expect(all[1].col).toBe(2);
  26. expect(all[8].row).toBe(from.row);
  27. expect(all[8].col).toBe(from.col);
  28. });
  29. });
  30. describe('getInner', function () {
  31. it('should get cells in range excluding from and to', function () {
  32. var from = new Walkontable.CellCoords(1, 1);
  33. var to = new Walkontable.CellCoords(3, 3);
  34. var range = new Walkontable.CellRange(from, from, to);
  35. var inner = range.getInner();
  36. expect(inner.length).toBe(7);
  37. expect(inner[1].row).toBe(1);
  38. expect(inner[1].col).toBe(3);
  39. });
  40. it('should get cells in range excluding from and to (reverse order)', function () {
  41. var from = new Walkontable.CellCoords(3, 3);
  42. var to = new Walkontable.CellCoords(1, 1);
  43. var range = new Walkontable.CellRange(from, from, to);
  44. var inner = range.getInner();
  45. expect(inner.length).toBe(7);
  46. expect(inner[1].row).toBe(1);
  47. expect(inner[1].col).toBe(3);
  48. });
  49. });
  50. describe('includes', function () {
  51. it('should return true if range is a single cell and the same cell is given', function () {
  52. var from = new Walkontable.CellCoords(0, 0);
  53. var to = new Walkontable.CellCoords(0, 0);
  54. var range = new Walkontable.CellRange(from, from, to);
  55. expect(range.includes(new Walkontable.CellCoords(0, 0))).toBe(true);
  56. });
  57. it('should return true if given cell is within the range', function () {
  58. var from = new Walkontable.CellCoords(1, 1);
  59. var to = new Walkontable.CellCoords(3, 3);
  60. var range = new Walkontable.CellRange(from, from, to);
  61. expect(range.includes(new Walkontable.CellCoords(1, 1))).toBe(true);
  62. expect(range.includes(new Walkontable.CellCoords(3, 1))).toBe(true);
  63. expect(range.includes(new Walkontable.CellCoords(3, 3))).toBe(true);
  64. expect(range.includes(new Walkontable.CellCoords(1, 3))).toBe(true);
  65. expect(range.includes(new Walkontable.CellCoords(2, 2))).toBe(true);
  66. expect(range.includes(new Walkontable.CellCoords(1, 2))).toBe(true);
  67. expect(range.includes(new Walkontable.CellCoords(2, 1))).toBe(true);
  68. });
  69. it('should return false if given cell outside the range', function () {
  70. var from = new Walkontable.CellCoords(1, 1);
  71. var to = new Walkontable.CellCoords(3, 3);
  72. var range = new Walkontable.CellRange(from, from, to);
  73. expect(range.includes(new Walkontable.CellCoords(0, 0))).toBe(false);
  74. expect(range.includes(new Walkontable.CellCoords(4, 4))).toBe(false);
  75. expect(range.includes(new Walkontable.CellCoords(1, 4))).toBe(false);
  76. expect(range.includes(new Walkontable.CellCoords(4, 1))).toBe(false);
  77. expect(range.includes(new Walkontable.CellCoords(-1, -1))).toBe(false);
  78. });
  79. });
  80. describe('includesRange', function () {
  81. describe('B has more than one cell', function () {
  82. /*
  83. +----------+
  84. | a |
  85. | +------+ |
  86. | | b | |
  87. | | | |
  88. | +------+ |
  89. +----------+
  90. */
  91. it('B is included in A, none of borders touch each other', function () {
  92. var aTopLeft = new Walkontable.CellCoords(0, 0);
  93. var aBottomRight = new Walkontable.CellCoords(5, 5);
  94. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  95. var bTopLeft = new Walkontable.CellCoords(1, 1);
  96. var bBottomRight = new Walkontable.CellCoords(4, 4);
  97. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  98. expect(a.includesRange(b)).toBe(true);
  99. });
  100. /*
  101. +----------+
  102. | b |
  103. | +------+ |
  104. | | a | |
  105. | | | |
  106. | +------+ |
  107. +----------+
  108. */
  109. it('A is included in B, none of borders touch each other', function () {
  110. var aTopLeft = new Walkontable.CellCoords(1, 1);
  111. var aBottomRight = new Walkontable.CellCoords(4, 4);
  112. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  113. var bTopLeft = new Walkontable.CellCoords(0, 0);
  114. var bBottomRight = new Walkontable.CellCoords(5, 4);
  115. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  116. expect(a.includesRange(b)).toBe(false);
  117. });
  118. /*
  119. +-----------+
  120. | a | b | |
  121. | | | |
  122. | +-----+ |
  123. +-----------+
  124. */
  125. it('B is included in A, top borders touch', function () {
  126. var aTopLeft = new Walkontable.CellCoords(0, 0);
  127. var aBottomRight = new Walkontable.CellCoords(5, 5);
  128. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  129. var bTopLeft = new Walkontable.CellCoords(0, 1);
  130. var bBottomRight = new Walkontable.CellCoords(4, 4);
  131. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  132. expect(a.includesRange(b)).toBe(true);
  133. });
  134. /*
  135. +---------+
  136. | a | b |
  137. | | |
  138. | +-----|
  139. | |
  140. +---------+
  141. */
  142. it('B is included in A, top and right borders touch', function () {
  143. var aTopLeft = new Walkontable.CellCoords(0, 0);
  144. var aBottomRight = new Walkontable.CellCoords(5, 5);
  145. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  146. var bTopLeft = new Walkontable.CellCoords(0, 1);
  147. var bBottomRight = new Walkontable.CellCoords(4, 5);
  148. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  149. expect(a.includesRange(b)).toBe(true);
  150. });
  151. /*
  152. +---------+
  153. | +-----|
  154. | a | b |
  155. | | |
  156. | +-----|
  157. +---------+
  158. */
  159. it('B is included in A, right borders touch', function () {
  160. var aTopLeft = new Walkontable.CellCoords(0, 0);
  161. var aBottomRight = new Walkontable.CellCoords(5, 5);
  162. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  163. var bTopLeft = new Walkontable.CellCoords(1, 1);
  164. var bBottomRight = new Walkontable.CellCoords(4, 5);
  165. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  166. expect(a.includesRange(b)).toBe(true);
  167. });
  168. /*
  169. +---------+
  170. | +-----|
  171. | a | b |
  172. | | |
  173. +---------+
  174. */
  175. it('B is included in A, bottom and right borders touch', function () {
  176. var aTopLeft = new Walkontable.CellCoords(0, 0);
  177. var aBottomRight = new Walkontable.CellCoords(5, 5);
  178. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  179. var bTopLeft = new Walkontable.CellCoords(1, 1);
  180. var bBottomRight = new Walkontable.CellCoords(5, 5);
  181. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  182. expect(a.includesRange(b)).toBe(true);
  183. });
  184. /*
  185. +-----------+
  186. | +-----+ |
  187. | a | b | |
  188. | | | |
  189. +-----------+
  190. */
  191. it('B is included in A, bottom borders touch', function () {
  192. var aTopLeft = new Walkontable.CellCoords(0, 0);
  193. var aBottomRight = new Walkontable.CellCoords(5, 5);
  194. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  195. var bTopLeft = new Walkontable.CellCoords(1, 1);
  196. var bBottomRight = new Walkontable.CellCoords(5, 4);
  197. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  198. expect(a.includesRange(b)).toBe(true);
  199. });
  200. /*
  201. +-----------+
  202. |-----+ a |
  203. | b | |
  204. | | |
  205. +-----------+
  206. */
  207. it('B is included in A, bottom and left borders touch', function () {
  208. var aTopLeft = new Walkontable.CellCoords(0, 0);
  209. var aBottomRight = new Walkontable.CellCoords(5, 5);
  210. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  211. var bTopLeft = new Walkontable.CellCoords(1, 0);
  212. var bBottomRight = new Walkontable.CellCoords(5, 4);
  213. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  214. expect(a.includesRange(b)).toBe(true);
  215. });
  216. /*
  217. +-----------+
  218. |-----+ a |
  219. | b | |
  220. | | |
  221. |-----+ |
  222. +-----------+
  223. */
  224. it('B is included in A, left borders touch', function () {
  225. var aTopLeft = new Walkontable.CellCoords(0, 0);
  226. var aBottomRight = new Walkontable.CellCoords(5, 5);
  227. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  228. var bTopLeft = new Walkontable.CellCoords(1, 0);
  229. var bBottomRight = new Walkontable.CellCoords(4, 4);
  230. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  231. expect(a.includesRange(b)).toBe(true);
  232. });
  233. /*
  234. +-----------+
  235. | b | a |
  236. | | |
  237. |-----+ |
  238. +-----------+
  239. */
  240. it('B is included in A, top and left borders touch', function () {
  241. var aTopLeft = new Walkontable.CellCoords(0, 0);
  242. var aBottomRight = new Walkontable.CellCoords(5, 5);
  243. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  244. var bTopLeft = new Walkontable.CellCoords(0, 0);
  245. var bBottomRight = new Walkontable.CellCoords(4, 4);
  246. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  247. expect(a.includesRange(b)).toBe(true);
  248. });
  249. /*
  250. +------------+
  251. | a | b | |
  252. | | | |
  253. +------------+
  254. */
  255. it('B is included in A, top and bottom borders touch', function () {
  256. var aTopLeft = new Walkontable.CellCoords(0, 0);
  257. var aBottomRight = new Walkontable.CellCoords(5, 5);
  258. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  259. var bTopLeft = new Walkontable.CellCoords(0, 1);
  260. var bBottomRight = new Walkontable.CellCoords(5, 4);
  261. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  262. expect(a.includesRange(b)).toBe(true);
  263. });
  264. /*
  265. +----------+
  266. | a | b |
  267. | | |
  268. +----------+
  269. */
  270. it('B is included in A, top, right and bottom borders touch', function () {
  271. var aTopLeft = new Walkontable.CellCoords(0, 0);
  272. var aBottomRight = new Walkontable.CellCoords(5, 5);
  273. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  274. var bTopLeft = new Walkontable.CellCoords(0, 1);
  275. var bBottomRight = new Walkontable.CellCoords(5, 5);
  276. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  277. expect(a.includesRange(b)).toBe(true);
  278. });
  279. /*
  280. +----------+
  281. | b | a |
  282. | | |
  283. +----------+
  284. */
  285. it('B is included in A, top, left and bottom borders touch', function () {
  286. var aTopLeft = new Walkontable.CellCoords(0, 0);
  287. var aBottomRight = new Walkontable.CellCoords(5, 5);
  288. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  289. var bTopLeft = new Walkontable.CellCoords(0, 0);
  290. var bBottomRight = new Walkontable.CellCoords(5, 4);
  291. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  292. expect(a.includesRange(b)).toBe(true);
  293. });
  294. /*
  295. +----------+
  296. | a |
  297. |----------|
  298. | b |
  299. |----------|
  300. +----------+
  301. */
  302. it('B is included in A, left and right borders touch', function () {
  303. var aTopLeft = new Walkontable.CellCoords(0, 0);
  304. var aBottomRight = new Walkontable.CellCoords(5, 5);
  305. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  306. var bTopLeft = new Walkontable.CellCoords(1, 0);
  307. var bBottomRight = new Walkontable.CellCoords(4, 5);
  308. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  309. expect(a.includesRange(b)).toBe(true);
  310. });
  311. /*
  312. +----------+
  313. | a |
  314. |----------|
  315. | b |
  316. +----------+
  317. */
  318. it('B is included in A, left, bottom and right borders touch', function () {
  319. var aTopLeft = new Walkontable.CellCoords(0, 0);
  320. var aBottomRight = new Walkontable.CellCoords(5, 5);
  321. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  322. var bTopLeft = new Walkontable.CellCoords(1, 0);
  323. var bBottomRight = new Walkontable.CellCoords(5, 5);
  324. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  325. expect(a.includesRange(b)).toBe(true);
  326. });
  327. /*
  328. +----------+
  329. | b |
  330. |----------|
  331. | a |
  332. +----------+
  333. */
  334. it('B is included in A, left, top and right borders touch', function () {
  335. var aTopLeft = new Walkontable.CellCoords(0, 0);
  336. var aBottomRight = new Walkontable.CellCoords(5, 5);
  337. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  338. var bTopLeft = new Walkontable.CellCoords(0, 0);
  339. var bBottomRight = new Walkontable.CellCoords(4, 5);
  340. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  341. expect(a.includesRange(b)).toBe(true);
  342. });
  343. });
  344. describe('B has exactly one cell', function () {
  345. /*
  346. +----------+
  347. | a |
  348. | +------+ |
  349. | | b | |
  350. | | | |
  351. | +------+ |
  352. +----------+
  353. */
  354. it('B is included in A, none of borders touch each other', function () {
  355. var aTopLeft = new Walkontable.CellCoords(0, 0);
  356. var aBottomRight = new Walkontable.CellCoords(5, 5);
  357. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  358. var bTopLeft = new Walkontable.CellCoords(1, 1);
  359. var bBottomRight = new Walkontable.CellCoords(1, 1);
  360. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  361. expect(a.includesRange(b)).toBe(true);
  362. });
  363. });
  364. });
  365. describe('expand', function () {
  366. it('should not change range if expander to a cell that fits within the range', function () {
  367. var from = new Walkontable.CellCoords(1, 1);
  368. var to = new Walkontable.CellCoords(3, 3);
  369. var range = new Walkontable.CellRange(from, from, to);
  370. var topLeft = range.getTopLeftCorner();
  371. var bottomRight = range.getBottomRightCorner();
  372. var expander = new Walkontable.CellCoords(3, 1);
  373. var res = range.expand(expander);
  374. expect(res).toBe(false);
  375. var topLeft2 = range.getTopLeftCorner();
  376. var bottomRight2 = range.getBottomRightCorner();
  377. expect(topLeft2).toEqual(topLeft);
  378. expect(bottomRight2).toEqual(bottomRight);
  379. });
  380. it('should change range if expander to a cell outside of the cell range', function () {
  381. var from = new Walkontable.CellCoords(1, 1);
  382. var to = new Walkontable.CellCoords(3, 3);
  383. var range = new Walkontable.CellRange(from, from, to);
  384. var topLeft = range.getTopLeftCorner();
  385. var expander = new Walkontable.CellCoords(4, 4);
  386. var res = range.expand(expander);
  387. expect(res).toBe(true);
  388. var topLeft2 = range.getTopLeftCorner();
  389. var bottomRight2 = range.getBottomRightCorner();
  390. expect(topLeft2).toEqual(topLeft);
  391. expect(bottomRight2).toEqual(expander);
  392. });
  393. it('should change range if expander to a cell outside of the cell range (inverted)', function () {
  394. var from = new Walkontable.CellCoords(1, 1);
  395. var to = new Walkontable.CellCoords(3, 3);
  396. var range = new Walkontable.CellRange(from, from, to);
  397. var topLeft = range.getTopLeftCorner();
  398. var expander = new Walkontable.CellCoords(4, 4);
  399. var res = range.expand(expander);
  400. expect(res).toBe(true);
  401. var topLeft2 = range.getTopLeftCorner();
  402. var bottomRight2 = range.getBottomRightCorner();
  403. expect(topLeft2).toEqual(topLeft);
  404. expect(bottomRight2).toEqual(expander);
  405. });
  406. it('should change range if expander to a cell outside of the cell range (bottom left)', function () {
  407. var from = new Walkontable.CellCoords(1, 1);
  408. var to = new Walkontable.CellCoords(3, 3);
  409. var range = new Walkontable.CellRange(from, from, to);
  410. var expander = new Walkontable.CellCoords(3, 0);
  411. var res = range.expand(expander);
  412. expect(res).toBe(true);
  413. var topLeft2 = range.getTopLeftCorner();
  414. var bottomRight2 = range.getBottomRightCorner();
  415. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  416. expect(bottomRight2).toEqual(new Walkontable.CellCoords(3, 3));
  417. });
  418. it('should change range if expander to a cell outside of the cell range (inverted top right)', function () {
  419. var from = new Walkontable.CellCoords(2, 0);
  420. var to = new Walkontable.CellCoords(1, 0);
  421. var range = new Walkontable.CellRange(from, from, to);
  422. var expander = new Walkontable.CellCoords(1, 1);
  423. var res = range.expand(expander);
  424. expect(res).toBe(true);
  425. var topLeft2 = range.getTopLeftCorner();
  426. var bottomRight2 = range.getBottomRightCorner();
  427. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  428. expect(bottomRight2).toEqual(new Walkontable.CellCoords(2, 1));
  429. });
  430. it('should change range if expander to a cell outside of the cell range (inverted bottom left)', function () {
  431. var from = new Walkontable.CellCoords(2, 1);
  432. var to = new Walkontable.CellCoords(1, 1);
  433. var range = new Walkontable.CellRange(from, from, to);
  434. var expander = new Walkontable.CellCoords(3, 0);
  435. var res = range.expand(expander);
  436. expect(res).toBe(true);
  437. var topLeft2 = range.getTopLeftCorner();
  438. var bottomRight2 = range.getBottomRightCorner();
  439. expect(topLeft2).toEqual(new Walkontable.CellCoords(1, 0));
  440. expect(bottomRight2).toEqual(new Walkontable.CellCoords(3, 1));
  441. });
  442. });
  443. describe('overlaps', function () {
  444. describe('positive', function () {
  445. /*
  446. +-------+
  447. | |
  448. | b |
  449. +-------+ |
  450. | +-|-----+
  451. | a |
  452. | |
  453. +-------+
  454. */
  455. it('overlapping from NE', function () {
  456. var aTopLeft = new Walkontable.CellCoords(3, 0);
  457. var aBottomRight = new Walkontable.CellCoords(8, 5);
  458. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  459. var bTopLeft = new Walkontable.CellCoords(0, 3);
  460. var bBottomRight = new Walkontable.CellCoords(5, 8);
  461. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  462. expect(a.overlaps(b)).toBe(true);
  463. });
  464. /*
  465. +---------+
  466. | +-------+
  467. | | | |
  468. | a | | b |
  469. | | | |
  470. | +-------+
  471. +---------+
  472. */
  473. it('overlapping from E', function () {
  474. var aTopLeft = new Walkontable.CellCoords(0, 0);
  475. var aBottomRight = new Walkontable.CellCoords(5, 5);
  476. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  477. var bTopLeft = new Walkontable.CellCoords(1, 3);
  478. var bBottomRight = new Walkontable.CellCoords(4, 6);
  479. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  480. expect(a.overlaps(b)).toBe(true);
  481. });
  482. /*
  483. +--------+
  484. | |
  485. | a |
  486. | +---------+
  487. | | | |
  488. +----|---+ |
  489. | b |
  490. | |
  491. +---------+
  492. */
  493. it('overlapping from SE', function () {
  494. var aTopLeft = new Walkontable.CellCoords(0, 0);
  495. var aBottomRight = new Walkontable.CellCoords(5, 5);
  496. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  497. var bTopLeft = new Walkontable.CellCoords(3, 3);
  498. var bBottomRight = new Walkontable.CellCoords(8, 8);
  499. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  500. expect(a.overlaps(b)).toBe(true);
  501. });
  502. /*
  503. +---------+
  504. | a |
  505. | +-----+ |
  506. +-|-----|-+
  507. | b |
  508. +-----+
  509. */
  510. it('overlapping from S', function () {
  511. var aTopLeft = new Walkontable.CellCoords(0, 0);
  512. var aBottomRight = new Walkontable.CellCoords(5, 5);
  513. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  514. var bTopLeft = new Walkontable.CellCoords(3, 1);
  515. var bBottomRight = new Walkontable.CellCoords(6, 4);
  516. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  517. expect(a.overlaps(b)).toBe(true);
  518. });
  519. /*
  520. +--------+
  521. | a |
  522. +--------+ |
  523. | | | |
  524. | +----|---+
  525. | b |
  526. +--------+
  527. */
  528. it('overlapping from SW', function () {
  529. var aTopLeft = new Walkontable.CellCoords(0, 3);
  530. var aBottomRight = new Walkontable.CellCoords(5, 8);
  531. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  532. var bTopLeft = new Walkontable.CellCoords(3, 0);
  533. var bBottomRight = new Walkontable.CellCoords(8, 5);
  534. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  535. expect(a.overlaps(b)).toBe(true);
  536. });
  537. /*
  538. +-------+
  539. +---|--+ |
  540. | | | |
  541. | b | | a |
  542. | | | |
  543. +---|--+ |
  544. +-------+
  545. */
  546. it('overlapping from S', function () {
  547. var aTopLeft = new Walkontable.CellCoords(0, 3);
  548. var aBottomRight = new Walkontable.CellCoords(5, 8);
  549. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  550. var bTopLeft = new Walkontable.CellCoords(1, 1);
  551. var bBottomRight = new Walkontable.CellCoords(4, 4);
  552. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  553. expect(a.overlaps(b)).toBe(true);
  554. });
  555. /*
  556. +------+
  557. | b |
  558. | +-------+
  559. | | | |
  560. +---|--+ a |
  561. | |
  562. +-------+
  563. */
  564. it('overlapping from NW', function () {
  565. var aTopLeft = new Walkontable.CellCoords(3, 3);
  566. var aBottomRight = new Walkontable.CellCoords(8, 8);
  567. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  568. var bTopLeft = new Walkontable.CellCoords(0, 0);
  569. var bBottomRight = new Walkontable.CellCoords(5, 5);
  570. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  571. expect(a.overlaps(b)).toBe(true);
  572. });
  573. /*
  574. +---------+
  575. | b |
  576. | +-----+ |
  577. +-|-----|-+
  578. | a |
  579. +-----+
  580. */
  581. it('overlapping from N', function () {
  582. var aTopLeft = new Walkontable.CellCoords(3, 1);
  583. var aBottomRight = new Walkontable.CellCoords(6, 4);
  584. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  585. var bTopLeft = new Walkontable.CellCoords(0, 0);
  586. var bBottomRight = new Walkontable.CellCoords(5, 5);
  587. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  588. expect(a.overlaps(b)).toBe(true);
  589. });
  590. /*
  591. +----------+
  592. | a |
  593. | +------+ |
  594. | | b | |
  595. | | | |
  596. | +------+ |
  597. +----------+
  598. */
  599. it('overlapping when includes', function () {
  600. var aTopLeft = new Walkontable.CellCoords(0, 0);
  601. var aBottomRight = new Walkontable.CellCoords(5, 5);
  602. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  603. var bTopLeft = new Walkontable.CellCoords(1, 1);
  604. var bBottomRight = new Walkontable.CellCoords(4, 4);
  605. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  606. expect(a.overlaps(b)).toBe(true);
  607. });
  608. /*
  609. +----------+
  610. | b |
  611. | +------+ |
  612. | | a | |
  613. | | | |
  614. | +------+ |
  615. +----------+
  616. */
  617. it('overlapping when included', function () {
  618. var aTopLeft = new Walkontable.CellCoords(1, 1);
  619. var aBottomRight = new Walkontable.CellCoords(4, 4);
  620. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  621. var bTopLeft = new Walkontable.CellCoords(0, 0);
  622. var bBottomRight = new Walkontable.CellCoords(5, 5);
  623. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  624. expect(a.overlaps(b)).toBe(true);
  625. });
  626. /*
  627. b-> +----------+
  628. | a |
  629. | |
  630. | |
  631. +----------+
  632. */
  633. it('overlapping when A includes B and B has only one cell, and this cell is A\'s top left corner', function () {
  634. var aTopLeft = new Walkontable.CellCoords(0, 0);
  635. var aBottomRight = new Walkontable.CellCoords(5, 5);
  636. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  637. var bTopLeft = new Walkontable.CellCoords(0, 0);
  638. var bBottomRight = new Walkontable.CellCoords(0, 0);
  639. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  640. expect(a.overlaps(b)).toBe(true);
  641. });
  642. /*
  643. +----------+ <- b
  644. | a |
  645. | |
  646. | |
  647. +----------+
  648. */
  649. it('overlapping when A includes B and B has only one cell, and this cell is A\'s top right corner', function () {
  650. var aTopLeft = new Walkontable.CellCoords(0, 0);
  651. var aBottomRight = new Walkontable.CellCoords(5, 5);
  652. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  653. var bTopLeft = new Walkontable.CellCoords(0, 5);
  654. var bBottomRight = new Walkontable.CellCoords(0, 5);
  655. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  656. expect(a.overlaps(b)).toBe(true);
  657. });
  658. /*
  659. +----------+
  660. | a |
  661. | |
  662. | |
  663. b -> +----------+
  664. */
  665. it('overlapping when A includes B and B has only one cell, and this cell is A\'s bottom left corner', function () {
  666. var aTopLeft = new Walkontable.CellCoords(0, 0);
  667. var aBottomRight = new Walkontable.CellCoords(5, 5);
  668. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  669. var bTopLeft = new Walkontable.CellCoords(5, 0);
  670. var bBottomRight = new Walkontable.CellCoords(5, 0);
  671. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  672. expect(a.overlaps(b)).toBe(true);
  673. });
  674. /*
  675. +----------+
  676. | a |
  677. | |
  678. | |
  679. +----------+ <- b
  680. */
  681. it('overlapping when A includes B and B has only one cell, and this cell is A\'s bottom right corner', function () {
  682. var aTopLeft = new Walkontable.CellCoords(0, 0);
  683. var aBottomRight = new Walkontable.CellCoords(5, 5);
  684. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  685. var bTopLeft = new Walkontable.CellCoords(5, 5);
  686. var bBottomRight = new Walkontable.CellCoords(5, 5);
  687. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  688. expect(a.overlaps(b)).toBe(true);
  689. });
  690. /*
  691. +----+
  692. |b |
  693. +----+----+
  694. | a|
  695. +----+
  696. */
  697. it('overlapping by touching from NE', function () {
  698. var aTopLeft = new Walkontable.CellCoords(5, 0);
  699. var aBottomRight = new Walkontable.CellCoords(10, 5);
  700. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  701. var bTopLeft = new Walkontable.CellCoords(0, 5);
  702. var bBottomRight = new Walkontable.CellCoords(5, 10);
  703. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  704. expect(a.overlaps(b)).toBe(true);
  705. });
  706. /*
  707. +----+----+
  708. | a| b|
  709. +----+----+
  710. */
  711. it('overlapping by touching from E', function () {
  712. var aTopLeft = new Walkontable.CellCoords(0, 0);
  713. var aBottomRight = new Walkontable.CellCoords(5, 5);
  714. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  715. var bTopLeft = new Walkontable.CellCoords(0, 5);
  716. var bBottomRight = new Walkontable.CellCoords(5, 10);
  717. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  718. expect(a.overlaps(b)).toBe(true);
  719. });
  720. /*
  721. +----+
  722. | a|
  723. +----+----+
  724. | b|
  725. +----+
  726. */
  727. it('overlapping by touching from SE', function () {
  728. var aTopLeft = new Walkontable.CellCoords(0, 0);
  729. var aBottomRight = new Walkontable.CellCoords(5, 5);
  730. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  731. var bTopLeft = new Walkontable.CellCoords(5, 5);
  732. var bBottomRight = new Walkontable.CellCoords(10, 10);
  733. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  734. expect(a.overlaps(b)).toBe(true);
  735. });
  736. /*
  737. +----+
  738. | a|
  739. +----+
  740. | b|
  741. +----+
  742. */
  743. it('overlapping by touching from S', function () {
  744. var aTopLeft = new Walkontable.CellCoords(0, 0);
  745. var aBottomRight = new Walkontable.CellCoords(5, 5);
  746. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  747. var bTopLeft = new Walkontable.CellCoords(5, 5);
  748. var bBottomRight = new Walkontable.CellCoords(10, 5);
  749. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  750. expect(a.overlaps(b)).toBe(true);
  751. });
  752. /*
  753. +----+
  754. | a|
  755. +----+----+
  756. | b|
  757. +----+
  758. */
  759. it('overlapping by touching from SW', function () {
  760. var aTopLeft = new Walkontable.CellCoords(0, 5);
  761. var aBottomRight = new Walkontable.CellCoords(5, 10);
  762. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  763. var bTopLeft = new Walkontable.CellCoords(5, 0);
  764. var bBottomRight = new Walkontable.CellCoords(10, 5);
  765. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  766. expect(a.overlaps(b)).toBe(true);
  767. });
  768. /*
  769. +----+----+
  770. | b| a|
  771. +----+----+
  772. */
  773. it('overlapping by touching from W', function () {
  774. var aTopLeft = new Walkontable.CellCoords(0, 5);
  775. var aBottomRight = new Walkontable.CellCoords(5, 10);
  776. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  777. var bTopLeft = new Walkontable.CellCoords(0, 0);
  778. var bBottomRight = new Walkontable.CellCoords(5, 5);
  779. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  780. expect(a.overlaps(b)).toBe(true);
  781. });
  782. /*
  783. +----+
  784. | b|
  785. +----+----+
  786. | a|
  787. +----+
  788. */
  789. it('overlapping by touching from NW', function () {
  790. var aTopLeft = new Walkontable.CellCoords(5, 5);
  791. var aBottomRight = new Walkontable.CellCoords(10, 10);
  792. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  793. var bTopLeft = new Walkontable.CellCoords(0, 0);
  794. var bBottomRight = new Walkontable.CellCoords(5, 5);
  795. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  796. expect(a.overlaps(b)).toBe(true);
  797. });
  798. /*
  799. +----+
  800. | b|
  801. +----+
  802. | a|
  803. +----+
  804. */
  805. it('overlapping by touching from E', function () {
  806. var aTopLeft = new Walkontable.CellCoords(5, 0);
  807. var aBottomRight = new Walkontable.CellCoords(10, 5);
  808. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  809. var bTopLeft = new Walkontable.CellCoords(0, 0);
  810. var bBottomRight = new Walkontable.CellCoords(5, 5);
  811. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  812. expect(a.overlaps(b)).toBe(true);
  813. });
  814. });
  815. describe('negative', function () {
  816. /*
  817. +---+
  818. | b|
  819. +---+
  820. +------+
  821. | |
  822. | a |
  823. | |
  824. +------+
  825. */
  826. it('not overlapping from NE', function () {
  827. var aTopLeft = new Walkontable.CellCoords(6, 0);
  828. var aBottomRight = new Walkontable.CellCoords(11, 5);
  829. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  830. var bTopLeft = new Walkontable.CellCoords(0, 3);
  831. var bBottomRight = new Walkontable.CellCoords(5, 8);
  832. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  833. expect(a.overlaps(b)).toBe(false);
  834. });
  835. /*
  836. +------+
  837. | | +--+
  838. | a | | b|
  839. | | +--+
  840. +------+
  841. */
  842. it('not overlapping from E', function () {
  843. var aTopLeft = new Walkontable.CellCoords(0, 0);
  844. var aBottomRight = new Walkontable.CellCoords(5, 5);
  845. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  846. var bTopLeft = new Walkontable.CellCoords(1, 6);
  847. var bBottomRight = new Walkontable.CellCoords(4, 9);
  848. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  849. expect(a.overlaps(b)).toBe(false);
  850. });
  851. /*
  852. +----+
  853. |a |
  854. | | +----+
  855. +----+ |b |
  856. | |
  857. +----+
  858. */
  859. it('not overlapping from SE', function () {
  860. var aTopLeft = new Walkontable.CellCoords(0, 0);
  861. var aBottomRight = new Walkontable.CellCoords(5, 5);
  862. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  863. var bTopLeft = new Walkontable.CellCoords(1, 6);
  864. var bBottomRight = new Walkontable.CellCoords(4, 9);
  865. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  866. expect(a.overlaps(b)).toBe(false);
  867. });
  868. /*
  869. +----+
  870. |a |
  871. | |
  872. +----+
  873. +----+
  874. |b |
  875. | |
  876. +----+
  877. */
  878. it('not overlapping from S', function () {
  879. var aTopLeft = new Walkontable.CellCoords(0, 0);
  880. var aBottomRight = new Walkontable.CellCoords(5, 5);
  881. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  882. var bTopLeft = new Walkontable.CellCoords(6, 0);
  883. var bBottomRight = new Walkontable.CellCoords(11, 5);
  884. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  885. expect(a.overlaps(b)).toBe(false);
  886. });
  887. /*
  888. +----+
  889. |a |
  890. | |
  891. +----+
  892. +----+
  893. |b |
  894. | |
  895. +----+
  896. */
  897. it('not overlapping from SW', function () {
  898. var aTopLeft = new Walkontable.CellCoords(0, 3);
  899. var aBottomRight = new Walkontable.CellCoords(5, 8);
  900. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  901. var bTopLeft = new Walkontable.CellCoords(6, 0);
  902. var bBottomRight = new Walkontable.CellCoords(11, 5);
  903. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  904. expect(a.overlaps(b)).toBe(false);
  905. });
  906. /*
  907. +------+
  908. +--+ | |
  909. | b| | a |
  910. +--+ | |
  911. +------+
  912. */
  913. it('not overlapping from W', function () {
  914. var aTopLeft = new Walkontable.CellCoords(0, 6);
  915. var aBottomRight = new Walkontable.CellCoords(5, 11);
  916. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  917. var bTopLeft = new Walkontable.CellCoords(3, 0);
  918. var bBottomRight = new Walkontable.CellCoords(6, 3);
  919. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  920. expect(a.overlaps(b)).toBe(false);
  921. });
  922. /*
  923. +----+
  924. |b |
  925. | | +----+
  926. +----+ | a |
  927. | |
  928. +----+
  929. */
  930. it('not overlapping from NW', function () {
  931. var aTopLeft = new Walkontable.CellCoords(0, 6);
  932. var aBottomRight = new Walkontable.CellCoords(3, 11);
  933. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  934. var bTopLeft = new Walkontable.CellCoords(0, 0);
  935. var bBottomRight = new Walkontable.CellCoords(5, 5);
  936. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  937. expect(a.overlaps(b)).toBe(false);
  938. });
  939. /*
  940. +----+
  941. |b |
  942. +----+
  943. +----+
  944. | a|
  945. +----+
  946. */
  947. it('not overlapping from N', function () {
  948. var aTopLeft = new Walkontable.CellCoords(6, 0);
  949. var aBottomRight = new Walkontable.CellCoords(11, 5);
  950. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  951. var bTopLeft = new Walkontable.CellCoords(0, 0);
  952. var bBottomRight = new Walkontable.CellCoords(5, 5);
  953. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  954. expect(a.overlaps(b)).toBe(false);
  955. });
  956. });
  957. });
  958. describe('expand by range', function () {
  959. it('should not expand range A with range B if A includes B', function () {
  960. var aTopLeft = new Walkontable.CellCoords(0, 0);
  961. var aBottomRight = new Walkontable.CellCoords(5, 5);
  962. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  963. var bTopLeft = new Walkontable.CellCoords(2, 2);
  964. var bBottomRight = new Walkontable.CellCoords(4, 4);
  965. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  966. expect(a.expandByRange(b)).toBe(false);
  967. expect(a.getTopLeftCorner().row).toEqual(0);
  968. expect(a.getTopLeftCorner().col).toEqual(0);
  969. expect(a.getBottomRightCorner().row).toEqual(5);
  970. expect(a.getBottomRightCorner().col).toEqual(5);
  971. });
  972. it('should not expand range A with range B if A and B don\'t overlap', function () {
  973. var aTopLeft = new Walkontable.CellCoords(0, 0);
  974. var aBottomRight = new Walkontable.CellCoords(5, 5);
  975. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  976. var bTopLeft = new Walkontable.CellCoords(10, 10);
  977. var bBottomRight = new Walkontable.CellCoords(15, 15);
  978. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  979. expect(a.expandByRange(b)).toBe(false);
  980. expect(a.getTopLeftCorner().row).toEqual(0);
  981. expect(a.getTopLeftCorner().col).toEqual(0);
  982. expect(a.getBottomRightCorner().row).toEqual(5);
  983. expect(a.getBottomRightCorner().col).toEqual(5);
  984. });
  985. it('should not expand range A with range B', function () {
  986. var aTopLeft = new Walkontable.CellCoords(0, 0);
  987. var aBottomRight = new Walkontable.CellCoords(5, 5);
  988. var a = new Walkontable.CellRange(aTopLeft, aTopLeft, aBottomRight);
  989. var bTopLeft = new Walkontable.CellCoords(2, 2);
  990. var bBottomRight = new Walkontable.CellCoords(7, 7);
  991. var b = new Walkontable.CellRange(bTopLeft, bTopLeft, bBottomRight);
  992. expect(a.expandByRange(b)).toBe(true);
  993. expect(a.getTopLeftCorner().row).toEqual(0);
  994. expect(a.getTopLeftCorner().col).toEqual(0);
  995. expect(a.getBottomRightCorner().row).toEqual(7);
  996. expect(a.getBottomRightCorner().col).toEqual(7);
  997. });
  998. });
  999. describe('forAll', function () {
  1000. it('callback should be called for all cells in the range', function () {
  1001. var from = new Walkontable.CellCoords(1, 1);
  1002. var to = new Walkontable.CellCoords(3, 3);
  1003. var range = new Walkontable.CellRange(from, from, to);
  1004. var forAllCallback = jasmine.createSpy('beforeColumnSortHandler');
  1005. range.forAll(forAllCallback);
  1006. expect(forAllCallback.calls.count()).toBe(9);
  1007. });
  1008. it('callback should be called with row, column parameters', function () {
  1009. var from = new Walkontable.CellCoords(1, 1);
  1010. var to = new Walkontable.CellCoords(2, 2);
  1011. var range = new Walkontable.CellRange(from, from, to);
  1012. var rows = [];
  1013. var cols = [];
  1014. range.forAll(function (row, col) {
  1015. rows.push(row);
  1016. cols.push(col);
  1017. });
  1018. expect(rows).toEqual([1, 1, 2, 2]);
  1019. expect(cols).toEqual([1, 2, 1, 2]);
  1020. });
  1021. it('iteration should be interrupted when callback returns false', function () {
  1022. var from = new Walkontable.CellCoords(1, 1);
  1023. var to = new Walkontable.CellCoords(2, 2);
  1024. var range = new Walkontable.CellRange(from, from, to);
  1025. var callCount = 0;
  1026. range.forAll(function (row, col) {
  1027. callCount++;
  1028. if (callCount == 2) {
  1029. return false;
  1030. }
  1031. });
  1032. expect(callCount).toBe(2);
  1033. });
  1034. });
  1035. describe('change direction', function () {
  1036. it('should properly change direction on NW-SE', function () {
  1037. var from = new Walkontable.CellCoords(2, 1);
  1038. var to = new Walkontable.CellCoords(1, 2);
  1039. var range = new Walkontable.CellRange(from, from, to);
  1040. expect(range.getDirection()).toBe('SW-NE');
  1041. range.setDirection('NW-SE');
  1042. expect(range.getDirection()).toBe('NW-SE');
  1043. expect(range.from.row).toBe(1);
  1044. expect(range.from.col).toBe(1);
  1045. expect(range.to.row).toBe(2);
  1046. expect(range.to.col).toBe(2);
  1047. });
  1048. it('should properly change direction on NE-SW', function () {
  1049. var from = new Walkontable.CellCoords(2, 1);
  1050. var to = new Walkontable.CellCoords(1, 2);
  1051. var range = new Walkontable.CellRange(from, from, to);
  1052. expect(range.getDirection()).toBe('SW-NE');
  1053. range.setDirection('NE-SW');
  1054. expect(range.getDirection()).toBe('NE-SW');
  1055. expect(range.from.row).toBe(1);
  1056. expect(range.from.col).toBe(2);
  1057. expect(range.to.row).toBe(2);
  1058. expect(range.to.col).toBe(1);
  1059. });
  1060. it('should properly change direction on SE-NW', function () {
  1061. var from = new Walkontable.CellCoords(1, 1);
  1062. var to = new Walkontable.CellCoords(2, 2);
  1063. var range = new Walkontable.CellRange(from, from, to);
  1064. expect(range.getDirection()).toBe('NW-SE');
  1065. range.setDirection('SE-NW');
  1066. expect(range.getDirection()).toBe('SE-NW');
  1067. expect(range.from.row).toBe(2);
  1068. expect(range.from.col).toBe(2);
  1069. expect(range.to.row).toBe(1);
  1070. expect(range.to.col).toBe(1);
  1071. });
  1072. it('should properly change direction on SW-NE', function () {
  1073. var from = new Walkontable.CellCoords(1, 1);
  1074. var to = new Walkontable.CellCoords(2, 2);
  1075. var range = new Walkontable.CellRange(from, from, to);
  1076. expect(range.getDirection()).toBe('NW-SE');
  1077. range.setDirection('SW-NE');
  1078. expect(range.getDirection()).toBe('SW-NE');
  1079. expect(range.from.row).toBe(2);
  1080. expect(range.from.col).toBe(1);
  1081. expect(range.to.row).toBe(1);
  1082. expect(range.to.col).toBe(2);
  1083. });
  1084. });
  1085. });