|
1 | 1 | # frozen_string_literal: false
|
2 |
| -require 'rexml/document' |
3 |
| -require 'test/unit' |
4 |
| -require 'rexml/functions' |
| 2 | + |
| 3 | +require "test/unit" |
| 4 | +require "rexml/document" |
| 5 | +require "rexml/functions" |
5 | 6 |
|
6 | 7 | module REXMLTests
|
7 |
| - class TC_Rexml_Functions_Number < Test::Unit::TestCase |
| 8 | + class TestFunctionsNumber < Test::Unit::TestCase |
| 9 | + def setup |
| 10 | + REXML::Functions.context = nil |
| 11 | + end |
8 | 12 |
|
9 |
| - def test_functions_number_int |
10 |
| - telem = REXML::Element.new("elem") |
11 |
| - telem.text="9" |
12 |
| - assert_equal(9, REXML::Functions::number(telem)) |
| 13 | + def test_true |
| 14 | + assert_equal(1, REXML::Functions.number(true)) |
13 | 15 | end
|
14 |
| - def test_functions_number_float |
15 |
| - telem = REXML::Element.new("elem") |
16 |
| - telem.text="10.4" |
17 |
| - assert_equal(10.4, REXML::Functions::number(telem)) |
| 16 | + |
| 17 | + def test_false |
| 18 | + assert_equal(0, REXML::Functions.number(false)) |
18 | 19 | end
|
19 |
| - def test_functions_number_negative_int |
20 |
| - telem = REXML::Element.new("elem") |
21 |
| - telem.text="-9" |
22 |
| - assert_equal(-9, REXML::Functions::number(telem)) |
| 20 | + |
| 21 | + def test_numeric |
| 22 | + assert_equal(29, REXML::Functions.number(29)) |
23 | 23 | end
|
24 |
| - def test_functions_number_negative_float |
25 |
| - telem = REXML::Element.new("elem") |
26 |
| - telem.text="-9.13" |
27 |
| - assert_equal(-9.13, REXML::Functions::number(telem)) |
| 24 | + |
| 25 | + def test_string_integer |
| 26 | + assert_equal(100, REXML::Functions.number("100")) |
| 27 | + end |
| 28 | + |
| 29 | + def test_string_float |
| 30 | + assert_equal(-9.13, REXML::Functions.number("-9.13")) |
| 31 | + end |
| 32 | + |
| 33 | + def test_node_set |
| 34 | + root = REXML::Document.new("<root>100</root>").root |
| 35 | + assert_equal(100, REXML::Functions.number([root])) |
28 | 36 | end
|
29 |
| - #def test_functions_number_scientific_notation |
30 |
| - # telem = REXML::Element.new("elem") |
31 |
| - # telem.text="9.13E12" |
32 |
| - # assert_equal(9.13E12, REXML::Functions::number(telem)) |
33 |
| - #end |
34 | 37 | end
|
35 | 38 | end
|
0 commit comments