Sha256: 76b937308bf1acef2cd2bec831f4b691fe5eac3cf83c7328d0f75b6e9a49d8e4

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

# encoding: UTF-8

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

require 'spec_helper'

include TwitterCldr::Utils

describe RegexpAst do
  let(:ast) do
    RegexpAst::Root.new(
      [RegexpAst::Literal.new([], nil, 'foobar')], nil
    )
  end

  let(:ast_dump) do
    "BAhvOihUd2l0dGVyQ2xkcjo6VXRpbHM6OlJlZ2V4cEFzdDo6Um9vdAc6EUBl\n" +
    "eHByZXNzaW9uc1sGbzorVHdpdHRlckNsZHI6OlV0aWxzOjpSZWdleHBBc3Q6\n" +
    "OkxpdGVyYWwIOgpAdGV4dEkiC2Zvb2JhcgY6BkVUOwZbADoQQHF1YW50aWZp\n" +
    "ZXIwOwow\n"
  end

  def check_ast(obj)
    expect(obj).to be_a(RegexpAst::Root)
    expr = obj.expressions.first
    expect(expr).to be_a(RegexpAst::Literal)
    expect(expr.text).to eq('foobar')
  end

  describe "#dump" do
    it "should correctly serialize the ast" do
      obj = Marshal.load(Base64.decode64(RegexpAst.dump(ast)))
      check_ast(obj)
    end
  end

  describe "#load" do
    it "should load the dumped ast and construct a valid object" do
      obj = RegexpAst.load(ast_dump)
      check_ast(obj)
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/utils/regexp_ast_spec.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.5 spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.4 spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.3 spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.2 spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.1 spec/utils/regexp_ast_spec.rb
twitter_cldr-4.4.0 spec/utils/regexp_ast_spec.rb