<commit_before>require "spec_helper"
require "support/shared_examples.rb"

load "pre_commit/checkers/strict_paren_spacing_checker.rb"

RSpec.describe StrictParenSpacingChecker do
  let(:checker_class) { StrictParenSpacingChecker }

  context "code with no parens" do
    subject(:checker) { test_class_with_change(checker_class, "Hello") }
    it_should_behave_like "it finds no error"
  end

  context "code with a properly spaced paren" do
    subject(:checker) { test_class_with_change(checker_class, " (Hello) ") }
    it_should_behave_like "it finds no error"
  end

  context "code with a '( '" do
    subject(:checker) { test_class_with_change(checker_class, "Hi ( there") }
    it_should_behave_like "it finds an error"

    context "in a shell script" do
      subject(:checker) { test_class_with_change(checker_class, "Hi ( there", file: "foo.sh") }
      it_should_behave_like "it finds no error"
    end

    context "in an extensionless shell script" do
      subject(:checker) { test_class_with_change(checker_class, "Hi ( there", file: "foo") }
      it_should_behave_like "it finds no error"
    end

    context "in a bash script" do
      subject(:checker) { test_class_with_change(checker_class, "Hi ( there", file: "foo.bash") }
      it_should_behave_like "it finds no error"
    end
  end

  context "code with a ' )'" do
    subject(:checker) { test_class_with_change(checker_class, "Hi (there )") }
    it_should_behave_like "it finds an error"
  end

  context "code with a '[ '" do
    subject(:checker) { test_class_with_change(checker_class, "Hi [ there") }
    it_should_behave_like "it finds an error"
  end

  context "code with a ' ]'" do
    subject(:checker) { test_class_with_change(checker_class, "Hi there ]") }
    it_should_behave_like "it finds an error"
  end

  context "code with two copies of the same error '( '" do
    subject(:checker) { test_class_with_change(checker_class, "Hi ( there\n and here's ( another") }
    it_should_behave_like "it finds an error"
  end

  context "code with two different errors '( ' and ' ]'" do
    subject(:checker) { test_class_with_change(checker_class, "Hi ( there\n and here's ]another") }
    it_should_behave_like "it finds two errors"
  end

end<commit_msg>Abstract out code examples from paren tests<commit_after>require "spec_helper"
require "support/shared_examples.rb"

load "pre_commit/checkers/strict_paren_spacing_checker.rb"

RSpec.describe StrictParenSpacingChecker do
  let(:checker_class) { StrictParenSpacingChecker }

  context "code with no parens" do
    subject(:checker) { test_class_with_change(checker_class, "Hello") }
    it_should_behave_like "it finds no error"
  end

  context "code with a properly spaced paren" do
    subject(:checker) { test_class_with_change(checker_class, " (Hello) ") }
    it_should_behave_like "it finds no error"
  end

  context "code with a '( '" do
    let(:code) { "Hi ( there" }

    subject(:checker) { test_class_with_change(checker_class, code) }
    it_should_behave_like "it finds an error"

    context "in a shell script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo.sh") }
      it_should_behave_like "it finds no error"
    end

    context "in an extensionless shell script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo") }
      it_should_behave_like "it finds no error"
    end

    context "in a bash script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo.bash") }
      it_should_behave_like "it finds no error"
    end
  end

  context "code with a ' )'" do
    let(:code) { "Hi (there )" }

    subject(:checker) { test_class_with_change(checker_class, code) }
    it_should_behave_like "it finds an error"

    context "in a shell script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo.sh") }
      it_should_behave_like "it finds no error"
    end

    context "in an extensionless shell script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo") }
      it_should_behave_like "it finds no error"
    end

    context "in a bash script" do
      subject(:checker) { test_class_with_change(checker_class, code, file: "foo.bash") }
      it_should_behave_like "it finds no error"
    end
  end

  context "code with a '[ '" do
    let(:code) { "Hi [ there" }

    subject(:checker) { test_class_with_change(checker_class, code) }
    it_should_behave_like "it finds an error"
  end

  context "code with a ' ]'" do
    let(:code) { "Hi there ]" }

    subject(:checker) { test_class_with_change(checker_class, code) }
    it_should_behave_like "it finds an error"
  end

  context "code with two copies of the same error '( '" do
    subject(:checker) { test_class_with_change(checker_class, "Hi ( there\n and here's ( another") }
    it_should_behave_like "it finds an error"
  end

  context "code with two different errors '( ' and ' ]'" do
    subject(:checker) { test_class_with_change(checker_class, "Hi ( there\n and here's ]another") }
    it_should_behave_like "it finds two errors"
  end

end
{'fraction_non_alphanumeric': 0.10001942124684404, 'fraction_numerical': 0.0, 'mean_word_length': 4.009727626459144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3521072', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1726, 'n_words': 468}