summaryrefslogtreecommitdiff
path: root/test/rexml/functions/test_number.rb
blob: 16e635701c7db03f1581a499abffb94fbb7fbbb6 (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
# frozen_string_literal: false

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

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

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

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

    def test_numeric
      assert_equal(29, REXML::Functions.number(29))
    end

    def test_string_integer
      assert_equal(100, REXML::Functions.number("100"))
    end

    def test_string_float
      assert_equal(-9.13, REXML::Functions.number("-9.13"))
    end

    def test_node_set
      root = REXML::Document.new("<root>100</root>").root
      assert_equal(100, REXML::Functions.number([root]))
    end
  end
end