<commit_before>require 'rails_helper'

RSpec.describe Formatter do
  let(:account)       { Fabricate(:account, username: 'alice') }
  let(:local_text)    { 'Hello world http://google.com' }
  let(:local_status)  { Fabricate(:status, text: local_text, account: account) }
  let(:remote_status) { Fabricate(:status, text: '<script>alert("Hello")</script> Beep boop', uri: 'beepboop', account: account) }

  describe '#format' do
    subject { Formatter.instance.format(local_status) }

    it 'returns a string' do
      expect(subject).to be_a String
    end

    it 'contains plain text' do
      expect(subject).to match('Hello world')
    end

    it 'contains a link' do
      expect(subject).to match('<a href="http://google.com" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">google.com</span><span class="invisible"></span></a>')
    end

    context 'matches a stand-alone medium URL' do
      let(:local_text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' }
      it 'has valid url' do
        expect(subject).to include('href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"')
      end
    end

    context 'matches a stand-alone google URL' do
      let(:local_text) { 'http://google.com' }
      it 'has valid url' do
        expect(subject).to include('href="http://google.com"')
      end
    end

    context 'matches a URL without trailing period' do
      let(:local_text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' }
      it 'has valid url' do
        expect(subject).to include('href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"')
      end
    end

=begin
    it 'matches a URL without closing paranthesis' do
      expect(subject.match('(http://google.com/)')[0]).to eq 'http://google.com'
    end
=end

    context 'matches a URL without exclamation point' do
      let(:local_text) { 'http://www.google.com!' }
      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without single quote' do
      let(:local_text) { "http://www.google.com'" }

      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without angle brackets' do
      let(:local_text) { 'http://www.google.com>' }
      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without single quote' do
      let(:local_text) { "http://www.google.com'" }

      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without angle brackets' do
      let(:local_text) { 'http://www.google.com>' }<commit_msg>Remove duplicated code<commit_after>require 'rails_helper'

RSpec.describe Formatter do
  let(:account)       { Fabricate(:account, username: 'alice') }
  let(:local_text)    { 'Hello world http://google.com' }
  let(:local_status)  { Fabricate(:status, text: local_text, account: account) }
  let(:remote_status) { Fabricate(:status, text: '<script>alert("Hello")</script> Beep boop', uri: 'beepboop', account: account) }

  describe '#format' do
    subject { Formatter.instance.format(local_status) }

    it 'returns a string' do
      expect(subject).to be_a String
    end

    it 'contains plain text' do
      expect(subject).to match('Hello world')
    end

    it 'contains a link' do
      expect(subject).to match('<a href="http://google.com" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">google.com</span><span class="invisible"></span></a>')
    end

    context 'matches a stand-alone medium URL' do
      let(:local_text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' }
      it 'has valid url' do
        expect(subject).to include('href="https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4"')
      end
    end

    context 'matches a stand-alone google URL' do
      let(:local_text) { 'http://google.com' }
      it 'has valid url' do
        expect(subject).to include('href="http://google.com"')
      end
    end

    context 'matches a URL without trailing period' do
      let(:local_text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' }
      it 'has valid url' do
        expect(subject).to include('href="http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona"')
      end
    end

=begin
    it 'matches a URL without closing paranthesis' do
      expect(subject.match('(http://google.com/)')[0]).to eq 'http://google.com'
    end
=end

    context 'matches a URL without exclamation point' do
      let(:local_text) { 'http://www.google.com!' }
      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without single quote' do
      let(:local_text) { "http://www.google.com'" }
      it 'has valid url' do
        expect(subject).to include('href="http://www.google.com"')
      end
    end

    context 'matches a URL without angle brackets' do
      let(:local_text) { 'http://www.google.com>' }
{'fraction_non_alphanumeric': 0.15031616982836496, 'fraction_numerical': 0.015537488708220415, 'mean_word_length': 3.17811320754717, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 18, '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': '5186635', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1784, 'n_words': 408}