summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_scalar_scanner.rb11
-rw-r--r--test/visitors/test_to_ruby.rb24
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')