slim-4.0.1/ 0000755 0000041 0000041 00000000000 13411312757 012514 5 ustar www-data www-data slim-4.0.1/.travis.yml 0000644 0000041 0000041 00000001626 13411312757 014632 0 ustar www-data www-data # https://www.ruby-lang.org/en/downloads/releases/ language: ruby rvm: - 2.5.1 - 2.5.0 - 2.4.4 - 2.4.3 - jruby-9.2.0.0 - jruby-9.1.17.0 # Recommend sudo required when using trusty dist # https://docs.travis-ci.com/user/reference/trusty/ sudo: required dist: trusty script: "bundle exec rake $TASK" after_success: - bundle exec codeclimate-test-reporter env: global: # travis encrypt CODECLIMATE_REPO_TOKEN=??? - secure: "a7sD9iwPJJn3Fj+mn62GAmy/PEguh3elrilsp1KS+WfDiCiIKD8Q5KG2Jv67DGcQAGI3dPWeh7+ZhZ/W7nEipwWUBmSvGYVeoF63y8j6mNRLeekqspj94l47hXyFePj9bCadY1b1/xY4lE1pMEU8eA8AOUHUqCSuH+Kk/MuvyLM=" matrix: - "TASK=test:core_and_plugins" - "TASK=test:rails RAILS=5.2.0" - "TASK=test:rails RAILS=5.1.6" - "TASK=test:sinatra SINATRA=2.0.1" - "TASK=test:sinatra SINATRA=1.4.8" - "TASK=bench" - "TASK=bench slow=1" notifications: irc: "chat.freenode.net#slim-lang" slim-4.0.1/test/ 0000755 0000041 0000041 00000000000 13411312757 013473 5 ustar www-data www-data slim-4.0.1/test/logic_less/ 0000755 0000041 0000041 00000000000 13411312757 015616 5 ustar www-data www-data slim-4.0.1/test/logic_less/test_logic_less.rb 0000644 0000041 0000041 00000014525 13411312757 021334 0 ustar www-data www-data require 'helper' require 'slim/logic_less' class TestSlimLogicLess < TestSlim class Scope def initialize @hash = { person: [ { name: 'Joe', age: 1, selected: true }, { name: 'Jack', age: 2 } ] } end end def test_lambda source = %q{ p == person .name = name == simple .hello= hello == list li = key } hash = { hello: 'Hello!', person: lambda do |&block| %w(Joe Jack).map do |name| "#{block.call(name: name)}" end.join end, simple: lambda do |&block| "
No person No person 2
', source, scope: hash end def test_escaped_interpolation source = %q{ p text with \#{123} test } assert_html 'text with #{123} test
', source end def test_ruby_attributes source = %q{ p - person b name=name Person a id=name = age span class=name Person } assert_html '', source, scope: Scope.new, dictionary: '@hash' end def test_boolean_attributes source = %q{ p - person input checked=selected = name } assert_html 'JoeJack
', source, scope: Scope.new, dictionary: '@hash' end def test_sections source = %q{ p - person .name = name } assert_html 'Hello World
", body end it "raises error if template not found" do mock_app { get('/') { slim(:no_such_template) } } assert_raises(Errno::ENOENT) { get('/') } end HTML4_DOCTYPE = "" it "passes slim options to the slim engine" do mock_app { get('/') { slim("x foo='bar'", :attr_quote => "'") }} get '/' assert ok? assert_body "Contents.
\n" end end rescue LoadError warn "#{$!}: skipping slim tests" end slim-4.0.1/test/sinatra/helper.rb 0000644 0000041 0000041 00000006422 13411312757 016744 0 ustar www-data www-data if ENV['COVERAGE'] require 'simplecov' SimpleCov.start do add_filter '/test/' add_group 'sinatra-contrib', 'sinatra-contrib' add_group 'rack-protection', 'rack-protection' end end ENV['APP_ENV'] = 'test' Encoding.default_external = "UTF-8" if defined? Encoding RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE require 'rack' testdir = File.dirname(__FILE__) $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir) libdir = File.dirname(File.dirname(__FILE__)) + '/lib' $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir) require 'minitest' require 'contest' require 'rack/test' require 'sinatra' require 'sinatra/base' class Sinatra::Base include Minitest::Assertions # Allow assertions in request context def assertions @assertions ||= 0 end attr_writer :assertions end class Rack::Builder def include?(middleware) @ins.any? { |m| middleware === m } end end Sinatra::Base.set :environment, :test class Minitest::Test include Rack::Test::Methods class << self alias_method :it, :test alias_method :section, :context end def self.example(desc = nil, &block) @example_count = 0 unless instance_variable_defined? :@example_count @example_count += 1 it(desc || "Example #{@example_count}", &block) end alias_method :response, :last_response setup do Sinatra::Base.set :environment, :test end # Sets up a Sinatra::Base subclass defined with the block # given. Used in setup or individual spec methods to establish # the application. def mock_app(base=Sinatra::Base, &block) @app = Sinatra.new(base, &block) end def app Rack::Lint.new(@app) end def slim_app(&block) mock_app do set :views, File.dirname(__FILE__) + '/views' get('/', &block) end get '/' end def body response.body.to_s end def assert_body(value) if value.respond_to? :to_str assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "") else assert_match value, body end end def assert_status(expected) assert_equal Integer(expected), Integer(status) end def assert_like(a,b) pattern = /id=['"][^"']*["']|\s+/ assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "") end def assert_include(str, substr) assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}" end def options(uri, params = {}, env = {}, &block) request(uri, env.merge(:method => "OPTIONS", :params => params), &block) end def patch(uri, params = {}, env = {}, &block) request(uri, env.merge(:method => "PATCH", :params => params), &block) end def link(uri, params = {}, env = {}, &block) request(uri, env.merge(:method => "LINK", :params => params), &block) end def unlink(uri, params = {}, env = {}, &block) request(uri, env.merge(:method => "UNLINK", :params => params), &block) end # Delegate other missing methods to response. def method_missing(name, *args, &block) if response && response.respond_to?(name) response.send(name, *args, &block) else super end rescue Rack::Test::Error super end # Do not output warnings for the duration of the block. def silence_warnings $VERBOSE, v = nil, $VERBOSE yield ensure $VERBOSE = v end end slim-4.0.1/test/sinatra/contest.rb 0000644 0000041 0000041 00000006245 13411312757 017147 0 ustar www-data www-data # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require "rubygems" require "minitest/autorun" # Contest adds +teardown+, +test+ and +context+ as class methods, and the # instance methods +setup+ and +teardown+ now iterate on the corresponding # blocks. Note that all setup and teardown blocks must be defined with the # block syntax. Adding setup or teardown instance methods defeats the purpose # of this library. class Minitest::Test def self.setup(&block) setup_blocks << block end def self.teardown(&block) teardown_blocks << block end def self.setup_blocks() @setup_blocks ||= [] end def self.teardown_blocks() @teardown_blocks ||= [] end def setup_blocks(base = self.class) setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks base.setup_blocks.each do |block| instance_eval(&block) end end def teardown_blocks(base = self.class) teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks base.teardown_blocks.each do |block| instance_eval(&block) end end alias setup setup_blocks alias teardown teardown_blocks def self.context(*name, &block) subclass = Class.new(self) remove_tests(subclass) subclass.class_eval(&block) if block_given? const_set(context_name(name.join(" ")), subclass) end def self.test(name, &block) define_method(test_name(name), &block) end class << self alias_method :should, :test alias_method :describe, :context end private def self.context_name(name) # "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}" name.tr(" ", "_").to_sym end def self.test_name(name) name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0" name = name.succ while method_defined? name name.to_sym end def self.sanitize_name(name) # name.gsub(/\W+/, ' ').strip name.gsub(/\W+/, ' ') end def self.remove_tests(subclass) subclass.public_instance_methods.grep(/^test_/).each do |meth| subclass.send(:undef_method, meth.to_sym) end end end slim-4.0.1/test/sinatra/test_include.rb 0000644 0000041 0000041 00000000727 13411312757 020151 0 ustar www-data www-data require 'slim/include' require_relative 'helper.rb' begin class SlimTest < Minitest::Test it 'renders .slim files includes with js embed' do slim_app { slim :embed_include_js } assert ok? assert_equal "1337
', source end def test_ternary_operation_in_attribute_2 source = %q{ p id=(false ? 'notshown' : 'shown') = output_number } assert_html '1337
', source end def test_class_attribute_merging source = %{ .alpha class="beta" Test it } assert_html '1337
', source end def test_dynamic_empty_attribute source = %q{ p(id="marvin" class=nil nonempty=("".to_s) data-info="Illudium Q-36")= output_number } assert_html '1337
', source end def test_weird_attribute source = %q{ p img(src='img.png' whatsthis?!) img src='img.png' whatsthis?!="wtf" } assert_html 'Hello World, meet Slim.
', source end def test_relaxed_indentation_of_first_line source = %q{ p .content } assert_html "", source end def test_html_tag_with_text_and_empty_line source = %q{ p Hello p World } assert_html "Hello
World
", source end def test_html_namespaces source = %q{ html:body html:p html:id="test" Text } assert_html 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
', source end def test_render_with_text_block_with_subsequent_markup source = %q{ p | Lorem ipsum dolor sit amet, consectetur adipiscing elit. p Some more markup } assert_html 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Some more markup
', source end def test_render_with_text_block_with_trailing_whitespace source = %q{ ' this is a link to a href="link" page } assert_html "this is\na link to page", source end def test_nested_text source = %q{ p | This is line one. This is line two. This is line three. This is line four. p This is a new paragraph. } assert_html "This is line one.\n This is line two.\n This is line three.\n This is line four.
This is a new paragraph.
", source end def test_nested_text_with_nested_html_one_same_line source = %q{ p | This is line one. This is line two. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.This is a bold line in the paragraph. This is more content.
", source end def test_nested_text_with_nested_html_one_same_line2 source = %q{ p |This is line one. This is line two. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.This is a bold line in the paragraph. This is more content.
", source end def test_nested_text_with_nested_html source = %q{ p | This is line one. This is line two. This is line three. This is line four. span.bold This is a bold line in the paragraph. | This is more content. } assert_html "This is line one.\n This is line two.\n This is line three.\n This is line four.This is a bold line in the paragraph. This is more content.
", source end def test_simple_paragraph_with_padding source = %q{ p There will be 3 spaces in front of this line. } assert_html 'There will be 3 spaces in front of this line.
', source end def test_paragraph_with_nested_text source = %q{ p This is line one. This is line two. } assert_html "This is line one.\n This is line two.
", source end def test_paragraph_with_padded_nested_text source = %q{ p This is line one. This is line two. } assert_html "This is line one.\n This is line two.
", source end def test_paragraph_with_attributes_and_nested_text source = %q{ p#test class="paragraph" This is line one. This is line two. } assert_html "This is line one.\nThis is line two.
", source end def test_relaxed_text_indentation source = %q{ p | text block text line3 } assert_html "text block\ntext\n line3
", source end def test_output_code_with_leading_spaces source = %q{ p= hello_world p = hello_world p = hello_world } assert_html 'Hello World from @env
Hello World from @env
Hello World from @env
', source end def test_single_quoted_attributes source = %q{ p class='underscored_class_name' = output_number } assert_html '1337
', source end def test_nonstandard_attributes source = %q{ p id="dashed-id" class="underscored_class_name" = output_number } assert_html '1337
', source end def test_nonstandard_shortcut_attributes source = %q{ p#dashed-id.underscored_class_name = output_number } assert_html '1337
', source end def test_dashed_attributes source = %q{ p data-info="Illudium Q-36" = output_number } assert_html '1337
', source end def test_dashed_attributes_with_shortcuts source = %q{ p#marvin.martian data-info="Illudium Q-36" = output_number } assert_html '1337
', source end def test_parens_around_attributes source = %q{ p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number } assert_html '1337
', source end def test_square_brackets_around_attributes source = %q{ p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number } assert_html '1337
', source end def test_parens_around_attributes_with_equal_sign_snug_to_right_paren source = %q{ p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number } assert_html '1337
', source end def test_default_attr_delims_option source = %q{ p1337
', str end end def test_custom_attr_delims_option source = %q{ p { foo="bar" } } assert_html '', source assert_html '', source, attr_list_delims: {'{' => '}'} assert_html '{ foo="bar" }
', source, attr_list_delims: {'(' => ')', '[' => ']'} end def test_closed_tag source = %q{ closed/ } assert_html '< x=(1+1) > Hello
', source assert_html '< x=(1+1) > Hello
', source, attr_list_delims: {'{' => '}'} assert_html '{ foo="bar" x=(1+1) }
Hello
', source, attr_list_delims: {'<' => '>'}, code_attr_delims: { '(' => ')' } end def test_attributs_with_parens_and_spaces source = %q{label{ for='filter' }= hello_world} assert_html '', source end def test_attributs_with_parens_and_spaces2 source = %q{label{ for='filter' } = hello_world} assert_html '', source end def test_attributs_with_multiple_spaces source = %q{label for='filter' class="test" = hello_world} assert_html '', source end def test_closed_tag_with_attributes source = %q{ closed id="test" / } assert_html 'Hello
World
", source end def test_render_with_html_conditional_and_tag source = %q{ /[ if IE ] p Get a better browser. } assert_html "", source end def test_render_with_html_conditional_and_method_output source = %q{ /[ if IE ] = message 'hello' } assert_html "", source end def test_multiline_attributes_with_method source = %q{ p1337
', str end end def test_multiline_attributes_with_text_on_same_line source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_text source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_dynamic_attr source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_tag source = %q{ pTHE space modulator
', str end end def test_multiline_attributes_with_nested_text_and_extra_indentation source = %q{ li< id="myid" class="myclass" data-info="myinfo"> a href="link" My Link } Slim::Parser.options[:attr_list_delims].each do |k,v| str = source.sub('<',k).sub('>',v) assert_html '#{hello_world}
span = hello_world } assert_html 'Hello World from @env
Hello World from @env', source end end slim-4.0.1/test/core/helper.rb 0000644 0000041 0000041 00000007664 13411312757 016244 0 ustar www-data www-data begin require 'simplecov' SimpleCov.start rescue LoadError end require 'minitest/autorun' require 'slim' require 'slim/grammar' Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Grammar Slim::Engine.before :Pretty, Temple::Filters::Validator class TestSlim < Minitest::Test def setup @env = Env.new end def render(source, options = {}, &block) scope = options.delete(:scope) locals = options.delete(:locals) Slim::Template.new(options[:file], options) { source }.render(scope || @env, locals, &block) end class HtmlSafeString < String def html_safe? true end def to_s self end end def with_html_safe String.send(:define_method, :html_safe?) { false } String.send(:define_method, :html_safe) { HtmlSafeString.new(self) } yield ensure String.send(:undef_method, :html_safe?) if String.method_defined?(:html_safe?) String.send(:undef_method, :html_safe) if String.method_defined?(:html_safe) end def assert_html(expected, source, options = {}, &block) assert_equal expected, render(source, options, &block) end def assert_syntax_error(message, source, options = {}) render(source, options) raise 'Syntax error expected' rescue Slim::Parser::SyntaxError => ex assert_equal message, ex.message message =~ /([^\s]+), Line (\d+)/ assert_backtrace ex, "#{$1}:#{$2}" end def assert_ruby_error(error, from, source, options = {}) render(source, options) raise 'Ruby error expected' rescue error => ex assert_backtrace(ex, from) end def assert_backtrace(ex, from) if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' # HACK: Rubinius stack trace sometimes has one entry more if ex.backtrace[0] !~ /^#{Regexp.escape from}/ ex.backtrace[1] =~ /([^\s]+:\d+)/ assert_equal from, $1 end else ex.backtrace[0] =~ /([^\s]+:\d+)/ assert_equal from, $1 end end def assert_ruby_syntax_error(from, source, options = {}) render(source, options) raise 'Ruby syntax error expected' rescue SyntaxError => ex ex.message =~ /([^\s]+:\d+):/ assert_equal from, $1 end def assert_runtime_error(message, source, options = {}) render(source, options) raise Exception, 'Runtime error expected' rescue RuntimeError => ex assert_equal message, ex.message end end class Env attr_reader :var, :x def initialize @var = 'instance' @x = 0 end def id_helper "notice" end def hash {a: 'The letter a', b: 'The letter b'} end def show_first?(show = false) show end def define_macro(name, &block) @macro ||= {} @macro[name.to_s] = block '' end def call_macro(name, *args) @macro[name.to_s].call(*args) end def hello_world(text = "Hello World from @env", opts = {}) text << opts.to_a * " " if opts.any? if block_given? "#{text} #{yield} #{text}" else text end end def message(*args) args.join(' ') end def action_path(*args) "/action-#{args.join('-')}" end def in_keyword "starts with keyword" end def evil_method "" end def output_number 1337 end def succ_x @x = @x.succ end end class ViewEnv def output_number 1337 end def person [{name: 'Joe'}, {name: 'Jack'}] end def people %w(Andy Fred Daniel).collect{|n| Person.new(n)} end def cities %w{Atlanta Melbourne Karlsruhe} end def people_with_locations array = [] people.each_with_index do |p,i| p.location = Location.new cities[i] array << p end array end end require 'forwardable' class Person extend Forwardable attr_accessor :name def initialize(name) @name = name end def location=(location) @location = location end def_delegators :@location, :city end class Location attr_accessor :city def initialize(city) @city = city end end slim-4.0.1/test/core/test_parser_errors.rb 0000644 0000041 0000041 00000006766 13411312757 020716 0 ustar www-data www-data require 'helper' class TestParserErrors < TestSlim def test_correct_filename source = %q{ doctype 5 div Invalid } assert_syntax_error "Unexpected indentation\n test.slim, Line 3, Column 2\n div Invalid\n ^\n", source, file: 'test.slim' end def test_unexpected_indentation source = %q{ doctype 5 div Invalid } assert_syntax_error "Unexpected indentation\n (__TEMPLATE__), Line 3, Column 2\n div Invalid\n ^\n", source end def test_malformed_indentation source = %q{ p div Valid div Invalid } assert_syntax_error "Malformed indentation\n (__TEMPLATE__), Line 4, Column 1\n div Invalid\n ^\n", source end def test_malformed_indentation2 source = %q{ div Valid div Invalid } assert_syntax_error "Malformed indentation\n (__TEMPLATE__), Line 3, Column 1\n div Invalid\n ^\n", source end def test_unknown_line_indicator source = %q{ p div Valid .valid #valid ?invalid } assert_syntax_error "Unknown line indicator\n (__TEMPLATE__), Line 6, Column 2\n ?invalid\n ^\n", source end def test_expected_closing_delimiter source = %q{ p img(src="img.jpg" title={title} } assert_syntax_error "Expected closing delimiter )\n (__TEMPLATE__), Line 3, Column 33\n img(src=\"img.jpg\" title={title}\n ^\n", source end def test_missing_quote_unexpected_end source = %q{ p img(src="img.jpg } assert_syntax_error "Unexpected end of file\n (__TEMPLATE__), Line 3, Column 0\n \n ^\n", source end def test_expected_closing_attribute_delimiter source = %q{ p img src=[hash[1] + hash[2] } assert_syntax_error "Expected closing delimiter ]\n (__TEMPLATE__), Line 3, Column 28\n img src=[hash[1] + hash[2]\n ^\n", source end def test_invalid_empty_attribute source = %q{ p img{src= } } assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3, Column 11\n img{src= }\n ^\n", source end def test_invalid_empty_attribute2 source = %q{ p img{src=} } assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3, Column 10\n img{src=}\n ^\n", source end def test_invalid_empty_attribute3 source = %q{ p img src= } assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3, Column 10\n img src=\n ^\n", source end def test_missing_tag_in_block_expansion source = %{ html: body: } assert_syntax_error "Expected tag\n (__TEMPLATE__), Line 2, Column 11\n html: body:\n ^\n", source end def test_invalid_tag_in_block_expansion source = %{ html: body: /comment } assert_syntax_error "Expected tag\n (__TEMPLATE__), Line 2, Column 12\n html: body: /comment\n ^\n", source source = %{ html: body:/comment } assert_syntax_error "Expected tag\n (__TEMPLATE__), Line 2, Column 11\n html: body:/comment\n ^\n", source end def test_unexpected_text_after_closed source = %{ img / text } assert_syntax_error "Unexpected text after closed tag\n (__TEMPLATE__), Line 2, Column 6\n img / text\n ^\n", source end def test_illegal_shortcuts source = %{ .#test } assert_syntax_error "Illegal shortcut\n (__TEMPLATE__), Line 2, Column 0\n .#test\n ^\n", source source = %{ div.#test } assert_syntax_error "Illegal shortcut\n (__TEMPLATE__), Line 2, Column 3\n div.#test\n ^\n", source end end slim-4.0.1/test/core/test_tabs.rb 0000644 0000041 0000041 00000003021 13411312757 016734 0 ustar www-data www-data require 'helper' class TestSlimTabs < TestSlim def teardown Slim::Engine.set_options tabsize: 4 end def test_single_tab1_expansion Slim::Engine.set_options tabsize: 1 source = %Q{ | \t0 \t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 } result = %q{ 0 1 2 3 4 5 6 7 8 }.strip assert_html result, source end def test_single_tab4_expansion Slim::Engine.set_options tabsize: 4 source = %Q{ | \t0 \t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 } result = %q{ 0 1 2 3 4 5 6 7 8 }.strip assert_html result, source end def test_multi_tab1_expansion Slim::Engine.set_options tabsize: 1 source = %Q{ | \t0 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 } result = %q{ 0 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 }.strip assert_html result, source end def test_multi_tab4_expansion Slim::Engine.set_options tabsize: 4 source = %Q{ | \t0 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 \t\t1 \t \t2 \t \t3 \t \t4 } result = %q{ 0 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 }.strip assert_html result, source end end slim-4.0.1/test/core/test_embedded_engines.rb 0000644 0000041 0000041 00000015277 13411312757 021264 0 ustar www-data www-data require 'helper' require 'erb' class TestSlimEmbeddedEngines < TestSlim def test_render_with_markdown source = %q{ markdown: #Header Hello from #{"Markdown!"} #{1+2} * one * two } if ::Tilt['md'].name =~ /Redcarpet/ # redcarpet assert_html "Hello from Markdown!
\n\n3
\n\nHello from Markdown!
\n\n3
\n\nHello from Markdown!
\n\n3
\n\nHello from Markdown!
\n\n3
\n\nHello from Markdown!
\n\n3
\n\nHi
}, source end def test_render_with_javascript_empty_attributes source = %q{ javascript (): alert('hello') } assert_html %{}, source end def test_render_with_javascript_attribute source = %q{ javascript [class = "myClass"]: alert('hello') } assert_html %{}, source end def test_render_with_javascript_multiple_attributes source = %q{ javascript { class = "myClass" id="myId" other-attribute = 'my_other_attribute' } : alert('hello') } assert_html %{}, source end def test_render_with_javascript_with_tabs source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "Hi
", source end def test_render_with_javascript_including_variable source = %q{ - func = "alert('hello');" javascript: $(function() { #{func} }); } assert_html %q||, source end def test_render_with_javascript_with_explicit_html_comment Slim::Engine.with_options(js_wrapper: :comment) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "Hi
", source end end def test_render_with_javascript_with_explicit_cdata_comment Slim::Engine.with_options(js_wrapper: :cdata) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "Hi
", source end end def test_render_with_javascript_with_format_xhtml_comment Slim::Engine.with_options(js_wrapper: :guess, format: :xhtml) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "Hi
", source end end def test_render_with_javascript_with_format_html_comment Slim::Engine.with_options(js_wrapper: :guess, format: :html) do source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi" assert_html "Hi
", source end end def test_render_with_ruby source = %q{ ruby: variable = 1 + 2 = variable } assert_html '3', source end def test_render_with_ruby_heredoc source = %q{ ruby: variable = <<-MSG foobar MSG = variable } assert_html "foobar\n", source end def test_render_with_scss source = %q{ scss: $color: #f00; body { color: $color; } } assert_html "", source end def test_render_with_scss_attribute source = %q{ scss [class="myClass"]: $color: #f00; body { color: $color; } } assert_html "", source end def test_render_with_sass source = %q{ sass: $color: #f00 body color: $color } assert_html "", source end def test_render_with_sass_attribute source = %q{ sass [class="myClass"]: $color: #f00 body color: $color } assert_html "", source end def test_disabled_embedded_engine source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript] assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript) source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: [:javascript] assert_runtime_error 'Embedded engine ruby is disabled', source, enable_engines: %w(javascript) source = %{ ruby: Embedded Ruby } assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: [:ruby] assert_runtime_error 'Embedded engine ruby is disabled', source, disable_engines: %w(ruby) end def test_enabled_embedded_engine source = %q{ javascript: $(function() {}); } assert_html '', source, disable_engines: [:ruby] assert_html '', source, disable_engines: %w(ruby) source = %q{ javascript: $(function() {}); } assert_html '', source, enable_engines: [:javascript] assert_html '', source, enable_engines: %w(javascript) end end slim-4.0.1/test/core/test_ruby_errors.rb 0000644 0000041 0000041 00000006170 13411312757 020370 0 ustar www-data www-data require 'helper' class TestSlimRubyErrors < TestSlim def test_multline_attribute source = %q{ p(data-1=1 data2-=1) p = unknown_ruby_method } assert_ruby_error NameError, "test.slim:5", source, file: 'test.slim' end def test_broken_output_line source = %q{ p = hello_world + \ hello_world + \ unknown_ruby_method } assert_ruby_error NameError, "test.slim:4", source, file: 'test.slim' end def test_broken_output_line2 source = %q{ p = hello_world + \ hello_world p Hello = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):5", source end def test_output_block source = %q{ p = hello_world "Hello Ruby" do = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):3", source end def test_output_block2 source = %q{ p = hello_world "Hello Ruby" do = "Hello from block" p Hello = unknown_ruby_method } assert_ruby_error NameError, "(__TEMPLATE__):5", source end def test_text_block source = %q{ p Text line 1 Text line 2 = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):4", source end def test_text_block2 source = %q{ | Text line 1 Text line 2 = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):5", source end def test_comment source = %q{ / Comment line 1 Comment line 2 = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):4", source end def test_embedded_ruby1 source = %q{ ruby: a = 1 b = 2 = a + b = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):7", source end def test_embedded_ruby2 source = %q{ ruby: a = 1 unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):4", source end def test_embedded_markdown source = %q{ markdown: #Header Hello from #{"Markdown!"} "Second Line!" = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):6", source end def test_embedded_javascript source = %q{ javascript: alert(); alert(); = unknown_ruby_method } assert_ruby_error NameError,"(__TEMPLATE__):5", source end def test_invalid_nested_code source = %q{ p - test = 123 = "Hello from within a block! " } assert_ruby_syntax_error "(__TEMPLATE__):3", source end def test_invalid_nested_output source = %q{ p = "Hello Ruby!" = "Hello from within a block! " } assert_ruby_syntax_error "(__TEMPLATE__):3", source end def test_explicit_end source = %q{ div - if show_first? p The first paragraph - end } assert_runtime_error 'Explicit end statements are forbidden', source end def test_multiple_id_attribute source = %{ #alpha id="beta" Test it } assert_runtime_error 'Multiple id attributes specified', source end def test_splat_multiple_id_attribute source = %{ #alpha *{id:"beta"} Test it } assert_runtime_error 'Multiple id attributes specified', source end # def test_invalid_option # render('', foobar: 42) # raise Exception, 'ArgumentError expected' # rescue ArgumentError => ex # assert_equal 'Option :foobar is not supported by Slim::Engine', ex.message # end end slim-4.0.1/test/core/test_code_output.rb 0000644 0000041 0000041 00000005675 13411312757 020356 0 ustar www-data www-data require 'helper' class TestSlimCodeOutput < TestSlim def test_render_with_call source = %q{ p = hello_world } assert_html 'Hello World from @env
', source end def test_render_with_trailing_whitespace source = %q{ p => hello_world } assert_html 'Hello World from @env
', source end def test_render_with_trailing_whitespace_after_tag source = %q{ p=> hello_world } assert_html 'Hello World from @env
', source end def test_no_escape_render_with_trailing_whitespace source = %q{ p ==> hello_world } assert_html 'Hello World from @env
', source end def test_no_escape_render_with_trailing_whitespace_after_tag source = %q{ p==> hello_world } assert_html 'Hello World from @env
', source end def test_render_with_conditional_call source = %q{ p = hello_world if true } assert_html 'Hello World from @env
', source end def test_render_with_parameterized_call source = %q{ p = hello_world("Hello Ruby!") } assert_html 'Hello Ruby!
', source end def test_render_with_spaced_parameterized_call source = %q{ p = hello_world "Hello Ruby!" } assert_html 'Hello Ruby!
', source end def test_render_with_spaced_parameterized_call_2 source = %q{ p = hello_world "Hello Ruby!", dummy: "value" } assert_html 'Hello Ruby!dummy value
', source end def test_render_with_call_and_inline_text source = %q{ h1 This is my title p = hello_world } assert_html 'Hello World from @env
', source end def test_render_with_attribute_starts_with_keyword source = %q{ p = hello_world in_keyword } assert_html 'starts with keyword
', source end def test_hash_call source = %q{ p = hash[:a] } assert_html 'The letter a
', source end def test_tag_output_without_space source = %q{ p= hello_world p=hello_world } assert_html 'Hello World from @env
Hello World from @env
', source end def test_class_output_without_space source = %q{ .test=hello_world #test==hello_world } assert_html 'Hello World from @env
Hello World from @env
', source end def test_render_with_backslash_end # Keep trailing spaces! source = %q{ p = \ "Hello" + \ " Ruby!" - variable = 1 + \ 2 + \ 3 = variable + \ 1 } assert_html 'Hello Ruby!
7', source end def test_render_with_comma_end source = %q{ p = message("Hello", "Ruby!") } assert_html 'Hello Ruby!
', source end def test_render_with_no_trailing_character source = %q{ p = hello_world} assert_html 'Hello World from @env
', source end end slim-4.0.1/test/core/test_encoding.rb 0000644 0000041 0000041 00000001247 13411312757 017601 0 ustar www-data www-data require 'helper' class TestSlimEncoding < TestSlim def test_windows_crlf source = "a href='#' something\r\nbr\r\na href='#' others\r\n" result = "somethingHello World from @env
', source end def test_render_with_call_to_set_custom_attributes source = %q{ p data-id="#{id_helper}" data-class="hello world" = hello_world } assert_html 'Hello World from @env
', source end def test_render_with_call_to_set_attributes_and_call_to_set_content source = %q{ p id="#{id_helper}" class="hello world" = hello_world } assert_html 'Hello World from @env
', source end def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content source = %q{ p id="#{id_helper}" class="hello world" = hello_world("Hello Ruby!") } assert_html 'Hello Ruby!
', source end def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content source = %q{ p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!" } assert_html 'Hello Ruby!
', source end def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2 source = %q{ p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!", dummy: "value" } assert_html 'Hello Ruby!dummy value
', source end def test_hash_call_in_attribute source = %q{ p id="#{hash[:a]}" Test it } assert_html 'Test it
', source end def test_instance_variable_in_attribute_without_quotes source = %q{ p id=@var } assert_html '', source end def test_method_call_in_attribute_without_quotes source = %q{ form action=action_path(:page, :save) method='post' } assert_html '', source end def test_ruby_attribute_with_unbalanced_delimiters source = %q{ div crazy=action_path('[') id="crazy_delimiters" } assert_html '', source end def test_method_call_in_delimited_attribute_without_quotes source = %q{ form(action=action_path(:page, :save) method='post') } assert_html '', source end def test_method_call_in_delimited_attribute_without_quotes2 source = %q{ form(method='post' action=action_path(:page, :save)) } assert_html '', source end def test_hash_call_in_attribute_without_quotes source = %q{ p id=hash[:a] Test it } assert_html 'Test it
', source end def test_hash_call_in_delimited_attribute source = %q{ p(id=hash[:a]) Test it } assert_html 'Test it
', source end def test_hash_call_in_attribute_with_ruby_evaluation source = %q{ p id=(hash[:a] + hash[:a]) Test it } assert_html 'Test it
', source end def test_hash_call_in_delimited_attribute_with_ruby_evaluation source = %q{ p(id=(hash[:a] + hash[:a])) Test it } assert_html 'Test it
', source end def test_hash_call_in_delimited_attribute_with_ruby_evaluation_2 source = %q{ p[id=(hash[:a] + hash[:a])] Test it } assert_html 'Test it
', source end def test_hash_call_in_delimited_attribute_with_ruby_evaluation_3 source = %q{ p(id=(hash[:a] + hash[:a]) class=hash[:a]) Test it } assert_html 'Test it
', source end def test_hash_call_in_delimited_attribute_with_ruby_evaluation_4_ source = %q{ p(id=hash[:a] class=hash[:a]) Test it } assert_html 'Test it
', source end def test_computation_in_attribute source = %q{ p id=(1 + 1)*5 Test it } assert_html 'Test it
', source end def test_code_attribute_does_not_modify_argument template = 'span class=attribute' model = OpenStruct.new(attribute: [:a, :b, [:c, :d]]) output = Slim::Template.new { template }.render(model) assert_equal('', output) assert_equal([:a, :b, [:c, :d]], model.attribute) end def test_number_type_interpolation source = %q{ p = output_number } assert_html '1337
', source end end slim-4.0.1/test/core/test_code_escaping.rb 0000644 0000041 0000041 00000007434 13411312757 020602 0 ustar www-data www-data require 'helper' class TestSlimCodeEscaping < TestSlim def test_escaping_evil_method source = %q{ p = evil_method } assert_html '<script>do_something_evil();</script>
', source end def test_render_without_html_safe source = %q{ p = "Hello World\\n, meet \\"Slim\\"." } assert_html "<strong>Hello World\n, meet \"Slim\"</strong>.
", source end def test_render_without_html_safe2 source = %q{ p = "Hello World\\n, meet 'Slim'." } assert_html "<strong>Hello World\n, meet 'Slim'</strong>.
", source end def test_render_with_html_safe_false source = %q{ p = "Hello World\\n, meet \\"Slim\\"." } with_html_safe do assert_html "<strong>Hello World\n, meet \"Slim\"</strong>.
", source, use_html_safe: true end end def test_render_with_html_safe_true source = %q{ p = "Hello World\\n, meet \\"Slim\\".".html_safe } with_html_safe do assert_html "Hello World\n, meet \"Slim\".
", source, use_html_safe: true end end def test_render_splat_with_html_safe_true source = %q{ p *{ title: '&'.html_safe } } with_html_safe do assert_html "", source, use_html_safe: true end end def test_render_splat_with_html_safe_false source = %q{ p *{ title: '&' } } with_html_safe do assert_html "", source, use_html_safe: true end end def test_render_splat_injecting_evil_attr_name source = %q{ p *{ ">'test' } } with_html_safe do assert_raises Slim::InvalidAttributeNameError do render(source, use_html_safe: true) end end end def test_render_attribute_with_html_safe_true source = %q{ p title=('&'.html_safe) } with_html_safe do assert_html "
", source, use_html_safe: true end end def test_render_with_disable_escape_false source = %q{ = "Hello
" == "World
" } assert_html "<p>Hello</p>World
", source end def test_render_with_disable_escape_true source = %q{ = "Hello
" == "World
" } assert_html "Hello
World
", source, disable_escape: true end def test_escaping_evil_method_with_pretty source = %q{ p = evil_method } assert_html "\n <script>do_something_evil();</script>\n
", source, pretty: true end def test_render_without_html_safe_with_pretty source = %q{ p = "Hello World\\n, meet \\"Slim\\"." } assert_html "\n <strong>Hello World\n , meet \"Slim\"</strong>.\n
", source, pretty: true end def test_render_with_html_safe_false_with_pretty source = %q{ p = "Hello World\\n, meet \\"Slim\\"." } with_html_safe do assert_html "\n <strong>Hello World\n , meet \"Slim\"</strong>.\n
", source, use_html_safe: true, pretty: true end end def test_render_with_html_safe_true_with_pretty source = %q{ p = "Hello World\\n, meet \\"Slim\\".".html_safe } with_html_safe do assert_html "\n Hello World\n , meet \"Slim\".\n
", source, use_html_safe: true, pretty: true end end def test_render_with_disable_escape_false_with_pretty source = %q{ = "Hello
" == "World
" } assert_html "<p>Hello</p>World
", source, pretty: true end def test_render_with_disable_escape_true_with_pretty source = %q{ = "Hello
" == "World
" } assert_html "Hello
World
", source, disable_escape: true, pretty: true end end slim-4.0.1/test/core/test_thread_options.rb 0000644 0000041 0000041 00000001003 13411312757 021023 0 ustar www-data www-data require 'helper' class TestSlimThreadOptions < TestSlim def test_thread_options source = %q{p.test} assert_html '', source assert_html "", source, attr_quote: "'" Slim::Engine.with_options(attr_quote: "'") do assert_html "", source assert_html '', source, attr_quote: '"' end assert_html '', source assert_html "", source, attr_quote: "'" end end slim-4.0.1/test/core/test_splat_prefix_option.rb 0000644 0000041 0000041 00000007302 13411312757 022101 0 ustar www-data www-data require 'helper' class TestSplatPrefixOption < TestSlim def prefixes ['*','**','*!','*%','*^','*$'] end def options(prefix) { splat_prefix: prefix } end def test_splat_without_content prefixes.each do |prefix| source = %Q{ #{prefix}hash p#{prefix}hash } assert_html '', source, options(prefix) end end def test_shortcut_splat prefixes.each do |prefix| source = %Q{ #{prefix}hash This is my title } assert_html 'Hello World from @env
', source end def test_nested_interpolation_in_attribute source = %q{ p id="#{"abc#{1+1}" + "("}" = hello_world } assert_html 'Hello World from @env
', source end def test_interpolation_in_text source = %q{ p | #{hello_world} with "quotes" p | A message from the compiler: #{hello_world} } assert_html 'Hello World from @env with "quotes"
A message from the compiler: Hello World from @env
', source end def test_interpolation_in_tag source = %q{ p #{hello_world} } assert_html 'Hello World from @env
', source end def test_escape_interpolation source = %q{ p \\#{hello_world} p text1 \\#{hello_world} text2 } assert_html '#{hello_world}
text1 #{hello_world} text2
', source end def test_complex_interpolation source = %q{ p Message: #{message('hello', "user #{output_number}")} } assert_html 'Message: hello user 1337
', source end def test_interpolation_with_escaping source = %q{ | #{evil_method} } assert_html '<script>do_something_evil();</script>', source end def test_interpolation_without_escaping source = %q{ | #{{evil_method}} } assert_html '', source end def test_interpolation_with_escaping_and_delimiter source = %q{ | #{(evil_method)} } assert_html '<script>do_something_evil();</script>', source end end slim-4.0.1/test/core/test_pretty.rb 0000644 0000041 0000041 00000005664 13411312757 017351 0 ustar www-data www-data require 'helper' class TestSlimPretty < TestSlim def setup super Slim::Engine.set_options pretty: true end def teardown Slim::Engine.set_options pretty: false end def test_pretty source = %q{ doctype 5 html head title Hello World! /! Meta tags with long explanatory multiline comment meta name="description" content="template language" /! Stylesheets link href="style.css" media="screen" rel="stylesheet" type="text/css" link href="colors.css" media="screen" rel="stylesheet" type="text/css" /! Javascripts script src="jquery.js" script src="jquery.ui.js" /[if lt IE 9] script src="old-ie1.js" script src="old-ie2.js" sass: body background-color: red body #container p Hello World! p= "dynamic text with\nnewline" } result = %q{Hello World!
dynamic text with newline
Hello Ruby! Hello from within a block! Hello Ruby!
', source end def test_render_with_output_code_block_without_do source = %q{ p = hello_world "Hello Ruby!" | Hello from within a block! } assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!
', source end def test_render_variable_ending_with_do source = %q{ - appelido=10 p= appelido - appelido } assert_html '10
', source end def test_render_with_output_code_within_block source = %q{ p = hello_world "Hello Ruby!" do = hello_world "Hello from within a block!" } assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!
', source end def test_render_with_output_code_within_block_without_do source = %q{ p = hello_world "Hello Ruby!" = hello_world "Hello from within a block!" } assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!
', source end def test_render_with_output_code_within_block_2 source = %q{ p = hello_world "Hello Ruby!" do = hello_world "Hello from within a block!" do = hello_world "And another one!" } assert_html 'Hello Ruby! Hello from within a block! And another one! Hello from within a block! Hello Ruby!
', source end def test_render_with_output_code_within_block_2_without_do source = %q{ p = hello_world "Hello Ruby!" = hello_world "Hello from within a block!" = hello_world "And another one!" } assert_html 'Hello Ruby! Hello from within a block! And another one! Hello from within a block! Hello Ruby!
', source end def test_output_block_with_arguments source = %q{ p = define_macro :person do |first_name, last_name| .first_name = first_name .last_name = last_name == call_macro :person, 'John', 'Doe' == call_macro :person, 'Max', 'Mustermann' } assert_html 'Hey!Hey!Hey!
', source end def test_render_with_control_code_loop_without_do source = %q{ p - 3.times | Hey! } assert_html 'Hey!Hey!Hey!
', source end def test_captured_code_block_with_conditional source = %q{ = hello_world "Hello Ruby!" do - if true | Hello from within a block! } assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source end def test_captured_code_block_with_conditional_without_do source = %q{ = hello_world "Hello Ruby!" - if true | Hello from within a block! } assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source end def test_if_without_content source = %q{ - if true } assert_html '', source end def test_unless_without_content source = %q{ - unless true } assert_html '', source end def test_if_with_comment source = %q{ - if true / comment } assert_html '', source end def test_control_do_with_comment source = %q{ - hello_world "Hello" / comment } assert_html '', source end def test_output_do_with_comment source = %q{ = hello_world "Hello" / comment } assert_html 'Hello', source end def test_output_if_without_content source = %q{ = if true } assert_html '', source end def test_output_if_with_comment source = %q{ = if true / comment } assert_html '', source end def test_output_format_with_if source = %q{ h3.subtitle - if true a href="#" Title true - else a href="#" Title false } assert_html 'The second paragraph
A
B
C
', source end def test_render_with_consecutive_conditionals source = %q{ div - if show_first? true p The first paragraph - if show_first? true p The second paragraph } assert_html 'The first paragraph
The second paragraph
The second paragraph
The first paragraph
42Hello World from @env
', source end def test_render_with_case source = %q{ p - case 42 - when 41 | 41 - when 42 | 42 | is the answer p - case 41 - when 41 | 41 - when 42 | 42 | is the answer p - case 42 when 41 | 41 - when 42 | 42 | is the answer p - case 41 when 41 | 41 - when 42 | 42 | is the answer } assert_html '42 is the answer
41 is the answer
42 is the answer
41 is the answer
', source end def test_render_with_slim_comments source = %q{ p Hello / This is a comment Another comment p World } assert_html 'Hello
World
', source end def test_render_with_yield source = %q{ div == yield :menu } assert_html 'Begin
After
', source end def test_render_with_begin_rescue_exception source = %q{ - begin p Begin - raise 'Boom' p After Boom - rescue => ex p = ex.message p After } assert_html 'Begin
Boom
After
', source end def test_render_with_begin_rescue_ensure source = %q{ - begin p Begin - raise 'Boom' p After Boom - rescue => ex p = ex.message - ensure p Ensure p After } assert_html 'Begin
Boom
Ensure
After
', source end end slim-4.0.1/test/core/test_erb_converter.rb 0000644 0000041 0000041 00000003074 13411312757 020652 0 ustar www-data www-data require 'helper' require 'slim/erb_converter' class TestSlimERBConverter < TestSlim def test_converter source = %q{ doctype 5 html head title Hello World! /! Meta tags with long explanatory multiline comment meta name="description" content="template language" /! Stylesheets link href="style.css" media="screen" rel="stylesheet" type="text/css" link href="colors.css" media="screen" rel="stylesheet" type="text/css" /! Javascripts script src="jquery.js" script src="jquery.ui.js" /[if lt IE 9] script src="old-ie1.js" script src="old-ie2.js" sass: body background-color: red body #container p Hello World! p= "dynamic text with\nnewline" } result = %q{Hello World!
<%= ::Temple::Utils.escape_html(("dynamic text with\nnewline")) %>
Hello World!
", template.render end def test_evaluating_in_an_object_scope template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" } scope = Object.new scope.instance_variable_set :@name, 'Joe' assert_equal "Hey Joe!
", template.render(scope) end def test_passing_a_block_for_yield template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" } assert_equal "Hey Joe!
", template.render { 'Joe' } end def test_backtrace_file_and_line_reporting_without_locals data = File.read(__FILE__).split("\n__END__\n").last fail unless data[0] == ?h template = Slim::Template.new('test.slim', 10) { data } begin template.render fail 'should have raised an exception' rescue => ex assert_kind_of NameError, ex assert_backtrace(ex, 'test.slim:12') end end def test_backtrace_file_and_line_reporting_with_locals data = File.read(__FILE__).split("\n__END__\n").last fail unless data[0] == ?h template = Slim::Template.new('test.slim') { data } begin template.render(Object.new, name: 'Joe', foo: 'bar') fail 'should have raised an exception' rescue => ex assert_kind_of MockError, ex assert_backtrace(ex, 'test.slim:5') end end def test_compiling_template_source_to_a_method template = Slim::Template.new { |t| "Hello World!" } template.render method = template.send(:compiled_method, []) assert_kind_of UnboundMethod, method end def test_passing_locals template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" } assert_equal "Hey Joe!
", template.render(Object.new, name: 'Joe') end end __END__ html body h1 = "Hey #{name}" = raise MockError p we never get here slim-4.0.1/test/core/test_commands.rb 0000644 0000041 0000041 00000014434 13411312757 017616 0 ustar www-data www-data require 'helper' require 'open3' require 'tempfile' class TestSlimCommands < Minitest::Test # nothing complex STATIC_TEMPLATE = "p Hello World!\n" # requires a `name` variable to exist at render time DYNAMIC_TEMPLATE = "p Hello \#{name}!\n" # a more complex example LONG_TEMPLATE = "h1 Hello\np\n | World!\n small Tiny text" # exception raising example EXCEPTION_TEMPLATE = '- raise NotImplementedError' # Temple has this feature... STRING_FREEZER = RUBY_VERSION >= '2.1' ? '.freeze' : '' def test_option_help out, err = exec_slimrb '--help' assert err.empty? assert_match %r{Show this message}, out end def test_option_version out, err = exec_slimrb '--version' assert err.empty? assert_match %r{\ASlim #{Regexp.escape Slim::VERSION}$}, out end def test_render prepare_common_test STATIC_TEMPLATE do |out, err| assert err.empty? assert_equal "Hello World!
\n", out end end # superficial test, we don't want to test Tilt/Temple def test_compile prepare_common_test STATIC_TEMPLATE, '--compile' do |out, err| assert err.empty? assert_match %r{\"Hello World!<\/p>\"#{STRING_FREEZER}}, out end end def test_erb prepare_common_test DYNAMIC_TEMPLATE, '--erb' do |out, err| assert err.empty? assert_equal "
Hello <%= ::Temple::Utils.escape_html((name)) %>!
\n", out end end def test_rails prepare_common_test DYNAMIC_TEMPLATE, '--rails' do |out, err| assert err.empty? assert out.include? %Q{@output_buffer = ActiveSupport::SafeBuffer.new;} assert out.include? %Q{@output_buffer.safe_concat(("Hello "#{STRING_FREEZER}));} assert out.include? %Q{@output_buffer.safe_concat(((::Temple::Utils.escape_html((name))).to_s));} assert out.include? %Q{@output_buffer.safe_concat(("!
"#{STRING_FREEZER}));} end end def test_pretty prepare_common_test LONG_TEMPLATE, '--pretty' do |out, err| assert err.empty? assert_equal "\n World!Tiny text\n
\n", out end end # We cannot run these two on Travis, because we can't install libyaml. # See https://github.com/slim-template/slim/issues/576 if ENV['TRAVIS'] && RUBY_ENGINE != 'rbx' def test_locals_json data = '{"name":"from slim"}' prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err| assert err.empty? assert_equal "Hello from slim!
\n", out end end def test_locals_yaml data = "name: from slim" prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err| assert err.empty? assert_equal "Hello from slim!
\n", out end end end def test_locals_hash data = '{name:"from slim"}' prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err| assert err.empty? assert_equal "Hello from slim!
\n", out end end def test_require with_tempfile 'puts "Not in slim"', 'rb' do |lib| prepare_common_test STATIC_TEMPLATE, '--require', lib, stdin_file: false, file_file: false do |out, err| assert err.empty? assert_equal "Not in slim\nHello World!
\n", out end end end def test_error prepare_common_test EXCEPTION_TEMPLATE, stdin_file: false do |out, err| assert out.empty? assert_match %r{NotImplementedError: NotImplementedError}, err assert_match %r{Use --trace for backtrace}, err end end def test_trace_error prepare_common_test EXCEPTION_TEMPLATE, '--trace', stdin_file: false do |out, err| assert out.empty? assert_match %r{bin\/slimrb}, err end end private # Whether you call slimrb with a file argument or pass the slim content # via $stdin; whether you want the output written to $stdout or into # another file given as argument, the output is the same. # # This method prepares a test with this exact behaviour: # # It yields the tupel (out, err) once after the `content` was passed # in via $stdin and once it was passed as a (temporary) file argument. # # In effect, this method executes a test (given as block) 4 times: # # 1. read from $stdin, write to $stdout # 2. read from file, write to $stdout # 3. read from $stdin, write to file # 4. read from file, write to file def prepare_common_test(content, *args) options = Hash === args.last ? args.pop : {} # case 1. $stdin â $stdout unless options[:stdin_stdout] == false out, err = exec_slimrb(*args, '--stdin') do |i| i.write content end yield out, err end # case 2. file â $stdout unless options[:file_stdout] == false with_tempfile content do |in_file| out, err = exec_slimrb(*args, in_file) yield out, err end end # case 3. $stdin â file unless options[:stdin_file] == false with_tempfile content do |out_file| _, err = exec_slimrb(*args, '--stdin', out_file) do |i| i.write content end yield File.read(out_file), err end end # case 3. file â file unless options[:file_file] == false with_tempfile '' do |out_file| with_tempfile content do |in_file| _, err = exec_slimrb(*args, in_file, out_file) do |i| i.write content end yield File.read(out_file), err end end end end # Calls bin/slimrb as a subprocess. # # Yields $stdin to the caller and returns a tupel (out,err) with the # contents of $stdout and $stderr. # # (I'd like to use Minitest::Assertions#capture_subprecess_io here, # but then there's no way to insert data via $stdin.) def exec_slimrb(*args) out, err = nil, nil Open3.popen3 'ruby', 'bin/slimrb', *args do |i,o,e,t| yield i if block_given? i.close out, err = o.read, e.read end return out, err end # Creates a temporary file with the given content and yield the path # to this file. The file itself is only available inside the block and # will be deleted afterwards. def with_tempfile(content=nil, extname='slim') f = Tempfile.new ['slim', ".#{extname}"] if content f.write content f.flush # ensure content is actually saved to disk f.rewind end yield f.path ensure f.close f.unlink end end slim-4.0.1/test/core/test_unicode.rb 0000644 0000041 0000041 00000000603 13411312757 017434 0 ustar www-data www-data require 'helper' class TestSlimUnicode < TestSlim def test_unicode_tags source = "СÑаÑÑÑ Ð³ÐŸÐŽÐ°" result = "<СÑаÑÑÑ>гПЎаСÑаÑÑÑ>" assert_html result, source end def test_unicode_attrs source = "СÑаÑÑÑ Ð³ÐŸÐŽÐ°=123 content" result = "<СÑаÑÑÑ Ð³ÐŸÐŽÐ°=\"123\">contentСÑаÑÑÑ>" assert_html result, source end end slim-4.0.1/test/core/test_html_escaping.rb 0000644 0000041 0000041 00000002456 13411312757 020633 0 ustar www-data www-data require 'helper' class TestSlimHtmlEscaping < TestSlim def test_html_will_not_be_escaped source = %q{ ptest <x>
', source end def test_html_nested_escaping source = %q{ = hello_world do | escaped & } assert_html 'Hello World from @env escaped & Hello World from @env', source end def test_html_quoted_attr_escape source = %q{ p id="&" class=="&" } assert_html '', source end def test_html_quoted_attr_escape_with_interpolation source = %q{ p id="{'"'}" class=="&#{'"'}" p id="{{'"'}}" class=="&#{{'"'}}" } assert_html '', source end def test_html_ruby_attr_escape source = %q{ p id=('&'.to_s) class==('&'.to_s) } assert_html '', source end end slim-4.0.1/test/rails/ 0000755 0000041 0000041 00000000000 13411312757 014605 5 ustar www-data www-data slim-4.0.1/test/rails/test/ 0000755 0000041 0000041 00000000000 13411312757 015564 5 ustar www-data www-data slim-4.0.1/test/rails/test/helper.rb 0000644 0000041 0000041 00000001750 13411312757 017373 0 ustar www-data www-data # Configure Rails Envinronment ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment.rb", __FILE__) require "rails/test_help" require "nokogiri" require 'rails-controller-testing' Rails::Controller::Testing.install Rails.backtrace_cleaner.remove_silencers! class ActionDispatch::IntegrationTest protected def assert_xpath(xpath, message="Unable to find '#{xpath}' in response body.") assert_response :success, "Response type is not :success (code 200..299)." body = @response.body assert !body.empty?, "No response body found." doc = Nokogiri::HTML(body) rescue nil assert_not_nil doc, "Cannot parse response body." assert doc.xpath(xpath).size >= 1, message end def assert_html(expected, options = {}) expected = "With a partial!
" end if RUBY_ENGINE == 'jruby' && RUBY_ENGINE < '2.2.0' puts 'Streaming test disabled for JRuby < 9000.', 'See https://github.com/jruby/jruby/issues/1243', 'and https://github.com/jruby/jruby/issues/1789' else puts 'Streaming test enabled.' test "streaming" do get "/slim/streaming" output = "2f\r\nPage content
Hello Streaming!
Hello Streaming!
\r\n14\r\n1337
" end test "render thread_options" do get "/slim/thread_options", params: { attr: 'role'} assert_html 'Test
' get "/slim/thread_options", params: { attr: 'id'} # Overwriting doesn't work because of caching assert_html 'Test
' end test "content_for" do get "/slim/content_for" assert_html "Page content
Hello Slim!
Hello Slim!
", heading: 'Heading set from a view' end test "form_for" do get "/entries/edit/1" assert_match %r{action="/entries"}, @response.body assert_match %r{}, @response.body assert_xpath '//input[@id="entry_name" and @name="entry[name]" and @type="text"]' end test "splat" do get "/slim/splat" assert_html "