# File tests/tokenizertester.rb, line 39 def test_entity_replacement t = NQXML::Tokenizer.new('') # add a method that lets us set the internal entity hash class << t def testSetInternalEntities(h); @internalEntities = h; end end t.testSetInternalEntities({ # as if we saw <!ENTITY...> tags 'a' => '&b;', 'b' => '&foo;', 'foo' => '&bar;', 'bar' => 'bletch', 'ugly' => 'An ampersand (&) may be escaped' + ' numerically (&#38;) or with a general' + ' entity (&amp;).' }) assert_equal('x <&> x', t.replaceAllRefsButParams('x <&> x')) assert_equal('x "\ x', t.replaceAllRefsButParams('x "' x')) assert_equal('x A x', t.replaceAllRefsButParams('x A x')) assert_equal('x A x', t.replaceAllRefsButParams('x A x')) assert_equal('&&', t.replaceAllRefsButParams('&&')) assert_equal('&', t.replaceAllRefsButParams('&')) assert_equal('&', t.replaceAllRefsButParams('&')) assert_equal('bletch', t.replaceAllRefsButParams('&bar;')) assert_equal('bletch', t.replaceAllRefsButParams('&foo;')) assert_equal('bletch', t.replaceAllRefsButParams('&b;')) assert_equal('bletch', t.replaceAllRefsButParams('&a;')) assert_equal('An ampersand (&) may be escaped' + ' numerically (&) or with a general' + ' entity (&).', t.replaceAllRefsButParams('&ugly;')) # Make sure unknown entities raise an error expect_error('x &huh; x', /entity reference '&huh;' is undefined/) end