Sha256: b6fd9e8525bf22878de599d83dba1ca4eb8da98bfbee1f2cb8a72bc2cb836afb

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe Analects::CedictLoader do
  let ( :contents ) do
    '# CC-CEDICT
# Community maintained free Chinese-English dictionary.
#
#! charset=UTF-8
#! entries=104941
佰 佰 [bai3] /hundred (banker\'s anti-fraud numeral)/
佱 佱 [fa3] /old variant of 法[fa3]/law/
佳 佳 [jia1] /beautiful/fine/good/
'
  end

  let ( :cedict_loader ) { Analects::CedictLoader.new( StringIO.new(contents), nil ) }

  it "should parse headers" do
    cedict_loader.headers.should == { 'charset' => 'UTF-8', 'entries' => '104941' }
  end

  it "should parse entries" do
    cedict_loader.take(1).should == [ ['佰', '佰', 'bai3', '/hundred (banker\'s anti-fraud numeral)/' ] ]
  end

  it "can be enumerated multiple times" do
    2.times do
      cedict_loader.each do |x|
        x.should == ['佰', '佰', 'bai3', '/hundred (banker\'s anti-fraud numeral)/' ]
        break;
      end
    end
  end

  it "is an enumerable" do
    cedict_loader.count.should === 3
    cedict_loader.to_a.should be_instance_of( Array )
    cedict_loader.map {|x| x.size.should === 4 }
  end

  if RUBY_VERSION.split('.').take(2).join('.').to_f >= 1.9
    it "returns an enumerator when each is called without block" do
      cedict_loader.each.is_a? Enumerator
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
analects-0.4.2 spec/analects/cedict_loader_spec.rb
analects-0.4.1 spec/analects/cedict_loader_spec.rb
analects-0.4.0 spec/analects/cedict_loader_spec.rb
analects-0.3.1 spec/analects/cedict_loader_spec.rb