require "test/unit/testcase" require "rexml/document" require "rexml/validation/relaxng" class RNGValidation < Test::Unit::TestCase include REXML def test_validate rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) error( validator, %q{} ) end def test_sequence rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) end def test_choice rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_optional rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) end def test_zero_or_more rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) end def test_one_or_more rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) end def test_attribute rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) end def test_choice_attributes rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{}) no_error( validator, %q{} ) end def test_choice_attribute_element rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{}) no_error( validator, %q{} ) end def test_empty rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{Text} ) no_error( validator, %q{}) end def test_text_val rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{Text} ) error( validator, %q{}) end def test_choice_text rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{Text} ) error( validator, %q{Text} ) no_error( validator, %q{Text} ) no_error( validator, %q{} ) end def test_group rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) end def test_value # Values as text nodes rng = %q{ VaLuE } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{X} ) error( validator, %q{} ) no_error( validator, %q{VaLuE} ) # Values as text nodes, via choice rng = %q{ Option 1 Option 2 } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{XYZ} ) no_error( validator, %q{Option 1} ) no_error( validator, %q{Option 2} ) # Attribute values rng = %q{ VaLuE } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) # Attribute values via choice rng = %q{ Option 1 Option 2 } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_interleave rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) end def test_mixed rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{Text} ) no_error( validator, %q{Text} ) end def test_ref_sequence rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) error( validator, %q{} ) end def test_ref_choice rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_ref_zero_plus rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_ref_one_plus rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_ref_interleave rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_ref_recurse rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) error( validator, %q{} ) no_error( validator, %q{} ) no_error( validator, %q{} ) end def test_ref_optional rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) rng = %q{ } validator = REXML::Validation::RelaxNG.new( rng ) no_error( validator, %q{} ) no_error( validator, %q{} ) error( validator, %q{} ) error( validator, %q{} ) end def error( validator, source ) parser = REXML::Parsers::TreeParser.new( source ) parser.add_listener( validator.reset ) assert_raise( REXML::Validation::ValidationException, "Expected a validation error" ) { parser.parse } end def no_error( validator, source ) parser = REXML::Parsers::TreeParser.new( source ) parser.add_listener( validator.reset ) assert_nothing_raised { parser.parse } end end