1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
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
assert_instance_of Time, ss.tokenize(time)
end
end
attr_reader :ss
def setup
@ss = Psych::ScalarScanner.new
end
def test_scan_date
date = '1980-12-16'
token = @ss.tokenize date
assert_equal 1980, token.year
assert_equal 12, token.month
assert_equal 16, token.day
end
def test_scan_inf
assert_equal 1 / 0.0, ss.tokenize('.inf')
end
def test_scan_minus_inf
assert_equal -1 / 0.0, ss.tokenize('-.inf')
end
def test_scan_nan
assert ss.tokenize('.nan').nan?
end
def test_scan_null
assert_equal nil, ss.tokenize('null')
assert_equal nil, ss.tokenize('~')
assert_equal nil, ss.tokenize('')
end
def test_scan_symbol
assert_equal :foo, ss.tokenize(':foo')
end
def test_scan_sexagesimal_float
assert_equal 685230.15, ss.tokenize('190:20:30.15')
end
def test_scan_sexagesimal_int
assert_equal 685230, ss.tokenize('190:20:30')
end
def test_scan_float
assert_equal 1.2, ss.tokenize('1.2')
end
def test_scan_true
assert_equal true, ss.tokenize('true')
end
end
|