require 'helper'
class TestSkimLogicLess < TestSkim
def test_sections
source = %q{
p
- person
.name = name
}
hash = {
:person => [
{ :name => 'Joe', },
{ :name => 'Jack', }
]
}
assert_html '
Joe
Jack
', source, :context => hash, :sections => true
end
def test_flag_section
source = %q{
p
- show_person
- person
.name = name
- show_person
| shown
}
hash = {
:show_person => true,
:person => [
{ :name => 'Joe', },
{ :name => 'Jack', }
]
}
assert_html 'Joe
Jack
shown', source, :context => hash, :sections => true
end
def test_inverted_section
source = %q{
p
- person
.name = name
-! person
| No person
- !person
| No person 2
}
hash = {}
assert_html 'No person No person 2
', source, :context => hash, :sections => true
end
def test_output_with_content
source = %{
p = method_with_block do
block
}
assert_runtime_error 'Output statements with content are forbidden in sections mode', source, :sections => true
end
def test_sections2
source = %q{
p
- person
.name = name
}
assert_html 'Joe
Jack
', source, :sections => true
end
def test_with_array
source = %q{
ul
- people_with_locations
li = name
li = city
}
assert_html '- Andy
- Atlanta
- Fred
- Melbourne
- Daniel
- Karlsruhe
', source, :sections => true
end
def test_method
source = %q{
a href=output_number Link
}
assert_html 'Link', source, :sections => true
end
SECTION = <<-SRC
- test
| Test
SRC
INVERTED_SECTION = <<-SRC
-! test
| Test
SRC
def test_undefined_section
assert_html "", SECTION, :context => {}, :sections => true
end
def test_null_section
assert_html "", SECTION, :context => {:test => nil}, :sections => true
end
def test_false_section
assert_html "", SECTION, :context => {:test => false}, :sections => true
end
def test_empty_string_section
assert_html "Test", SECTION, :context => {:test => ""}, :sections => true
end
def test_empty_array_section
assert_html "", SECTION, :context => {:test => []}, :sections => true
end
def test_empty_object_section
assert_html "Test", SECTION, :context => {:test => {}}, :sections => true
end
def test_undefined_inverted_section
assert_html "Test", INVERTED_SECTION, :context => {}, :sections => true
end
def test_null_inverted_section
assert_html "Test", INVERTED_SECTION, :context => {:test => nil}, :sections => true
end
def test_false_inverted_section
assert_html "Test", INVERTED_SECTION, :context => {:test => false}, :sections => true
end
def test_empty_string_inverted_section
assert_html "", INVERTED_SECTION, :context => {:test => ""}, :sections => true
end
def test_empty_array_inverted_section
assert_html "Test", INVERTED_SECTION, :context => {:test => []}, :sections => true
end
def test_empty_object_inverted_section
assert_html "", INVERTED_SECTION, :context => {:test => {}}, :sections => true
end
def test_doesnt_modify_context
source = %q{
- constant_object
= constant_object_size
}
assert_html '2', source, :sections => true
end
end