blankslate 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Portions copyright 2011 by Bart ten Brinke (info@retrosync.com).
5
- # All rights reserved.
6
-
7
- # Permission is granted for use, copying, modification, distribution,
8
- # and distribution of modified versions of this work as long as the
9
- # above copyright notice is included.
10
- #++
11
-
12
- require 'test/unit'
13
- require 'test/preload'
14
- require 'builder'
15
-
16
- class TestMethodCaching < Test::Unit::TestCase
17
-
18
- # We can directly ask if xml object responds to the cache_me or
19
- # do_not_cache_me methods because xml is derived from BasicObject
20
- # (and repond_to? is not defined in BasicObject).
21
- #
22
- # Instead we are going to stub out method_missing so that it throws
23
- # an error, and then make sure that error is either thrown or not
24
- # thrown as appropriate.
25
-
26
- def teardown
27
- super
28
- Builder::XmlBase.cache_method_calls = true
29
- end
30
-
31
- def test_caching_does_not_break_weird_symbols
32
- xml = Builder::XmlMarkup.new
33
- xml.__send__("work-order", 1)
34
- assert_equal "<work-order>1</work-order>", xml.target!
35
- end
36
-
37
- def test_method_call_caching
38
- xml = Builder::XmlMarkup.new
39
- xml.cache_me
40
-
41
- def xml.method_missing(*args)
42
- ::Kernel.fail StandardError, "SHOULD NOT BE CALLED"
43
- end
44
- assert_nothing_raised do
45
- xml.cache_me
46
- end
47
- end
48
-
49
- def test_method_call_caching_disabled
50
- Builder::XmlBase.cache_method_calls = false
51
- xml = Builder::XmlMarkup.new
52
- xml.do_not_cache_me
53
-
54
- def xml.method_missing(*args)
55
- ::Kernel.fail StandardError, "SHOULD BE CALLED"
56
- end
57
- assert_raise(StandardError, /SHOULD BE CALLED/) do
58
- xml.do_not_cache_me
59
- end
60
- end
61
-
62
- end
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
- # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
6
- # All rights reserved.
7
-
8
- # Permission is granted for use, copying, modification, distribution,
9
- # and distribution of modified versions of this work as long as the
10
- # above copyright notice is included.
11
- #++
12
-
13
- require 'test/unit'
14
- require 'builder/xchar'
15
-
16
- class TestNameCollisions < Test::Unit::TestCase
17
- module Collide
18
- def xchr
19
- end
20
- end
21
-
22
- def test_no_collision
23
- assert_nothing_raised do
24
- Builder.check_for_name_collision(Collide, :not_defined)
25
- end
26
- end
27
-
28
- def test_collision
29
- assert_raise RuntimeError do
30
- Builder.check_for_name_collision(Collide, "xchr")
31
- end
32
- end
33
-
34
- def test_collision_with_symbol
35
- assert_raise RuntimeError do
36
- Builder.check_for_name_collision(Collide, :xchr)
37
- end
38
- end
39
- end
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
- # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
6
- # All rights reserved.
7
-
8
- # Permission is granted for use, copying, modification, distribution,
9
- # and distribution of modified versions of this work as long as the
10
- # above copyright notice is included.
11
- #++
12
-
13
- #!/usr/bin/env ruby
14
-
15
- require 'test/unit'
16
- require 'builder/xchar'
17
-
18
- if String.method_defined?(:encode)
19
- class String
20
- ENCODING_BINARY = Encoding.find('BINARY')
21
-
22
- # shim method for testing purposes
23
- def to_xs(escape=true)
24
- raise NameError.new('to_xs') unless caller[0].index(__FILE__)
25
-
26
- result = Builder::XChar.encode(self)
27
- if escape
28
- result.gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}
29
- else
30
- # really only useful for testing purposes
31
- result.force_encoding(ENCODING_BINARY)
32
- end
33
- end
34
- end
35
- end
36
-
37
- class TestXmlEscaping < Test::Unit::TestCase
38
- REPLACEMENT_CHAR = Builder::XChar::REPLACEMENT_CHAR.to_xs
39
-
40
- def test_ascii
41
- assert_equal 'abc', 'abc'.to_xs
42
- end
43
-
44
- def test_predefined
45
- assert_equal '&amp;', '&'.to_xs # ampersand
46
- assert_equal '&lt;', '<'.to_xs # left angle bracket
47
- assert_equal '&gt;', '>'.to_xs # right angle bracket
48
- end
49
-
50
- def test_invalid
51
- assert_equal REPLACEMENT_CHAR, "\x00".to_xs # null
52
- assert_equal REPLACEMENT_CHAR, "\x0C".to_xs # form feed
53
- assert_equal REPLACEMENT_CHAR, "\xEF\xBF\xBF".to_xs # U+FFFF
54
- end
55
-
56
- def test_iso_8859_1
57
- assert_equal '&#231;', "\xE7".to_xs # small c cedilla
58
- assert_equal '&#169;', "\xA9".to_xs # copyright symbol
59
- end
60
-
61
- def test_win_1252
62
- assert_equal '&#8217;', "\x92".to_xs # smart quote
63
- assert_equal '&#8364;', "\x80".to_xs # euro
64
- end
65
-
66
- def test_utf8
67
- assert_equal '&#8217;', "\xE2\x80\x99".to_xs # right single quote
68
- assert_equal '&#169;', "\xC2\xA9".to_xs # copy
69
- end
70
-
71
- def test_utf8_verbatim
72
- assert_equal "\xE2\x80\x99", "\xE2\x80\x99".to_xs(false) # right single quote
73
- assert_equal "\xC2\xA9", "\xC2\xA9".to_xs(false) # copy
74
- assert_equal "\xC2\xA9&amp;\xC2\xA9",
75
- "\xC2\xA9&\xC2\xA9".to_xs(false) # copy with ampersand
76
- end
77
- end