multirange_test.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2008 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.dom.MultiRangeTest');
  15. goog.setTestOnly('goog.dom.MultiRangeTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.dom.MultiRange');
  18. goog.require('goog.dom.Range');
  19. goog.require('goog.iter');
  20. goog.require('goog.testing.jsunit');
  21. var range;
  22. function setUp() {
  23. range = new goog.dom.MultiRange.createFromTextRanges([
  24. goog.dom.Range.createFromNodeContents(goog.dom.getElement('test2')),
  25. goog.dom.Range.createFromNodeContents(goog.dom.getElement('test1'))
  26. ]);
  27. }
  28. function testStartAndEnd() {
  29. assertEquals(goog.dom.getElement('test1').firstChild, range.getStartNode());
  30. assertEquals(0, range.getStartOffset());
  31. assertEquals(goog.dom.getElement('test2').firstChild, range.getEndNode());
  32. assertEquals(6, range.getEndOffset());
  33. }
  34. function testStartAndEndIterator() {
  35. var it = goog.iter.toIterator(range);
  36. assertEquals(goog.dom.getElement('test1').firstChild, it.getStartNode());
  37. assertEquals(0, it.getStartTextOffset());
  38. assertEquals(goog.dom.getElement('test2').firstChild, it.getEndNode());
  39. assertEquals(3, it.getEndTextOffset());
  40. it.next();
  41. it.next();
  42. assertEquals(6, it.getEndTextOffset());
  43. }
  44. function testIteration() {
  45. var tags = goog.iter.toArray(range);
  46. assertEquals(2, tags.length);
  47. assertEquals(goog.dom.getElement('test1').firstChild, tags[0]);
  48. assertEquals(goog.dom.getElement('test2').firstChild, tags[1]);
  49. }