diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-06 19:34:57 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-06 19:34:57 -0700 |
commit | 3b4656645f551f0ebe8b5c7e8660992bc88de123 (patch) | |
tree | 8672bb435ec295d833c4159e084608818b7c79b9 /test | |
parent | bec41aa80d5977c3f9315e3761f4d364d311960d (diff) | |
download | psych-3b4656645f551f0ebe8b5c7e8660992bc88de123.zip |
time can convert to ruby
Diffstat (limited to 'test')
-rw-r--r-- | test/test_scalar_scanner.rb | 11 | ||||
-rw-r--r-- | test/visitors/test_to_ruby.rb | 24 |
2 files changed, 35 insertions, 0 deletions
diff --git a/test/test_scalar_scanner.rb b/test/test_scalar_scanner.rb index c3b19aa..4e76082 100644 --- a/test/test_scalar_scanner.rb +++ b/test/test_scalar_scanner.rb @@ -2,6 +2,17 @@ require 'minitest/autorun' require 'psych' class TestScalarScanner < MiniTest::Unit::TestCase + def test_scan_time + [ '2001-12-15T02:59:43.1Z', + '2001-12-14t21:59:43.10-05:00', + '2001-12-14 21:59:43.10 -5', + '2001-12-15 2:59:43.10', + ].each do |time| + ss = Psych::ScalarScanner.new time + assert_equal :TIME, ss.tokenize.first + end + end + def test_scan_date date = '1980-12-16' ss = Psych::ScalarScanner.new date diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb index c60a9b9..41eae48 100644 --- a/test/visitors/test_to_ruby.rb +++ b/test/visitors/test_to_ruby.rb @@ -11,6 +11,30 @@ module Psych @visitor = ToRuby.new end + def test_time + now = Time.now + formatted = now.strftime("%Y-%m-%d %H:%M:%S") + + ".%06d %d:00" % [now.usec, now.gmt_offset / 3600] + + assert_equal now, Nodes::Scalar.new(formatted).to_ruby + end + + def test_time_utc + now = Time.now.utc + formatted = now.strftime("%Y-%m-%d %H:%M:%S") + + ".%06dZ" % [now.usec] + + assert_equal now, Nodes::Scalar.new(formatted).to_ruby + end + + def test_time_utc_no_z + now = Time.now.utc + formatted = now.strftime("%Y-%m-%d %H:%M:%S") + + ".%06d" % [now.usec] + + assert_equal now, Nodes::Scalar.new(formatted).to_ruby + end + def test_date d = '1980-12-16' actual = Date.strptime(d, '%Y-%m-%d') |