File: empty_value_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require "test_helper"
require_relative "test_subclasses"

# Tests empty_value? checking for nil/empty values
class EmptyValueTest < Minitest::Test
  cover "MultiXml*"
  include MultiXml::Helpers

  def test_true_for_empty_hash
    assert empty_value?({}, nil)
  end

  def test_true_when_nil_equals_true
    assert empty_value?({"nil" => "true"}, nil)
  end

  def test_true_when_only_type_present
    assert empty_value?({"type" => "integer"}, "integer")
  end

  def test_false_when_nil_not_true
    refute empty_value?({"nil" => "false", "other" => "value"}, nil)
  end

  def test_false_when_type_is_hash
    refute empty_value?({"type" => {"nested" => "value"}}, {"nested" => "value"})
  end

  def test_with_hash_type_returns_false
    hash_type = {"nested" => "data"}
    result = empty_value?({"type" => hash_type}, hash_type)

    refute result
  end

  def test_with_string_type_and_size_one
    result = empty_value?({"type" => "integer"}, "integer")

    assert result
  end

  def test_with_string_type_and_size_two
    result = empty_value?({"type" => "integer", "other" => "key"}, "integer")

    refute result
  end

  def test_with_hash_subclass_as_type
    type = HashSubclass.new
    type["nested"] = "value"
    hash = {"type" => type}

    refute empty_value?(hash, type)
  end

  def test_false_when_type_nil_and_hash_has_content
    refute empty_value?({"content" => "value"}, nil)
  end
end