<commit_before># -*- coding: utf-8 -*-
require File.expand_path('../../watirspec_helper', __FILE__)

describe 'Preferences' do

  before :all do
    @prefs = browser.preferences
  end

  describe '#new' do
    it 'constructs a new instance' do
      @prefs.should exist
      @prefs.should be_kind_of OperaWatir::Preferences
    end
  end

  describe '#each' do
    it 'contains a list of entries' do
      @prefs.each do |p|
        p.should be_kind_of OperaWatir::Preferences::Entry
      end
    end
  end

  describe '#length' do
    it 'has a valid length' do
      @prefs.length.should be_kind_of Integer
    end

    it 'has several sections' do
      @prefs.length.should > 10
    end

    it 'responds to alias #size' do
      @prefs.size.should == @prefs.length
    end
  end

  describe '#first' do
    it 'is a valid entry' do
      @prefs.first.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'is a section' do
      @prefs.first.should be_section
    end

    it 'has a key' do
      @prefs.first.key.should_not be_empty
    end

    it 'has a method' do
      @prefs.first.method.should match /^([a-z_]+)/
    end
  end

  describe '#last' do
    it 'is a valid entry' do
      @prefs.last.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'is a section' do
      @prefs.last.should be_section
    end

    it 'has a key' do
      @prefs.last.key.should_not be_empty
    end

    it 'has a method' do
      @prefs.last.method.should match /^([a-z_]+)/
    end
  end

  describe '#empty?' do
    it 'returns a valid type' do
      @prefs.empty?.should be_kind_of FalseClass
    end

    it 'is not empty' do
      @prefs.should_not be_empty
    end
  end

  describe '#to_s' do
    before :all do
      @string = @prefs.to_s
    end

    it 'returns a string' do
      @string.should be_kind_of String
    end

    it 'contains sections' do
      @string.should match /^([a-z_]+)/
    end

    it 'contains keys' do
      @string.should match /^\s{2}([a-z_]+)/
    end

    it 'contains values' do
      @string.should match /^\s{4}value:.+\"(.+)\"/
    end

    it 'contains defaults' do
      @string.should match /^\s{4}default:.+\"(.+)\"/
    end
  end

  describe '#to_h' do
    before :all do
      @hash = @prefs.to_h
    end

    it 'returns a hash' do
      @hash.should be_kind_of Hash
    end

    it 'returns entries of the type Preference' do
      @hash[0].parent.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'has several entries' do
      @hash.size > 10
    end

    it 'contains keys' do
      @hash[0].key.should_not be_empty
      @hash[0].method.should match /([a-z_]+)/
    end<commit_msg>Prefs object is an array, not a hash any more<commit_after># -*- coding: utf-8 -*-
require File.expand_path('../../watirspec_helper', __FILE__)

describe 'Preferences' do

  before :all do
    @prefs = browser.preferences
  end

  describe '#new' do
    it 'constructs a new instance' do
      @prefs.should exist
      @prefs.should be_kind_of OperaWatir::Preferences
    end
  end

  describe '#each' do
    it 'contains a list of entries' do
      @prefs.each do |p|
        p.should be_kind_of OperaWatir::Preferences::Entry
      end
    end
  end

  describe '#length' do
    it 'has a valid length' do
      @prefs.length.should be_kind_of Integer
    end

    it 'has several sections' do
      @prefs.length.should > 10
    end

    it 'responds to alias #size' do
      @prefs.size.should == @prefs.length
    end
  end

  describe '#first' do
    it 'is a valid entry' do
      @prefs.first.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'is a section' do
      @prefs.first.should be_section
    end

    it 'has a key' do
      @prefs.first.key.should_not be_empty
    end

    it 'has a method' do
      @prefs.first.method.should match /^([a-z_]+)/
    end
  end

  describe '#last' do
    it 'is a valid entry' do
      @prefs.last.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'is a section' do
      @prefs.last.should be_section
    end

    it 'has a key' do
      @prefs.last.key.should_not be_empty
    end

    it 'has a method' do
      @prefs.last.method.should match /^([a-z_]+)/
    end
  end

  describe '#empty?' do
    it 'returns a valid type' do
      @prefs.empty?.should be_kind_of FalseClass
    end

    it 'is not empty' do
      @prefs.should_not be_empty
    end
  end

  describe '#to_s' do
    before :all do
      @string = @prefs.to_s
    end

    it 'returns a string' do
      @string.should be_kind_of String
    end

    it 'contains sections' do
      @string.should match /^([a-z_]+)/
    end

    it 'contains keys' do
      @string.should match /^\s{2}([a-z_]+)/
    end

    it 'contains values' do
      @string.should match /^\s{4}value:.+\"(.+)\"/
    end

    it 'contains defaults' do
      @string.should match /^\s{4}default:.+\"(.+)\"/
    end
  end

  describe '#to_h' do
    before :all do
      @hash = @prefs.to_h
    end

    it 'returns a hash' do
      @hash.should be_kind_of Array
    end

    it 'returns entries of the type Preference' do
      @hash[0].parent.should be_kind_of OperaWatir::Preferences::Entry
    end

    it 'has several entries' do
      @hash.size > 10
    end

    it 'contains keys' do
      @hash[0].key.should_not be_empty
      @hash[0].method.should match /([a-z_]+)/
    end
{'fraction_non_alphanumeric': 0.11160631383472609, 'fraction_numerical': 0.004085422469823584, 'mean_word_length': 2.205952380952381, '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': '2221210', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1835, 'n_words': 568}