[ruby/psych] Eagerly require date
.
https://github.com/ruby/psych/commit/b2aa0032c0
This commit is contained in:
parent
577e6a3e19
commit
2bf5d26eb9
@ -1,4 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
require 'date'
|
||||||
|
|
||||||
require_relative 'psych/versions'
|
require_relative 'psych/versions'
|
||||||
case RUBY_ENGINE
|
case RUBY_ENGINE
|
||||||
when 'jruby'
|
when 'jruby'
|
||||||
|
@ -4,8 +4,6 @@ module Psych
|
|||||||
###
|
###
|
||||||
# Scan scalars for built in types
|
# Scan scalars for built in types
|
||||||
class ScalarScanner
|
class ScalarScanner
|
||||||
autoload :Date, "date"
|
|
||||||
|
|
||||||
# Taken from http://yaml.org/type/timestamp.html
|
# Taken from http://yaml.org/type/timestamp.html
|
||||||
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/
|
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ module Psych
|
|||||||
class_loader.big_decimal._load o.value
|
class_loader.big_decimal._load o.value
|
||||||
when "!ruby/object:DateTime"
|
when "!ruby/object:DateTime"
|
||||||
class_loader.date_time
|
class_loader.date_time
|
||||||
require 'date' unless defined? DateTime
|
|
||||||
t = @ss.parse_time(o.value)
|
t = @ss.parse_time(o.value)
|
||||||
DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
|
DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
|
||||||
(t.subsec/86400)
|
(t.subsec/86400)
|
||||||
|
@ -75,6 +75,8 @@ DESCRIPTION
|
|||||||
s.add_dependency 'stringio'
|
s.add_dependency 'stringio'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
s.add_dependency 'date'
|
||||||
|
|
||||||
s.metadata['msys2_mingw_dependencies'] = 'libyaml'
|
s.metadata['msys2_mingw_dependencies'] = 'libyaml'
|
||||||
s.metadata['changelog_uri'] = s.homepage + '/releases'
|
s.metadata['changelog_uri'] = s.homepage + '/releases'
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'date'
|
|
||||||
|
|
||||||
require 'psych'
|
require 'psych'
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
require 'date'
|
|
||||||
|
|
||||||
module Psych
|
module Psych
|
||||||
class TestDateTime < TestCase
|
class TestDateTime < TestCase
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
require 'date'
|
|
||||||
|
|
||||||
module Psych
|
module Psych
|
||||||
class TestScalarScanner < TestCase
|
class TestScalarScanner < TestCase
|
||||||
|
@ -50,6 +50,16 @@ module Psych
|
|||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_single_quote_when_matching_date
|
||||||
|
pend "Failing on JRuby" if RUBY_PLATFORM =~ /java/
|
||||||
|
|
||||||
|
lib = File.expand_path("../../../lib", __FILE__)
|
||||||
|
assert_separately(["-I", lib, "-r", "psych"], __FILE__, __LINE__ + 1, <<~'RUBY')
|
||||||
|
yml = Psych.dump('2024-11-19')
|
||||||
|
assert_equal '2024-11-19', Psych.load(yml)
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
def test_plain_when_shorten_than_line_width_and_no_final_line_break
|
def test_plain_when_shorten_than_line_width_and_no_final_line_break
|
||||||
str = "Lorem ipsum"
|
str = "Lorem ipsum"
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user