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