summaryrefslogtreecommitdiff
path: root/test/rexml/test_functions_boolean.rb
blob: b3e2117c10f45a10869201192c14c4a2f827412e (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: false

require "test/unit"
require "rexml/document"
require "rexml/functions"

module REXMLTests
  class TestFunctionsBoolean < Test::Unit::TestCase
    def setup
      REXML::Functions.context = nil
    end

    def test_true
      assert_equal(true, REXML::Functions.boolean(true))
    end

    def test_false
      assert_equal(false, REXML::Functions.boolean(false))
    end

    def test_integer_true
      assert_equal(true, REXML::Functions.boolean(1))
    end

    def test_integer_positive_zero
      assert_equal(false, REXML::Functions.boolean(0))
    end

    def test_integer_negative_zero
      assert_equal(false, REXML::Functions.boolean(-0))
    end

    def test_float_true
      assert_equal(true, REXML::Functions.boolean(1.1))
    end

    def test_float_positive_zero
      assert_equal(false, REXML::Functions.boolean(-0.0))
    end

    def test_float_negative_zero
      assert_equal(false, REXML::Functions.boolean(-0.0))
    end

    def test_float_nan
      assert_equal(false, REXML::Functions.boolean(Float::NAN))
    end

    def test_string_true
      assert_equal(true, REXML::Functions.boolean("content"))
    end

    def test_string_empty
      assert_equal(false, REXML::Functions.boolean(""))
    end

    def test_node_set_true
      root = REXML::Document.new("<root/>").root
      assert_equal(true, REXML::Functions.boolean([root]))
    end

    def test_node_set_empty
      assert_equal(false, REXML::Functions.boolean([]))
    end

    def test_nil
      assert_equal(false, REXML::Functions.boolean(nil))
    end

    def test_context
      REXML::Functions.context = {node: true}
      assert_equal(true, REXML::Functions.boolean())
    end
  end
end