<commit_before>require File.dirname(__FILE__) + '/helper'

class ERBTest < Test::Unit::TestCase
  def erb_app(&block)
    mock_app {
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  it 'renders inline ERB strings' do
    erb_app { erb '<%= 1 + 1 %>' }
    assert ok?
    assert_equal '2', body
  end

  it 'renders .erb files in views path' do
    erb_app { erb :hello }
    assert ok?
    assert_equal "Hello World\n", body
  end

  it 'takes a :locals option' do
    erb_app {
      locals = {:foo => 'Bar'}
      erb '<%= foo %>', :locals => locals
    }
    assert ok?
    assert_equal 'Bar', body
  end

  it "renders with inline layouts" do
    mock_app {
      layout { 'THIS. IS. <%= yield.upcase %>!' }
      get('/') { erb 'Sparta' }
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "renders with file layouts" do
    erb_app {
      erb 'Hello World', :layout => :layout2
    }
    assert ok?
    assert_body "ERB Layout!\nHello World"
  end

  it "renders erb with blocks" do
    mock_app {
      def container
        @_out_buf << "THIS."
        yield
        @_out_buf << "SPARTA!"
      end
      def is; "IS." end
      get '/' do
        erb '<% container do %> <%= is %> <% end %>'
      end
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "can be used in a nested fashion for partials and whatnot" do
    mock_app {
      template(:inner) { "<inner><%= 'hi' %></inner>" }
      template(:outer) { "<outer><%= erb :inner %></outer>" }
      get '/' do
        erb :outer
      end
    }

    get '/'
    assert ok?
    assert_equal '<outer><inner>hi</inner></outer>', body
  end
end
<commit_msg>test both ERB and Erubis<commit_after>require File.dirname(__FILE__) + '/helper'

class ERBTest < Test::Unit::TestCase
  def engine
    Tilt::ERBTemplate
  end

  def setup
    Tilt.prefer engine, :erb
    super
  end

  def erb_app(&block)
    mock_app {
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  it 'uses the correct engine' do
    assert_equal engine, Tilt[:erb]
  end

  it 'renders inline ERB strings' do
    erb_app { erb '<%= 1 + 1 %>' }
    assert ok?
    assert_equal '2', body
  end

  it 'renders .erb files in views path' do
    erb_app { erb :hello }
    assert ok?
    assert_equal "Hello World\n", body
  end

  it 'takes a :locals option' do
    erb_app {
      locals = {:foo => 'Bar'}
      erb '<%= foo %>', :locals => locals
    }
    assert ok?
    assert_equal 'Bar', body
  end

  it "renders with inline layouts" do
    mock_app {
      layout { 'THIS. IS. <%= yield.upcase %>!' }
      get('/') { erb 'Sparta' }
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "renders with file layouts" do
    erb_app {
      erb 'Hello World', :layout => :layout2
    }
    assert ok?
    assert_body "ERB Layout!\nHello World"
  end

  it "renders erb with blocks" do
    mock_app {
      def container
        @_out_buf << "THIS."
        yield
        @_out_buf << "SPARTA!"
      end
      def is; "IS." end
      get '/' do
        erb '<% container do %> <%= is %> <% end %>'
      end
    }
    get '/'
    assert ok?
    assert_equal 'THIS. IS. SPARTA!', body
  end

  it "can be used in a nested fashion for partials and whatnot" do
    mock_app {
      template(:inner) { "<inner><%= 'hi' %></inner>" }
      template(:outer) { "<outer><%= erb :inner %></outer>" }
      get '/' do
        erb :outer
      end
    }

    get '/'
    assert ok?
    assert_equal '<outer><inner>hi</inner></outer>', body
  end
end


begin
  require 'erubis'
  class ErubisTest < ERBTest
    def engine; Tilt::ErubisTemplate end
  end
rescue LoadError
  warn "#{$!.to_s}: skipping erubis tests"
end

{'fraction_non_alphanumeric': 0.1388816644993498, 'fraction_numerical': 0.002080624187256177, 'mean_word_length': 2.11417004048583, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6840024', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1353, 'n_words': 414}