Sha256: 84b48cb540b9f4acef4be3dd69bae660015740ea7b12cd8a5912724f32d8ac4d

Contents?: true

Size: 1.37 KB

Versions: 17

Compression:

Stored size: 1.37 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'

include TwitterCldr::Parsers

class FakeParser < Parser
  def do_parse(options); end
end

describe Parser do
  let(:parser) { FakeParser.new }
  let(:tokens) do
    [
      Token.new(:type => :a, :value => "a"),
      Token.new(:type => :b, :value => "b"),
      Token.new(:type => :c, :value => "c")
    ]
  end

  describe "#parse" do
    it "should call do_parse" do
      mock(parser).do_parse({})
      parser.parse(tokens)
    end
  end

  describe "#reset" do
    it "should reset the token index" do
      parser.parse(tokens)
      parser.send(:next_token, :a)
      expect(parser.send(:current_token).type).to eq(:b)
      parser.reset
      expect(parser.send(:current_token).type).to eq(:a)
    end
  end

  describe "#next_token" do
    it "should advance to the next token" do
      parser.parse(tokens)
      parser.send(:next_token, :a)
      expect(parser.send(:current_token).type).to eq(:b)
    end

    it "should raise an error after encountering an unexpected token" do
      parser.parse(tokens)
      expect { parser.send(:next_token, :z) }.to raise_error(UnexpectedTokenError)
    end
  end

  describe "#current_token" do
    it "returns the current token" do
      parser.parse(tokens)
      expect(parser.send(:current_token).type).to eq(:a)
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/spec/parsers/parser_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/spec/parsers/parser_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/spec/parsers/parser_spec.rb
twitter_cldr-3.2.1 spec/parsers/parser_spec.rb
twitter_cldr-3.2.0 spec/parsers/parser_spec.rb
twitter_cldr-3.1.2 spec/parsers/parser_spec.rb
twitter_cldr-3.1.1 spec/parsers/parser_spec.rb
twitter_cldr-3.1.0 spec/parsers/parser_spec.rb
twitter_cldr-3.0.10 spec/parsers/parser_spec.rb
twitter_cldr-3.0.9 spec/parsers/parser_spec.rb
twitter_cldr-3.0.8 spec/parsers/parser_spec.rb
twitter_cldr-3.0.7 spec/parsers/parser_spec.rb
twitter_cldr-3.0.6 spec/parsers/parser_spec.rb
twitter_cldr-3.0.5 spec/parsers/parser_spec.rb
twitter_cldr-3.0.4 spec/parsers/parser_spec.rb
twitter_cldr-3.0.3 spec/parsers/parser_spec.rb
twitter_cldr-3.0.2 spec/parsers/parser_spec.rb