<commit_before>require "isolation/abstract_unit"
require 'rails/source_annotation_extractor'

module ApplicationTests
  module RakeTests
    class RakeNotesTest < ActiveSupport::TestCase
      include ActiveSupport::Testing::Isolation

      def setup
        build_app
        require "rails/all"
        super
      end

      def teardown
        super
        teardown_app
      end

      test 'notes finds notes for certain file_types' do
        app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
        app_file "app/assets/javascripts/application.js", "// TODO: note in js"
        app_file "app/assets/stylesheets/application.css", "// TODO: note in css"
        app_file "app/controllers/application_controller.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in ruby"
        app_file "lib/tasks/task.rake", "# TODO: note in rake"
        app_file 'app/views/home/index.html.builder', '# TODO: note in builder'
        app_file 'config/locales/en.yml', '# TODO: note in yml'
        app_file 'config/locales/en.yaml', '# TODO: note in yaml'
        app_file "app/views/home/index.ruby", "# TODO: note in ruby"

        boot_rails
        load_tasks

        Dir.chdir(app_path) do
          output = `bundle exec rake notes`
          lines = output.scan(/\[([0-9\s]+)\](\s)/)

          assert_match(/note in erb/, output)
          assert_match(/note in js/, output)
          assert_match(/note in css/, output)
          assert_match(/note in rake/, output)
          assert_match(/note in builder/, output)
          assert_match(/note in yml/, output)
          assert_match(/note in yaml/, output)
          assert_match(/note in ruby/, output)

          assert_equal 9, lines.size

          lines.each do |line|
            assert_equal 4, line[0].size
            assert_equal ' ', line[1]
          end
        end
      end

      test 'notes finds notes in default directories' do
        app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
        app_file "config/initializers/some_initializer.rb", "# TODO: note in config directory"<commit_msg>Remove extra space assertion<commit_after>require "isolation/abstract_unit"
require 'rails/source_annotation_extractor'

module ApplicationTests
  module RakeTests
    class RakeNotesTest < ActiveSupport::TestCase
      include ActiveSupport::Testing::Isolation

      def setup
        build_app
        require "rails/all"
        super
      end

      def teardown
        super
        teardown_app
      end

      test 'notes finds notes for certain file_types' do
        app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
        app_file "app/assets/javascripts/application.js", "// TODO: note in js"
        app_file "app/assets/stylesheets/application.css", "// TODO: note in css"
        app_file "app/controllers/application_controller.rb", 1000.times.map { "" }.join("\n") << "# TODO: note in ruby"
        app_file "lib/tasks/task.rake", "# TODO: note in rake"
        app_file 'app/views/home/index.html.builder', '# TODO: note in builder'
        app_file 'config/locales/en.yml', '# TODO: note in yml'
        app_file 'config/locales/en.yaml', '# TODO: note in yaml'
        app_file "app/views/home/index.ruby", "# TODO: note in ruby"

        boot_rails
        load_tasks

        Dir.chdir(app_path) do
          output = `bundle exec rake notes`
          lines = output.scan(/\[([0-9\s]+)\]\s/).flatten

          assert_match(/note in erb/, output)
          assert_match(/note in js/, output)
          assert_match(/note in css/, output)
          assert_match(/note in rake/, output)
          assert_match(/note in builder/, output)
          assert_match(/note in yml/, output)
          assert_match(/note in yaml/, output)
          assert_match(/note in ruby/, output)

          assert_equal 9, lines.size

          lines.each do |line|
            assert_equal 4, line.size
          end
        end
      end

      test 'notes finds notes in default directories' do
        app_file "app/controllers/some_controller.rb", "# TODO: note in app directory"
        app_file "config/initializers/some_initializer.rb", "# TODO: note in config directory"
{'fraction_non_alphanumeric': 0.11153119092627599, 'fraction_numerical': 0.004253308128544423, 'mean_word_length': 2.3096168881939017, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '7548420', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1230, 'n_words': 336}