summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-30 14:32:35 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-30 14:32:35 -0700
commit0fdc41a6e3ab790e58db0e0f54affe5d2a8277f2 (patch)
tree023b528b6e33f4756c03960fccf96b8258ee9790 /test
parent211251bab57a5535e47832b75176096e087c89b0 (diff)
downloadpsych-0fdc41a6e3ab790e58db0e0f54affe5d2a8277f2.zip
using the same logic for string emitting and parsing
Diffstat (limited to 'test')
-rw-r--r--test/test_scalar_scanner.rb51
-rw-r--r--test/visitors/test_to_ruby.rb18
2 files changed, 69 insertions, 0 deletions
diff --git a/test/test_scalar_scanner.rb b/test/test_scalar_scanner.rb
new file mode 100644
index 0000000..5311249
--- /dev/null
+++ b/test/test_scalar_scanner.rb
@@ -0,0 +1,51 @@
+require 'minitest/autorun'
+require 'psych'
+
+class TestScalarScanner < MiniTest::Unit::TestCase
+ def test_scan_inf
+ ss = Psych::ScalarScanner.new('.inf')
+ assert_equal [:POSITIVE_INFINITY, 1 / 0.0], ss.tokenize
+ end
+
+ def test_scan_minus_inf
+ ss = Psych::ScalarScanner.new('-.inf')
+ assert_equal [:NEGATIVE_INFINITY, -1 / 0.0], ss.tokenize
+ end
+
+ def test_scan_nan
+ ss = Psych::ScalarScanner.new('.nan')
+ assert_equal :NAN, ss.tokenize.first
+ assert ss.tokenize.last.nan?
+ end
+
+ def test_scan_null
+ ss = Psych::ScalarScanner.new('null')
+ assert_equal [:NULL, nil], ss.tokenize
+
+ ss = Psych::ScalarScanner.new('~')
+ assert_equal [:NULL, nil], ss.tokenize
+
+ ss = Psych::ScalarScanner.new('')
+ assert_equal [:NULL, nil], ss.tokenize
+ end
+
+ def test_scan_symbol
+ ss = Psych::ScalarScanner.new(':foo')
+ assert_equal [:SYMBOL, :foo], ss.tokenize
+ end
+
+ def test_scan_sexagesimal_float
+ ss = Psych::ScalarScanner.new('190:20:30.15')
+ assert_equal [:FLOAT, 685230.15], ss.tokenize
+ end
+
+ def test_scan_sexagesimal_int
+ ss = Psych::ScalarScanner.new('190:20:30')
+ assert_equal [:INTEGER, 685230], ss.tokenize
+ end
+
+ def test_scan_float
+ ss = Psych::ScalarScanner.new('1.2')
+ assert_equal [:FLOAT, 1.2], ss.tokenize
+ end
+end
diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb
index 6facc68..0dafbd8 100644
--- a/test/visitors/test_to_ruby.rb
+++ b/test/visitors/test_to_ruby.rb
@@ -21,6 +21,24 @@ module Psych
assert_equal 1, Nodes::Scalar.new('+1').to_ruby
end
+ def test_int_ignore
+ ['1,000', '1_000'].each do |num|
+ i = Nodes::Scalar.new(num, nil, 'tag:yaml.org,2002:int')
+ assert_equal 1000, i.to_ruby
+
+ assert_equal 1000, Nodes::Scalar.new(num).to_ruby
+ end
+ end
+
+ def test_float_ignore
+ ['1,000.3', '1_000.3'].each do |num|
+ i = Nodes::Scalar.new(num, nil, 'tag:yaml.org,2002:float')
+ assert_equal 1000.3, i.to_ruby
+
+ assert_equal 1000.3, Nodes::Scalar.new(num).to_ruby
+ end
+ end
+
def test_float
i = Nodes::Scalar.new('1.2', nil, 'tag:yaml.org,2002:float')
assert_equal 1.2, i.to_ruby