# encoding: UTF-8
require 'test_helper'
class TestColorer < Pizzazz::TestCase
def test_that_it_colors_hashes
colored = Pizzazz.ify({:foo => 'bar'})
assert_equal colored, %q{{
"foo": "bar"
}}
end
def test_new_lines
colored = Pizzazz.ify({:message => "hello\nworld"})
assert_equal colored, %q{{
"message": "hello\nworld"
}}
end
def test_tabs
colored = Pizzazz.ify({:foo => 'bar'}, tab: '||||')
assert_equal colored, %q{{
||||"foo": "bar"
}}
end
def test_prefix
colored = Pizzazz.ify({:foo => 'bar'}, prefix: '**')
assert_equal colored, %q{**{
** "foo": "bar"
**}}
end
def test_omit_root_container
colored = Pizzazz.ify({:foo => 'bar'}, omit_root_container: true)
assert_equal colored, %q{"foo": "bar"}
colored = Pizzazz.ify([1, 2], omit_root_container: true)
assert_equal colored, %q{1,
2}
end
def test_that_it_truncates_arrays
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 2)
assert_equal colored, %q{{
"numbers": [
1,
2,
…
]
}}
colored = Pizzazz.ify({:numbers => [1, 2, 3]}, :array_limit => 1, :array_omission => 'hello')
assert_equal colored, %q{{
"numbers": [
1,
hello
]
}}
end
def test_that_it_truncates_values
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 5)
assert_equal colored, %q{{
"wooden": "base…"
}}
colored = Pizzazz.ify({:wooden => 'baseball bat'}, :value_limit => 9, :value_omission => '!')
assert_equal colored, %q{{
"wooden": "baseball!"
}}
end
def test_link
colored = Pizzazz.ify({:website => 'http://soff.es'})
assert_equal colored, %q{{
"website": "http://soff.es"
}}
colored = Pizzazz.ify({:website => 'http://soff.es'}, :detect_links => false)
assert_equal colored, %q{{
"website": "http://soff.es"
}}
end
def test_sort_keys
colored = Pizzazz.ify({:b => 'foo', :a => 'bar'})
assert_equal colored, %q{{
"a": "bar",
"b": "foo"
}}
colored = Pizzazz.ify({:b => 'foo', :a => 'bar'}, :sort_keys => false)
assert_equal colored, %q{{
"b": "foo",
"a": "bar"
}}
end
end