|
| 1 | +# frozen_string_literal: false |
| 2 | + |
| 3 | +require "test/unit" |
| 4 | +require "rexml/document" |
| 5 | +require "rexml/functions" |
| 6 | + |
| 7 | +module REXMLTests |
| 8 | + class TestFunctionsBoolean < Test::Unit::TestCase |
| 9 | + def setup |
| 10 | + REXML::Functions.context = nil |
| 11 | + end |
| 12 | + |
| 13 | + def test_true |
| 14 | + assert_equal(true, REXML::Functions.boolean(true)) |
| 15 | + end |
| 16 | + |
| 17 | + def test_false |
| 18 | + assert_equal(false, REXML::Functions.boolean(false)) |
| 19 | + end |
| 20 | + |
| 21 | + def test_integer_true |
| 22 | + assert_equal(true, REXML::Functions.boolean(1)) |
| 23 | + end |
| 24 | + |
| 25 | + def test_integer_positive_zero |
| 26 | + assert_equal(false, REXML::Functions.boolean(0)) |
| 27 | + end |
| 28 | + |
| 29 | + def test_integer_negative_zero |
| 30 | + assert_equal(false, REXML::Functions.boolean(-0)) |
| 31 | + end |
| 32 | + |
| 33 | + def test_float_true |
| 34 | + assert_equal(true, REXML::Functions.boolean(1.1)) |
| 35 | + end |
| 36 | + |
| 37 | + def test_float_positive_zero |
| 38 | + assert_equal(false, REXML::Functions.boolean(-0.0)) |
| 39 | + end |
| 40 | + |
| 41 | + def test_float_negative_zero |
| 42 | + assert_equal(false, REXML::Functions.boolean(-0.0)) |
| 43 | + end |
| 44 | + |
| 45 | + def test_float_nan |
| 46 | + assert_equal(false, REXML::Functions.boolean(Float::NAN)) |
| 47 | + end |
| 48 | + |
| 49 | + def test_string_true |
| 50 | + assert_equal(true, REXML::Functions.boolean("content")) |
| 51 | + end |
| 52 | + |
| 53 | + def test_string_empty |
| 54 | + assert_equal(false, REXML::Functions.boolean("")) |
| 55 | + end |
| 56 | + |
| 57 | + def test_node_set_true |
| 58 | + root = REXML::Document.new("<root/>").root |
| 59 | + assert_equal(true, REXML::Functions.boolean([root])) |
| 60 | + end |
| 61 | + |
| 62 | + def test_node_set_empty |
| 63 | + assert_equal(false, REXML::Functions.boolean([])) |
| 64 | + end |
| 65 | + |
| 66 | + def test_nil |
| 67 | + assert_equal(false, REXML::Functions.boolean(nil)) |
| 68 | + end |
| 69 | + |
| 70 | + def test_context |
| 71 | + REXML::Functions.context = {node: true} |
| 72 | + assert_equal(true, REXML::Functions.boolean()) |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments