summaryrefslogtreecommitdiff
path: root/test/test_scalar_scanner.rb
blob: 5311249a782164516a8e9328c591cc5ebaef76b0 (plain)
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
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