<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

require 'java' if RUBY_PLATFORM == 'java'

describe "CascadingProperties" do
  valid_source1 = <<-EOS
    compiler {
      error {
        message {
          varNotFound "variable not found"
          incompatibleType "incompatible type"
        }
      }
      maxReport 10
      files {
        input.encoding "SJIS"
        output.encoding  "UTF-8"
      }
    }
  EOS

  shared_examples_for "loadin valid_source1" do
    describe "root" do
      subject{ @root }
      its(:compiler){ should be_a(CascadingProperties::Node)}

      if RUBY_PLATFORM == 'java'
        it "should export to java.util.Properties" do
          props = subject.to_properties
          props.should be_a(java.util.Properties)
          props.size().should == 5
          props.getProperty("compiler.error.message.varNotFound"     ).should == "variable not found"
          props.getProperty("compiler.error.message.incompatibleType").should == "incompatible type"
          props.getProperty("compiler.maxReport").should == '10'
          props.getProperty("compiler.files.input.encoding").should == 'SJIS'
          props.getProperty("compiler.files.output.encoding").should == 'UTF-8'
        end
      else
        it "should raise NotImplementedError" do
          expect{ subject.to_properties }.to raise_error(NotImplementedError)
        end
      end
    end

    describe "compiler" do
      subject{ @root.compiler }
      its(:error){ should be_a(CascadingProperties::Node)}
      its(:maxReport){ should == 10}
      its(:files){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.error" do
      subject{ @root.compiler.error }
      its(:message){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.error.message" do
      subject{ @root.compiler.error.message }
      its(:varNotFound){ should == "variable not found"}
      its(:incompatibleType){ should == "incompatible type"}
    end

    describe "compiler.files" do
      subject{ @root.compiler.files }
      its(:input){ should be_a(CascadingProperties::Node)}
      its(:output){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.files.input" do
      subject{ @root.compiler.files.input }
      its(:encoding){ should == "SJIS" }
    end
    describe "compiler.files.output" do
      subject{ @root.compiler.files.output }
      its(:encoding){ should == "UTF-8" }
    end
  end

  describe :load do
    before do
      @root = CascadingProperties.load(valid_source1)
    end
    it_should_behave_like "loadin valid_source1"
  end

  describe :load_file do
    context 'basic1.rb' do
      before do
        path = File.expand_path('../examples/basic1.rb', File.dirname(__FILE__))
        @root = CascadingProperties.load_file(path)
      end
      it_should_behave_like "loadin valid_source1"
    end

    context 'with_erb.rb' do
      before do
        ENV['MAX_REPORT'] = '10'
        path = File.expand_path('../examples/with_erb.rb', File.dirname(__FILE__))
        @root = CascadingProperties.load_file(path)
      end
      it_should_behave_like "loadin valid_source1"
    end

  end
end
<commit_msg>insert "valid environment variable" context before add "invalid environment variable" context<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

require 'java' if RUBY_PLATFORM == 'java'

describe "CascadingProperties" do
  valid_source1 = <<-EOS
    compiler {
      error {
        message {
          varNotFound "variable not found"
          incompatibleType "incompatible type"
        }
      }
      maxReport 10
      files {
        input.encoding "SJIS"
        output.encoding  "UTF-8"
      }
    }
  EOS

  shared_examples_for "loadin valid_source1" do
    describe "root" do
      subject{ @root }
      its(:compiler){ should be_a(CascadingProperties::Node)}

      if RUBY_PLATFORM == 'java'
        it "should export to java.util.Properties" do
          props = subject.to_properties
          props.should be_a(java.util.Properties)
          props.size().should == 5
          props.getProperty("compiler.error.message.varNotFound"     ).should == "variable not found"
          props.getProperty("compiler.error.message.incompatibleType").should == "incompatible type"
          props.getProperty("compiler.maxReport").should == '10'
          props.getProperty("compiler.files.input.encoding").should == 'SJIS'
          props.getProperty("compiler.files.output.encoding").should == 'UTF-8'
        end
      else
        it "should raise NotImplementedError" do
          expect{ subject.to_properties }.to raise_error(NotImplementedError)
        end
      end
    end

    describe "compiler" do
      subject{ @root.compiler }
      its(:error){ should be_a(CascadingProperties::Node)}
      its(:maxReport){ should == 10}
      its(:files){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.error" do
      subject{ @root.compiler.error }
      its(:message){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.error.message" do
      subject{ @root.compiler.error.message }
      its(:varNotFound){ should == "variable not found"}
      its(:incompatibleType){ should == "incompatible type"}
    end

    describe "compiler.files" do
      subject{ @root.compiler.files }
      its(:input){ should be_a(CascadingProperties::Node)}
      its(:output){ should be_a(CascadingProperties::Node)}
    end
    describe "compiler.files.input" do
      subject{ @root.compiler.files.input }
      its(:encoding){ should == "SJIS" }
    end
    describe "compiler.files.output" do
      subject{ @root.compiler.files.output }
      its(:encoding){ should == "UTF-8" }
    end
  end

  describe :load do
    before do
      @root = CascadingProperties.load(valid_source1)
    end
    it_should_behave_like "loadin valid_source1"
  end

  describe :load_file do
    context 'basic1.rb' do
      before do
        path = File.expand_path('../examples/basic1.rb', File.dirname(__FILE__))
        @root = CascadingProperties.load_file(path)
      end
      it_should_behave_like "loadin valid_source1"
    end

    context 'with_erb.rb' do
      context "valid environment variable" do
        before do
          ENV['MAX_REPORT'] = '10'
          path = File.expand_path('../examples/with_erb.rb', File.dirname(__FILE__))
          @root = CascadingProperties.load_file(path)
        end
        it_should_behave_like "loadin valid_source1"
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.11060329067641682, 'fraction_numerical': 0.006093845216331505, 'mean_word_length': 2.7195467422096318, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3847730', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1936, 'n_words': 426}