<commit_before>import TextPositionAnchor from '../dom-anchor-text-position'

describe('TextPositionAnchor', () => {
  before(() => {
    fixture.setBase('test/fixtures');
  });

  beforeEach(() => {
    fixture.load('test.html');
  });

  afterEach(() => {
    fixture.cleanup();
  });

  it('is a function', () => {
    assert.isFunction(TextPositionAnchor);
  });
});
<commit_msg>Tests for fromRange on text nodes<commit_after>import TextPositionAnchor from '../dom-anchor-text-position'

describe('TextPositionAnchor', () => {
  before(() => {
    fixture.setBase('test/fixtures');
  });

  beforeEach(() => {
    fixture.load('test.html');
  });

  afterEach(() => {
    fixture.cleanup();
  });

  it('is a function', () => {
    assert.isFunction(TextPositionAnchor);
  });

  describe('fromRange', () => {
    it('requires a range argument', () => {
      let construct = () => TextPositionAnchor.fromRange();
      assert.throws(construct, 'required parameter');
    });

    it('can describe a whole, single text node', () => {
      let range = global.document.createRange();
      let codeNode = global.document.getElementsByTagName('code')[0];
      let textNode = codeNode.childNodes[0];
      range.selectNodeContents(textNode);
      let anchor = TextPositionAnchor.fromRange(range);
      let {start, end} = anchor;
      let text = global.document.body.textContent.substr(start, end - start);
      assert.equal(text, 'commodo vitae');
    });

    it('can describe part of a single text node', () => {
      let range = global.document.createRange();
      let codeNode = global.document.getElementsByTagName('code')[0];
      let textNode = codeNode.childNodes[0];
      range.setStart(textNode, 5);
      range.setEnd(textNode, 12);
      let anchor = TextPositionAnchor.fromRange(range);
      let {start, end} = anchor;
      let text = global.document.body.textContent.substr(start, end - start);
      assert.equal(text, 'do vita');
    });

    it('can describe a range from one text node to another', () => {
      let range = global.document.createRange();
      let emNode = global.document.getElementsByTagName('em')[0];
      let emTextNode = emNode.childNodes[0];
      let codeNode = global.document.getElementsByTagName('code')[0];
      let codeTextNode = codeNode.childNodes[0];
      range.setStart(emTextNode, 7);
      range.setEnd(codeTextNode, 7);
      let anchor = TextPositionAnchor.fromRange(range);
      let {start, end} = anchor;
      let text = global.document.body.textContent.substr(start, end - start);
      let expected = [
        'ultricies mi vitae est.',
        ' Mauris placerat eleifend\n  leo. Quisque sit amet est',
        ' et sapien ullamcorper pharetra. Vestibulum erat\n',
        '  wisi, condimentum sed, commodo',
      ].join('');
      assert.equal(text, expected);
    });
  });
});

{'fraction_non_alphanumeric': 0.15890794539726985, 'fraction_numerical': 0.004550227511375569, 'mean_word_length': 3.190615835777126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944597', 'n_tokens_mistral': 878, 'n_tokens_neox': 866, 'n_words': 182}