<commit_before>require File.join(File.dirname(__FILE__), '..', 'spec_helper')

require 'pathname'

describe Synxronize::Project do

  let(:dummy_synx_pathname) { Pathname(File.join(File.dirname(__FILE__), '..', 'dummy')) }
  let(:dummy_synx_project_path) { dummy_synx_pathname + 'dummy.xcodeproj' }

  let(:dummy_synx_project) do
    Synxronize::Project.open(dummy_synx_project_path)
  end

  def pathname_should_have_x_entries(pathname, num)
    # Every entries.count expectation is inflated by 2, because of '.' and '..'
    expect(pathname.entries.count).to eq(num + 2)
  end

  def pathname_should_have_files(*files)
    existing_files = pathname.entries.map(&:to_s)
    files.each |file| do
      expect(existing_files.include?(file)).to be(true)
  end5
  describe "#sync" do

    before(:all) { Synxronize::Project.open(dummy_synx_project_path).sync }

    let(:expected_structure) do
      [
        {
        "dummy" => 
          [
          ]
        },
        {
        "dummyTests" =>
          [
          ]
        },
        "dummy.xcodeproj",
        {
        "Products" =>
          []
        }
      ]
    end

    it "should have the correct physical file structure" do
      pathname_should_have_x_entries(dummy_synx_pathname, 3)
      dummy_dummy = dummy_synx_pathname + 'dummy'
      pathname_should_have_x_entries(dummy_dummy, 5)
      

      dummy_dummyTests = dummy_synx_pathname + 'dummyTests'

      dummy_Products = dummy_synx_pathname + 'Products'
      pathname_should_have_x_entries(dummy_Products, 0)

    end

    it "should not have modified the Xcode group structure" do
    end

    it "should have updated the pch and info.plist build setting paths" do
    end
  end

  describe "#root_pathname" do

    it "should return the pathname to the directory that the .pbxproj file is inside" do
      expected = Pathname(File.join(File.dirname(__FILE__), '..', 'dummy'))
      dummy_synx_project.send(:root_pathname).realpath.should eq(expected.realpath)
    end
  end

  describe "#work_root_pathname" do

    it "should return the pathname to the directory synxchronize will do its work in" do
      expected = Pathname(Synxronize::Project.const_get(:SYNXRONIZE_DIR)) + "dummy"
      dummy_synx_project.send(:work_root_pathname).realpath.should eq(expected.realpath)
    end

    it "should start fresh by removing any existing directory at work_root_pathname" do
      Pathname.any_instance.stub(:exist?).and_return(true)
      expect(FileUtils).to receive(:rm_rf)

      dummy_synx_project.send(:work_root_pathname)
    end

    it "should create a directory at work_root_pathname" do
      expect_any_instance_of(Pathname).to receive(:mkpath)
      dummy_synx_project.send(:work_root_pathname)
    end

    it "should be an idempotent operation but return the same value through memoization" do
      pathname = dummy_synx_project.send(:work_root_pathname)
      expect(FileUtils).to_not receive(:rm_rf)
      expect_any_instance_of(Pathname).to_not receive(:exist?)
      expect_any_instance_of(Pathname).to_not receive(:mkpath)
      expect(dummy_synx_project.send(:work_root_pathname)).to be(pathname)
    end
  end

  describe "#pathname_to_work_pathname" do

    it "should return the path in work_root_pathname that is relatively equivalent to root_pathname" do
      pathname = dummy_synx_project.send(:root_pathname) + "some" + "path" + "to" + "thing"

      value = dummy_synx_project.send(:pathname_to_work_pathname, pathname)
      expected = dummy_synx_project.send(:work_root_pathname) + "some" + "path" + "to" + "thing"

      expect(value).to eq(expected)
    end
  end
end<commit_msg>copy over dummy into another directory, and then blow it away on the tear down, to avoid dirtying the git index.<commit_after>require File.join(File.dirname(__FILE__), '..', 'spec_helper')

require 'fileutils'
require 'pathname'
require 'yaml'


