File: test-parser-yaml.rb

package info (click to toggle)
kwalify 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,860 kB
  • ctags: 1,188
  • sloc: ruby: 8,446; xml: 170; makefile: 37; java: 36
file content (57 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (5)
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
###
### $Rev$
### $Release: 0.7.2 $
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
###

require File.dirname(__FILE__) + '/test.rb'



class YamlParserTest < Test::Unit::TestCase

  filename = __FILE__.sub(/\.rb$/, '.yaml')
  load_yaml_testdata(filename, :lang=>'ruby')

  def _test()
    if @exception
      @error_class = @exception.split(/::/).inject(Kernel) { |c,s| c = c.const_get(s) }
    end
    parser = Kwalify::Yaml::Parser.new()
    @testopts ||= {}
    parser.preceding_alias = true if @testopts['preceding_alias']
    if @error_class
      ex = assert_raise(@error_class) do
        doc = parser.parse(@input)
      end
    else
      doc = parser.parse(@input)
      if @testopts['pp'] || @testopts['recursive']
        s = StringWriter.new
        PP.pp(doc, s)
        actual = s
      else
        actual = doc.inspect + "\n"
      end
      if $log
        File.open("#{@name}.expected", 'w') { |f| f.write(@expected) }
        File.open("#{@name}.actual", 'w') { |f| f.write(actual) }
      end
      if $print
        print actual
      else
        assert_text_equal(@expected, actual)
        #t = parser.instance_variable_get("@location_table")
        #require 'pp'
        if @locations
          @locations.each do |path, expected_linenum, expected_column|
            linenum, column = parser.location(path)
            assert_equal(expected_linenum, linenum)
            assert_equal(expected_column, column)
          end
        end
      end
    end
  end

end