Sha256: ce2e8ce84c69f33343e70a5980f063bf42061eed7daf1d76797ce678a15ed3b4

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# encoding: UTF-8

require 'test_helper'

class TestValue < Test::Unit::TestCase
  def value(value)
    JSONBuilder::Value.new(nil, value).to_s
  end

  def test_positive_value
    assert_equal '1', value(1)
  end

  def test_negative_value
    assert_equal '-5', value(-5)
  end

  def test_float_value
    assert_equal '13.37', value(13.37)
  end

  def test_nil_value
    assert_equal 'null', value(nil)
  end

  def test_true_value
    assert_equal 'true', value(true)
  end

  def test_false_value
    assert_equal 'false', value(false)
  end

  def test_symbol_value
    assert_equal 'test', value(:test)
  end

  def test_unicode_char_value
    assert_equal '"hellyé"', value('hellyé')
  end

  def test_time_value
    assert_equal '"2012-01-01T00:00:00Z"', value(Time.utc(2012))
  end

  def test_time_with_zone_value
    Time.zone = 'CET'
    assert_equal '"2012-01-01T00:00:00+01:00"', value(Time.zone.local(2012))
  end

  # This will be the local time zone offset, hence the wildcard.
  def test_date_value
    assert_match /"2012-01-01T00:00:00.*/, value(Date.parse('2012-01-01'))
  end

  def test_date_time_value
    assert_equal '"2012-01-01T00:00:00Z"', value(DateTime.parse('2012-01-01'))
  end

  def test_hash_value
    assert_equal '{"oh":"boy"}', value(:oh => :boy)
  end

  def test_custom_class
    assert_equal '"olleh"', value(Dozer.new('hello'))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_builder-3.1.2 test/value_test.rb
json_builder-3.1.1 test/value_test.rb
json_builder-3.1.0 test/value_test.rb