File: test.rb

package info (click to toggle)
libxslt-ruby 0.9.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 374
  • sloc: ansic: 2,965; ruby: 333; xml: 145; makefile: 5
file content (125 lines) | stat: -rw-r--r-- 2,682 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!ruby

require "test/unit"
require "../xslt"

# Test::Unit suite for flattenx extension
#
# $Id: test.rb,v 1.4 2005/11/14 00:22:27 whateley Exp $
# $Author: whateley $

class XsltTest < Test::Unit::TestCase
  def setup 
    if @xslt.nil? == true
      @xslt = XML::XSLT.new( )
      @testOut = "<?xml version=\"1.0\"?>\nThis is a test file\n"
      @xml_simple = true
      begin
        require "xml/simple"
      rescue LoadError => e
        @xml_simple = false
      end
      
      @xml_smart = true
      begin
        require "xml/smart"
      rescue LoadError => e
        @xml_smart = false
      end
    end
  end
  
  def test_instance
    assert_instance_of( XML::XSLT, @xslt )
  end
  
  def test_from_file
    @xslt.xml = "t.xml"
    @xslt.xsl = "t.xsl"
    out = @xslt.serve
    assert_equal( @testOut, out )
  end

  def test_from_data
    @xslt.xml = IO::readlines( "t.xml" ).join
    @xslt.xsl = IO::readlines( "t.xsl" ).join
    out = @xslt.serve
    assert_equal( @testOut, out )
  end
  
  def test_from_simple
    if @xml_simple
      require 'xml/simple'
      @xslt.xml = XML::Simple.open( "t.xml" )
      @xslt.xsl = XML::Simple.open( "t.xsl" )
      out = @xslt.serve()
      assert_equal( @testOut, out )
    else
      assert( true )
    end
  end

  def test_from_smart
    if @xml_smart
      require 'xml/smart'
      @xslt.xml = XML::Smart.open( "t.xml" )
      @xslt.xsl = XML::Smart.open( "t.xsl" )
      out = @xslt.serve()
      assert_equal( @testOut, out )
    else
      assert( true ) 
    end
  end

  def test_from_rexml
    require 'rexml/document'
    @xslt.xml = REXML::Document.new File.open( "t.xml" )
    @xslt.xsl = REXML::Document.new File.open( "t.xsl" )
    out = @xslt.serve()
    assert_equal( @testOut, out )
  end

  def test_error_1
    begin
      @xslt.xsl = "nil"
    rescue => e
      assert_instance_of( XML::XSLT::ParsingError, e )
    end
  end

  def test_error_2
    begin
      @xslt.xml = "nil"
    rescue => e
      assert_instance_of( XML::XSLT::ParsingError, e )
    end
  end

  def test_error_3
    begin
      @xslt.xml = "t.xsl"
    rescue => e
      assert_instance_of( XML::XSLT::ParsingError, e )
    end
  end

  def test_base_uri_1
    @xslt.xml = "<test/>"
    xsl = "subdir/test.xsl"

    # the base URI of a loaded XSL file should be the URI of that file
    assert_nothing_raised( XML::XSLT::ParsingError ) do
      @xslt.xsl = xsl
    end
  end

  def test_base_uri_2
    @xslt.xml = "<test/>"
    xsl = File.read("subdir/test.xsl")
    
    # a file loaded from memory has no base URI, so this should fail
    assert_raises( XML::XSLT::ParsingError ) do
      @xslt.xsl = xsl
    end
  end
end