Sha256: c25f812dd9730ec6bd1922084645f37478811070904990f1e8d8086233ef0ac4

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'
require 'ffi/hunspell/dictionary'

describe Hunspell::Dictionary do
  subject { Hunspell::Dictionary }

  let(:lang) { 'en_US' }

  let(:affix_path) { File.join(Hunspell.directories.last,"#{lang}.aff") }
  let(:dic_path) { File.join(Hunspell.directories.last,"#{lang}.dic") }

  describe "#initialize" do
    subject { described_class }

    it "should create a dictionary from '.aff' and '.dic' files" do
      dict = subject.new(affix_path,dic_path)
      dict.should_not be_nil

      dict.close
    end
  end

  describe "open" do
    subject { described_class }

    it "should find and open a dictionary file for a given language" do
      subject.open(lang) do |dict|
        dict.should_not be_nil
      end
    end

    it "should close the dictionary" do
      dict = subject.open(lang)
      dict.close

      dict.should be_closed
    end
  end

  subject { described_class.new(affix_path,dic_path) }

  after(:all) { subject.close }

  it "should provide the encoding of the dictionary files" do
    subject.encoding.should_not be_empty
  end

  it "should check if a word is valid" do
    subject.should be_valid('dog')
    subject.should_not be_valid('dxg')
  end

  describe "#stem" do
    it "should find the stems of a word" do
      subject.stem('fishing').should == %w[fishing fish]
    end

    context "when there are no stems" do
      it "should return []" do
        subject.stem("zzzzzzz").should == []
      end
    end
  end

  describe "#suggest" do
    it "should suggest alternate spellings for words" do
      subject.suggest('arbitrage').should == %w[
        arbitrage
        arbitrages
        arbitrager
        arbitraged
        arbitrate
      ]
    end

    context "when there are no suggestions" do
      it "should return []" do
        subject.suggest("________").should == []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-hunspell-0.2.6 spec/dictionary_spec.rb