Sha256: b4235ee47d0858e9bc661a2fed1fb4e9d9f322a04cfe71cb1e79e8fdcb9df46c

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require 'helper'

describe Temple::StaticAnalyzer do
  describe '.available?' do
    it 'should return true if its dependency is available' do
      Temple::StaticAnalyzer.available?.should.equal(defined?(Ripper) && Ripper.respond_to?(:lex))
    end
  end

  if Temple::StaticAnalyzer.available?
    describe '.static?' do
      it 'should return true if given Ruby expression is static' do
        ['true', 'false', '"hello world"', "[1, { 2 => 3 }]", "[\n1,\n]"].each do |exp|
          Temple::StaticAnalyzer.static?(exp).should.equal(true)
        end
      end

      it 'should return false if given Ruby expression is dynamic' do
        ['1 + 2', 'variable', 'method_call(a)', 'CONSTANT'].each do |exp|
          Temple::StaticAnalyzer.static?(exp).should.equal(false)
        end
      end
    end

    describe '.syntax_error?' do
      it 'should return false if given Ruby expression is valid' do
        ['Foo.bar.baz { |c| c.d! }', '{ foo: bar }'].each do |exp|
          Temple::StaticAnalyzer.syntax_error?(exp).should.equal(false)
        end
      end

      it 'should return true if given Ruby expression is invalid' do
        ['Foo.bar.baz { |c| c.d! ', ' foo: bar '].each do |exp|
          Temple::StaticAnalyzer.syntax_error?(exp).should.equal(true)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/test_static_analyzer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/test_static_analyzer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/test/test_static_analyzer.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/temple-0.8.2/test/test_static_analyzer.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/temple-0.8.2/test/test_static_analyzer.rb
temple-0.9.0 test/test_static_analyzer.rb
temple-0.8.2 test/test_static_analyzer.rb