summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-10-05 13:38:56 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-10-05 13:38:56 -0700
commit3d54485fc149b65344db0272df0ed1820bbb03f3 (patch)
treeebeb95f884ca5ac65d56325974fb35395d284e7b /test
parent3027b4d69c2fe2e3f4f254e102af3834fddff2f6 (diff)
downloadpsych-3d54485fc149b65344db0272df0ed1820bbb03f3.zip
supporting dates
Diffstat (limited to 'test')
-rw-r--r--test/test_scalar_scanner.rb6
-rw-r--r--test/visitors/test_to_ruby.rb9
2 files changed, 15 insertions, 0 deletions
diff --git a/test/test_scalar_scanner.rb b/test/test_scalar_scanner.rb
index af4adc5..c3b19aa 100644
--- a/test/test_scalar_scanner.rb
+++ b/test/test_scalar_scanner.rb
@@ -2,6 +2,12 @@ require 'minitest/autorun'
require 'psych'
class TestScalarScanner < MiniTest::Unit::TestCase
+ def test_scan_date
+ date = '1980-12-16'
+ ss = Psych::ScalarScanner.new date
+ assert_equal [:DATE, date], ss.tokenize
+ end
+
def test_scan_inf
ss = Psych::ScalarScanner.new('.inf')
assert_equal [:POSITIVE_INFINITY, 1 / 0.0], ss.tokenize
diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb
index 7265316..fa7c539 100644
--- a/test/visitors/test_to_ruby.rb
+++ b/test/visitors/test_to_ruby.rb
@@ -9,6 +9,15 @@ module Psych
@visitor = ToRuby.new
end
+ def test_date
+ d = '1980-12-16'
+ actual = Date.strptime(d, '%Y-%m-%d')
+
+ date = Nodes::Scalar.new(d, nil, 'tag:yaml.org,2002:timestamp', false)
+
+ assert_equal actual, date.to_ruby
+ end
+
def test_rational
mapping = Nodes::Mapping.new nil, 'ruby/object:Rational'
mapping.children << Nodes::Scalar.new('denominator')