Sha256: 2ad10a61c4f11059daca96e20d12e7e132ca260998f314b01e74caba4cf9a0a6

Contents?: true

Size: 1.94 KB

Versions: 69

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'
require 'tins'

module Tins
  class NullTest < Test::Unit::TestCase
    require 'tins/xt/null'

    def test_null
      assert_equal NULL, NULL.foo
      assert_equal NULL, NULL.foo.bar
      assert_equal 'NULL', NULL.inspect
      assert_equal '', NULL.to_s
      assert_equal 0, NULL.to_i
      assert_equal 0.0, NULL.to_f
      assert_equal [], NULL.to_a
      assert_equal 1, null(1)
      assert_equal 1, Null(1)
      assert_equal NULL, null(nil)
      assert_equal NULL, Null(nil)
      assert_equal NULL, NULL::NULL
      assert NULL.nil?
      assert NULL.blank?
      assert_equal nil, NULL.as_json
      assert_equal 'null', NULL.to_json
    end

    def test_null_plus
      assert_equal 1, null_plus(value: 1)
      assert_equal 1, NullPlus(value: 1)
      assert_kind_of Tins::NullPlus, null_plus(value: nil)
      assert_kind_of Tins::NullPlus, NullPlus(value: nil)
      assert_kind_of Tins::NullPlus, null_plus
      assert_kind_of Tins::NullPlus, NullPlus()
      assert_kind_of Tins::NullPlus, null_plus.foo
      assert_kind_of Tins::NullPlus, null_plus.foo.bar
      assert_kind_of Tins::NullPlus, NullPlus().foo
      assert_kind_of Tins::NullPlus, NullPlus().foo.bar
      assert null_plus.nil?
      assert null_plus().blank?
      assert_equal nil, null_plus().as_json
      assert_equal 'null', null_plus.to_json
      assert NullPlus().nil?
      assert NullPlus().blank?
      assert_equal nil, NullPlus().as_json
      assert_equal 'null', NullPlus().to_json
    end

    def foo
      1 / 0
    rescue => e
      null_plus(error: e)
    end

    def test_null_plus_caller_and_misc
      assert_match(/foo/, foo.caller.first)
      if foo.respond_to?(:caller_locations)
        assert_kind_of Thread::Backtrace::Location, foo.caller_locations.first
        assert_match(/foo/, foo.caller_locations.first.to_s)
      end
      assert_match(/foo/, foo.caller.first)
      assert_kind_of ZeroDivisionError, foo.error
    end
  end
end

Version data entries

69 entries across 58 versions & 2 rubygems

Version Path
tins-1.34.0 tests/null_test.rb
tins-1.33.0 tests/null_test.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/null_test.rb
tins-1.32.1 tests/null_test.rb
tins-1.32.0 tests/null_test.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/null_test.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/null_test.rb
tins-1.31.1 tests/null_test.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/tests/null_test.rb
tins-1.31.0 tests/null_test.rb
tins-1.30.0 tests/null_test.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/null_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/null_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/tests/null_test.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/null_test.rb