describe Synxronize::Project do

  DUMMY_SYNX_PATH = File.join(File.dirname(__FILE__), '..', 'dummy')
  DUMMY_SYNX_TEST_PATH = File.join(File.dirname(__FILE__), '..', 'test_dummy'))
  DUMMY_SYNX_TEST_PROJECT_PATH = File.join(DUMMY_SYNX_TEST_PATH, 'dummy.xcodeproj')

  before(:all) do
    FileUtils.rm_rf(DUMMY_SYNX_TEST_PATH)
    FileUtils.cp_r(DUMMY_SYNX_PATH, DUMMY_SYNX_TEST_PATH)
    DUMMY_SYNX_TEST_PROJECT = Synxronize::Project.open(DUMMY_SYNX_TEST_PROJECT_PATH)
  end

  after(:all) do
    FileUtils.rm_rf(DUMMY_SYNX_TEST_PATH)
  end

  describe "#sync" do

    before(:all) do 
      DUMMY_SYNX_TEST_PROJECT.sync
    end

    it "should have the correct physical file structure" do
      def verify_file_structure(dir_pathname, expected_structure)
        expected_structure.each do |entry_name, entry_entries|
          entry_pathname = dir_pathname + entry_name
          expect(File.exist?(entry_pathname) || Dir.exists?(entry_pathname)).to be(true), "Expected #{entry_pathname} to exist"

          if File.directory?(entry_pathname)
            entry_entries ||= {}
            # '.' and '..' show up in entries, so add 2
            failure_message = "Expected #{entry_pathname} to have #{entry_entries.count} children, found #{entry_pathname.entries.count - 2}"
            expect(entry_entries.count + 2).to eq(entry_pathname.entries.count), failure_message
            verify_file_structure(entry_pathname, entry_entries) if entry_entries.count > 0
          end
        end
      end

      expected_file_structure = YAML::load_file(File.join(File.dirname(__FILE__), "expected_file_structure.yml"))
      verify_file_structure(Pathname(DUMMY_SYNX_TEST_PROJECT_PATH).parent, expected_file_structure)

    end

    it "should not have modified the Xcode group structure" do
    end

    it "should have updated the pch and info.plist build setting paths" do
    end
  end

  describe "#root_pathname" do

    it "should return the pathname to the directory that the .pbxproj file is inside" do
      expected = Pathname(File.join(File.dirname(__FILE__), '..', 'dummy'))
      DUMMY_SYNX_TEST_PROJECT.send(:root_pathname).realpath.should eq(expected.realpath)
    end
  end

  describe "#work_root_pathname" do

    it "should return the pathname to the directory synxchronize will do its work in" do
      expected = Pathname(Synxronize::Project.const_get(:SYNXRONIZE_DIR)) + "dummy"
      DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname).realpath.should eq(expected.realpath)
    end

    it "should start fresh by removing any existing directory at work_root_pathname" do
      Pathname.any_instance.stub(:exist?).and_return(true)
      expect(FileUtils).to receive(:rm_rf)

      DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname)
    end

    it "should create a directory at work_root_pathname" do
      expect_any_instance_of(Pathname).to receive(:mkpath)
      DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname)
    end

    it "should be an idempotent operation but return the same value through memoization" do
      pathname = DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname)
      expect(FileUtils).to_not receive(:rm_rf)
      expect_any_instance_of(Pathname).to_not receive(:exist?)
      expect_any_instance_of(Pathname).to_not receive(:mkpath)
      expect(DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname)).to be(pathname)
    end
  end

  describe "#pathname_to_work_pathname" do

    it "should return the path in work_root_pathname that is relatively equivalent to root_pathname" do
      pathname = DUMMY_SYNX_TEST_PROJECT.send(:root_pathname) + "some" + "path" + "to" + "thing"

      value = DUMMY_SYNX_TEST_PROJECT.send(:pathname_to_work_pathname, pathname)
      expected = DUMMY_SYNX_TEST_PROJECT.send(:work_root_pathname) + "some" + "path" + "to" + "thing"

      expect(value).to eq(expected)
    end
  end
end
{'fraction_non_alphanumeric': 0.09496124031007752, 'fraction_numerical': 0.0012919896640826874, 'mean_word_length': 3.763692307692308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '645100', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2534, 'n_words': 538}