<commit_before>quail.aInPHasADistinctStyle=function(quail, test, Case){

  /**
   * Function for just testing the elements text, without checking text of children
   * @returns {*|jQuery}
   */
  function getElementText($elm){
    return $elm.clone()
      .children()
      .remove()
      .end()
      .text().trim();
  }

  /**
   * Checks if an element has a border set
   * @param element
   * @returns {boolean}
   */
  function hasBorder(element){
    return (element.outerWidth() - element.innerWidth() > 0) ||(element.outerHeight() - element.innerHeight() > 0);
  }


  function elmHasDistinctStyle($elm, $parent) {
    var result = false;
    var styleProperties = ['text-decoration', 'font-weight', 'font-style'];

    if ($elm.css('background-color') !== 'rgba(0, 0, 0, 0)') {
      styleProperties.push('background');
    }

    $.each(styleProperties, function (i, styleProp) {
      if (!result && $elm.css(styleProp) !== $parent.css(styleProp)) {
        result = true;
      }
    });

    return result || $elm.css('display') === 'block' || hasBorder($elm);
  }

  console.log(test.get('$scope').find('p a'));

  test.get('$scope').find('p a').each(function() {
    var $this = $(this);
    var $parent = (getElementText($this.parent()) ? $this.parent() : undefined);
    var $p = $(this).closest('p');

    var _case=Case({
      element: this,
      expected: $(this).closest('.quail-test').data('expected')
    });
    test.add(_case);

    if (!$this.attr('href') || !$this.is(':visible') || $this.text() === '') {
      _case.set({
        'status': 'inapplicable'
      });
      return;
    }

    if ($this.find('img').length >= 1 || // pass if there's an image
    elmHasDistinctStyle($this, $p) || // pass if the style is distinct
    (getElementText($parent) === '' && elmHasDistinctStyle($parent, $p))) { // pass if the parent style is distinct
      _case.set({'status': 'passed'});

    } else {
      _case.set({'status': 'failed'});
    }

  });
};
<commit_msg>rewrote aInPHasADistinctStyle<commit_after>quail.aInPHasADistinctStyle=function(quail, test, Case){

  /**
   * Checks if an element has a border set
   * @param element
   * @returns {boolean}
   */
  function hasBorder(element){
    return (element.outerWidth() - element.innerWidth() > 0) ||(element.outerHeight() - element.innerHeight() > 0);
  }

  /**
   * Test if two elements have a distinct style from it's ancestor
   * @param  {jQuery node} $elm    
   * @param  {jQuery node} $parent
   * @return {boolean}
   */
  function elmHasDistinctStyle($elm, $parent) {
    var result = false;
    var styleProperties = ['font-weight', 'font-style'];
    var textDecoration = $elm.css('text-decoration');

    if (textDecoration !== 'none' &&
    textDecoration !== $parent.css('text-decoration')) {
      result = true;
    }

    if ($elm.css('background-color') !== 'rgba(0, 0, 0, 0)') {
      styleProperties.push('background');
    }

    $.each(styleProperties, function (i, styleProp) {
      if (!result && $elm.css(styleProp) !== $parent.css(styleProp)) {
        result = true;
      }
    });

    return result  || hasBorder($elm);
  }

  function elmHasDistinctPosition($elm) {
    var isBlock = ($elm.css('display') === 'block');
    var position = $elm.css('position');
    var isPositioned = position !== 'relative' && position !== 'static';
    return isBlock || isPositioned;
  }


  test.get('$scope').each(function () {
    var $scope = $(this);
    var anchors = $scope.find('p a[href]:visible');

    anchors.each(function () {
      var $this = $(this);
      var $p = $this.closest('p');
      var $parent = $this.parent();

      var _case=Case({
        element: this,
        expected: $this.closest('.quail-test').data('expected')
      });
      test.add(_case);

      var aText = $this.text().trim();
      var pText = $p.text().trim();

      if (aText === '' || aText === pText) {
        _case.set('status', 'inapplicable');

      } else if (elmHasDistinctStyle($this, $p)) {
        _case.set('status', 'passed');

      } else if (elmHasDistinctPosition($this)) {
        _case.set('status', 'passed');

      } else if ($this.find('img').length > 0) {
        _case.set('status', 'passed');

      } else if ($parent.text().trim() === aText &&
      elmHasDistinctStyle($parent, $p)) {
        _case.set('status', 'passed');

      } else {
        _case.set('status', 'failed');
      }
    });

  });

};

{'fraction_non_alphanumeric': 0.1928876884987621, 'fraction_numerical': 0.0031510240828269186, 'mean_word_length': 2.8677110530896432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6704792', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1420, 'n_words': 309}