summaryrefslogtreecommitdiff
path: root/test/rexml/functions/test_boolean.rb
diff options
context:
space:
mode:
authorKouhei Sutou <[email protected]>2019-05-25 17:58:49 +0900
committerHiroshi SHIBATA <[email protected]>2019-08-04 11:55:43 +0900
commit643344dc9460626617c9ce88f07b3ae0fed49150 (patch)
treef8fd1055293a32a7568467fd7c86af34412f8918 /test/rexml/functions/test_boolean.rb
parent5f78b138b10a6732676689f0f8690c1db16c1355 (diff)
[ruby/rexml] xpath local_name: fix a bug that nil is returned for nonexistent case
It must be an empty string. https://github.com/ruby/rexml/commit/81bc7cd4f5
Diffstat (limited to 'test/rexml/functions/test_boolean.rb')
-rw-r--r--test/rexml/functions/test_boolean.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/rexml/functions/test_boolean.rb b/test/rexml/functions/test_boolean.rb
new file mode 100644
index 0000000000..b3e2117c10
--- /dev/null
+++ b/test/rexml/functions/test_boolean.rb
@@ -0,0 +1,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