psych-shopifork 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +15 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.rdoc +414 -0
  6. data/Manifest.txt +113 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +72 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +36 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +538 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +579 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1392 -0
  23. data/ext/psych/yaml/config.h +11 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2335 -0
  26. data/ext/psych/yaml/loader.c +432 -0
  27. data/ext/psych/yaml/parser.c +1374 -0
  28. data/ext/psych/yaml/reader.c +465 -0
  29. data/ext/psych/yaml/scanner.c +3570 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +643 -0
  33. data/lib/psych.rb +497 -0
  34. data/lib/psych/class_loader.rb +101 -0
  35. data/lib/psych/coder.rb +94 -0
  36. data/lib/psych/core_ext.rb +35 -0
  37. data/lib/psych/deprecated.rb +85 -0
  38. data/lib/psych/exception.rb +13 -0
  39. data/lib/psych/handler.rb +249 -0
  40. data/lib/psych/handlers/document_stream.rb +22 -0
  41. data/lib/psych/handlers/recorder.rb +39 -0
  42. data/lib/psych/json/ruby_events.rb +19 -0
  43. data/lib/psych/json/stream.rb +16 -0
  44. data/lib/psych/json/tree_builder.rb +12 -0
  45. data/lib/psych/json/yaml_events.rb +29 -0
  46. data/lib/psych/nodes.rb +77 -0
  47. data/lib/psych/nodes/alias.rb +18 -0
  48. data/lib/psych/nodes/document.rb +60 -0
  49. data/lib/psych/nodes/mapping.rb +56 -0
  50. data/lib/psych/nodes/node.rb +55 -0
  51. data/lib/psych/nodes/scalar.rb +67 -0
  52. data/lib/psych/nodes/sequence.rb +81 -0
  53. data/lib/psych/nodes/stream.rb +37 -0
  54. data/lib/psych/omap.rb +4 -0
  55. data/lib/psych/parser.rb +51 -0
  56. data/lib/psych/scalar_scanner.rb +149 -0
  57. data/lib/psych/set.rb +4 -0
  58. data/lib/psych/stream.rb +37 -0
  59. data/lib/psych/streaming.rb +27 -0
  60. data/lib/psych/syntax_error.rb +21 -0
  61. data/lib/psych/tree_builder.rb +96 -0
  62. data/lib/psych/visitors.rb +6 -0
  63. data/lib/psych/visitors/depth_first.rb +26 -0
  64. data/lib/psych/visitors/emitter.rb +51 -0
  65. data/lib/psych/visitors/json_tree.rb +24 -0
  66. data/lib/psych/visitors/to_ruby.rb +372 -0
  67. data/lib/psych/visitors/visitor.rb +19 -0
  68. data/lib/psych/visitors/yaml_tree.rb +507 -0
  69. data/lib/psych/y.rb +9 -0
  70. data/test/psych/handlers/test_recorder.rb +25 -0
  71. data/test/psych/helper.rb +114 -0
  72. data/test/psych/json/test_stream.rb +109 -0
  73. data/test/psych/nodes/test_enumerable.rb +43 -0
  74. data/test/psych/test_alias_and_anchor.rb +96 -0
  75. data/test/psych/test_array.rb +57 -0
  76. data/test/psych/test_boolean.rb +36 -0
  77. data/test/psych/test_class.rb +36 -0
  78. data/test/psych/test_coder.rb +184 -0
  79. data/test/psych/test_date_time.rb +25 -0
  80. data/test/psych/test_deprecated.rb +214 -0
  81. data/test/psych/test_document.rb +46 -0
  82. data/test/psych/test_emitter.rb +94 -0
  83. data/test/psych/test_encoding.rb +254 -0
  84. data/test/psych/test_engine_manager.rb +47 -0
  85. data/test/psych/test_exception.rb +151 -0
  86. data/test/psych/test_hash.rb +44 -0
  87. data/test/psych/test_json_tree.rb +65 -0
  88. data/test/psych/test_merge_keys.rb +132 -0
  89. data/test/psych/test_nil.rb +18 -0
  90. data/test/psych/test_null.rb +19 -0
  91. data/test/psych/test_numeric.rb +45 -0
  92. data/test/psych/test_object.rb +44 -0
  93. data/test/psych/test_object_references.rb +67 -0
  94. data/test/psych/test_omap.rb +75 -0
  95. data/test/psych/test_parser.rb +339 -0
  96. data/test/psych/test_psych.rb +168 -0
  97. data/test/psych/test_safe_load.rb +97 -0
  98. data/test/psych/test_scalar.rb +11 -0
  99. data/test/psych/test_scalar_scanner.rb +106 -0
  100. data/test/psych/test_serialize_subclasses.rb +38 -0
  101. data/test/psych/test_set.rb +49 -0
  102. data/test/psych/test_stream.rb +93 -0
  103. data/test/psych/test_string.rb +153 -0
  104. data/test/psych/test_struct.rb +49 -0
  105. data/test/psych/test_symbol.rb +17 -0
  106. data/test/psych/test_tainted.rb +130 -0
  107. data/test/psych/test_to_yaml_properties.rb +63 -0
  108. data/test/psych/test_tree_builder.rb +79 -0
  109. data/test/psych/test_yaml.rb +1289 -0
  110. data/test/psych/test_yamldbm.rb +197 -0
  111. data/test/psych/test_yamlstore.rb +87 -0
  112. data/test/psych/visitors/test_depth_first.rb +49 -0
  113. data/test/psych/visitors/test_emitter.rb +144 -0
  114. data/test/psych/visitors/test_to_ruby.rb +326 -0
  115. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  116. metadata +257 -0
@@ -0,0 +1,97 @@
1
+ require 'psych/helper'
2
+
3
+ module Psych
4
+ class TestSafeLoad < TestCase
5
+ class Foo; end
6
+
7
+ [1, 2.2, {}, [], "foo"].each do |obj|
8
+ define_method(:"test_basic_#{obj.class}") do
9
+ assert_safe_cycle obj
10
+ end
11
+ end
12
+
13
+ def test_no_recursion
14
+ x = []
15
+ x << x
16
+ assert_raises(Psych::BadAlias) do
17
+ Psych.safe_load Psych.dump(x)
18
+ end
19
+ end
20
+
21
+ def test_explicit_recursion
22
+ x = []
23
+ x << x
24
+ assert_equal(x, Psych.safe_load(Psych.dump(x), [], [], true))
25
+ end
26
+
27
+ def test_symbol_whitelist
28
+ yml = Psych.dump :foo
29
+ assert_raises(Psych::DisallowedClass) do
30
+ Psych.safe_load yml
31
+ end
32
+ assert_equal(:foo, Psych.safe_load(yml, [Symbol], [:foo]))
33
+ end
34
+
35
+ def test_symbol
36
+ assert_raises(Psych::DisallowedClass) do
37
+ assert_safe_cycle :foo
38
+ end
39
+ assert_raises(Psych::DisallowedClass) do
40
+ Psych.safe_load '--- !ruby/symbol foo', []
41
+ end
42
+ assert_safe_cycle :foo, [Symbol]
43
+ assert_safe_cycle :foo, %w{ Symbol }
44
+ assert_equal :foo, Psych.safe_load('--- !ruby/symbol foo', [Symbol])
45
+ end
46
+
47
+ def test_foo
48
+ assert_raises(Psych::DisallowedClass) do
49
+ Psych.safe_load '--- !ruby/object:Foo {}', [Foo]
50
+ end
51
+ assert_raises(Psych::DisallowedClass) do
52
+ assert_safe_cycle Foo.new
53
+ end
54
+ assert_kind_of(Foo, Psych.safe_load(Psych.dump(Foo.new), [Foo]))
55
+ end
56
+
57
+ X = Struct.new(:x)
58
+ def test_struct_depends_on_sym
59
+ assert_safe_cycle(X.new, [X, Symbol])
60
+ assert_raises(Psych::DisallowedClass) do
61
+ cycle X.new, [X]
62
+ end
63
+ end
64
+
65
+ def test_anon_struct
66
+ assert Psych.safe_load(<<-eoyml, [Struct, Symbol])
67
+ --- !ruby/struct
68
+ foo: bar
69
+ eoyml
70
+
71
+ assert_raises(Psych::DisallowedClass) do
72
+ Psych.safe_load(<<-eoyml, [Struct])
73
+ --- !ruby/struct
74
+ foo: bar
75
+ eoyml
76
+ end
77
+
78
+ assert_raises(Psych::DisallowedClass) do
79
+ Psych.safe_load(<<-eoyml, [Symbol])
80
+ --- !ruby/struct
81
+ foo: bar
82
+ eoyml
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def cycle object, whitelist = []
89
+ Psych.safe_load(Psych.dump(object), whitelist)
90
+ end
91
+
92
+ def assert_safe_cycle object, whitelist = []
93
+ other = cycle object, whitelist
94
+ assert_equal object, other
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative 'helper'
4
+
5
+ module Psych
6
+ class TestScalar < TestCase
7
+ def test_utf_8
8
+ assert_equal "日本語", Psych.load("--- 日本語")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,106 @@
1
+ require_relative 'helper'
2
+ require 'date'
3
+
4
+ module Psych
5
+ class TestScalarScanner < TestCase
6
+ attr_reader :ss
7
+
8
+ def setup
9
+ super
10
+ @ss = Psych::ScalarScanner.new ClassLoader.new
11
+ end
12
+
13
+ def test_scan_time
14
+ { '2001-12-15T02:59:43.1Z' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
15
+ '2001-12-14t21:59:43.10-05:00' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
16
+ '2001-12-14 21:59:43.10 -5' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
17
+ '2001-12-15 2:59:43.10' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
18
+ '2011-02-24 11:17:06 -0800' => Time.utc(2011, 02, 24, 19, 17, 06)
19
+ }.each do |time_str, time|
20
+ assert_equal time, @ss.tokenize(time_str)
21
+ end
22
+ end
23
+
24
+ def test_scan_bad_time
25
+ [ '2001-12-15T02:59:73.1Z',
26
+ '2001-12-14t90:59:43.10-05:00',
27
+ '2001-92-14 21:59:43.10 -5',
28
+ '2001-12-15 92:59:43.10',
29
+ '2011-02-24 81:17:06 -0800',
30
+ ].each do |time_str|
31
+ assert_equal time_str, @ss.tokenize(time_str)
32
+ end
33
+ end
34
+
35
+ def test_scan_bad_dates
36
+ x = '2000-15-01'
37
+ assert_equal x, @ss.tokenize(x)
38
+
39
+ x = '2000-10-51'
40
+ assert_equal x, @ss.tokenize(x)
41
+
42
+ x = '2000-10-32'
43
+ assert_equal x, @ss.tokenize(x)
44
+ end
45
+
46
+ def test_scan_good_edge_date
47
+ x = '2000-1-31'
48
+ assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
49
+ end
50
+
51
+ def test_scan_bad_edge_date
52
+ x = '2000-11-31'
53
+ assert_equal x, @ss.tokenize(x)
54
+ end
55
+
56
+ def test_scan_date
57
+ date = '1980-12-16'
58
+ token = @ss.tokenize date
59
+ assert_equal 1980, token.year
60
+ assert_equal 12, token.month
61
+ assert_equal 16, token.day
62
+ end
63
+
64
+ def test_scan_inf
65
+ assert_equal(1 / 0.0, ss.tokenize('.inf'))
66
+ end
67
+
68
+ def test_scan_minus_inf
69
+ assert_equal(-1 / 0.0, ss.tokenize('-.inf'))
70
+ end
71
+
72
+ def test_scan_nan
73
+ assert ss.tokenize('.nan').nan?
74
+ end
75
+
76
+ def test_scan_null
77
+ assert_equal nil, ss.tokenize('null')
78
+ assert_equal nil, ss.tokenize('~')
79
+ assert_equal nil, ss.tokenize('')
80
+ end
81
+
82
+ def test_scan_symbol
83
+ assert_equal :foo, ss.tokenize(':foo')
84
+ end
85
+
86
+ def test_scan_sexagesimal_float
87
+ assert_equal 685230.15, ss.tokenize('190:20:30.15')
88
+ end
89
+
90
+ def test_scan_sexagesimal_int
91
+ assert_equal 685230, ss.tokenize('190:20:30')
92
+ end
93
+
94
+ def test_scan_float
95
+ assert_equal 1.2, ss.tokenize('1.2')
96
+ end
97
+
98
+ def test_scan_true
99
+ assert_equal true, ss.tokenize('true')
100
+ end
101
+
102
+ def test_scan_strings_starting_with_underscores
103
+ assert_equal "_100", ss.tokenize('_100')
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestSerializeSubclasses < TestCase
5
+ class SomeObject
6
+ def initialize one, two
7
+ @one = one
8
+ @two = two
9
+ end
10
+
11
+ def == other
12
+ @one == other.instance_eval { @one } &&
13
+ @two == other.instance_eval { @two }
14
+ end
15
+ end
16
+
17
+ def test_some_object
18
+ so = SomeObject.new('foo', [1,2,3])
19
+ assert_equal so, Psych.load(Psych.dump(so))
20
+ end
21
+
22
+ class StructSubclass < Struct.new(:foo)
23
+ def initialize foo, bar
24
+ super(foo)
25
+ @bar = bar
26
+ end
27
+
28
+ def == other
29
+ super(other) && @bar == other.instance_eval{ @bar }
30
+ end
31
+ end
32
+
33
+ def test_struct_subclass
34
+ so = StructSubclass.new('foo', [1,2,3])
35
+ assert_equal so, Psych.load(Psych.dump(so))
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestSet < TestCase
5
+ def setup
6
+ super
7
+ @set = Psych::Set.new
8
+ @set['foo'] = 'bar'
9
+ @set['bar'] = 'baz'
10
+ end
11
+
12
+ def test_dump
13
+ assert_match(/!set/, Psych.dump(@set))
14
+ end
15
+
16
+ def test_roundtrip
17
+ assert_cycle(@set)
18
+ end
19
+
20
+ ###
21
+ # FIXME: Syck should also support !!set as shorthand
22
+ def test_load_from_yaml
23
+ loaded = Psych.load(<<-eoyml)
24
+ --- !set
25
+ foo: bar
26
+ bar: baz
27
+ eoyml
28
+ assert_equal(@set, loaded)
29
+ end
30
+
31
+ def test_loaded_class
32
+ assert_instance_of(Psych::Set, Psych.load(Psych.dump(@set)))
33
+ end
34
+
35
+ def test_set_shorthand
36
+ loaded = Psych.load(<<-eoyml)
37
+ --- !!set
38
+ foo: bar
39
+ bar: baz
40
+ eoyml
41
+ assert_instance_of(Psych::Set, loaded)
42
+ end
43
+
44
+ def test_set_self_reference
45
+ @set['self'] = @set
46
+ assert_cycle(@set)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,93 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestStream < TestCase
5
+ def test_parse_partial
6
+ rb = Psych.parse("--- foo\n...\n--- `").to_ruby
7
+ assert_equal 'foo', rb
8
+ end
9
+
10
+ def test_load_partial
11
+ rb = Psych.load("--- foo\n...\n--- `")
12
+ assert_equal 'foo', rb
13
+ end
14
+
15
+ def test_parse_stream_yields_documents
16
+ list = []
17
+ Psych.parse_stream("--- foo\n...\n--- bar") do |doc|
18
+ list << doc.to_ruby
19
+ end
20
+ assert_equal %w{ foo bar }, list
21
+ end
22
+
23
+ def test_parse_stream_break
24
+ list = []
25
+ Psych.parse_stream("--- foo\n...\n--- `") do |doc|
26
+ list << doc.to_ruby
27
+ break
28
+ end
29
+ assert_equal %w{ foo }, list
30
+ end
31
+
32
+ def test_load_stream_yields_documents
33
+ list = []
34
+ Psych.load_stream("--- foo\n...\n--- bar") do |ruby|
35
+ list << ruby
36
+ end
37
+ assert_equal %w{ foo bar }, list
38
+ end
39
+
40
+ def test_load_stream_break
41
+ list = []
42
+ Psych.load_stream("--- foo\n...\n--- `") do |ruby|
43
+ list << ruby
44
+ break
45
+ end
46
+ assert_equal %w{ foo }, list
47
+ end
48
+
49
+ def test_explicit_documents
50
+ io = StringIO.new
51
+ stream = Psych::Stream.new(io)
52
+ stream.start
53
+ stream.push({ 'foo' => 'bar' })
54
+
55
+ assert !stream.finished?, 'stream not finished'
56
+ stream.finish
57
+ assert stream.finished?, 'stream finished'
58
+
59
+ assert_match(/^---/, io.string)
60
+ assert_match(/\.\.\.$/, io.string)
61
+ end
62
+
63
+ def test_start_takes_block
64
+ io = StringIO.new
65
+ stream = Psych::Stream.new(io)
66
+ stream.start do |emitter|
67
+ emitter.push({ 'foo' => 'bar' })
68
+ end
69
+
70
+ assert stream.finished?, 'stream finished'
71
+ assert_match(/^---/, io.string)
72
+ assert_match(/\.\.\.$/, io.string)
73
+ end
74
+
75
+ def test_no_backreferences
76
+ io = StringIO.new
77
+ stream = Psych::Stream.new(io)
78
+ stream.start do |emitter|
79
+ x = { 'foo' => 'bar' }
80
+ emitter.push x
81
+ emitter.push x
82
+ end
83
+
84
+ assert stream.finished?, 'stream finished'
85
+ assert_match(/^---/, io.string)
86
+ assert_match(/\.\.\.$/, io.string)
87
+ assert_equal 2, io.string.scan('---').length
88
+ assert_equal 2, io.string.scan('...').length
89
+ assert_equal 2, io.string.scan('foo').length
90
+ assert_equal 2, io.string.scan('bar').length
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,153 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestString < TestCase
5
+ class X < String
6
+ end
7
+
8
+ class Y < String
9
+ attr_accessor :val
10
+ end
11
+
12
+ class Z < String
13
+ def initialize
14
+ force_encoding Encoding::US_ASCII
15
+ end
16
+ end
17
+
18
+ def test_doublequotes_when_there_is_a_single
19
+ yaml = Psych.dump "@123'abc"
20
+ assert_match(/---\s*"/, yaml)
21
+ end
22
+
23
+ def test_dash_dot
24
+ assert_cycle '-.'
25
+ assert_cycle '+.'
26
+ end
27
+
28
+ def test_string_subclass_with_anchor
29
+ y = Psych.load <<-eoyml
30
+ ---
31
+ body:
32
+ string: &70121654388580 !ruby/string
33
+ str: ! 'foo'
34
+ x:
35
+ body: *70121654388580
36
+ eoyml
37
+ assert_equal({"body"=>{"string"=>"foo", "x"=>{"body"=>"foo"}}}, y)
38
+ end
39
+
40
+ def test_self_referential_string
41
+ y = Psych.load <<-eoyml
42
+ ---
43
+ string: &70121654388580 !ruby/string
44
+ str: ! 'foo'
45
+ body: *70121654388580
46
+ eoyml
47
+
48
+ assert_equal({"string"=>"foo"}, y)
49
+ value = y['string']
50
+ assert_equal value, value.instance_variable_get(:@body)
51
+ end
52
+
53
+ def test_another_subclass_with_attributes
54
+ y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
55
+ assert_equal "foo", y
56
+ assert_equal Y, y.class
57
+ assert_equal 1, y.val
58
+ end
59
+
60
+ def test_backwards_with_syck
61
+ x = Psych.load "--- !str:#{X.name} foo\n\n"
62
+ assert_equal X, x.class
63
+ assert_equal 'foo', x
64
+ end
65
+
66
+ def test_empty_subclass
67
+ assert_match "!ruby/string:#{X}", Psych.dump(X.new)
68
+ x = Psych.load Psych.dump X.new
69
+ assert_equal X, x.class
70
+ end
71
+
72
+ def test_empty_character_subclass
73
+ assert_match "!ruby/string:#{Z}", Psych.dump(Z.new)
74
+ x = Psych.load Psych.dump Z.new
75
+ assert_equal Z, x.class
76
+ end
77
+
78
+ def test_subclass_with_attributes
79
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
80
+ assert_equal Y, y.class
81
+ assert_equal 1, y.val
82
+ end
83
+
84
+ def test_string_with_base_60
85
+ yaml = Psych.dump '01:03:05'
86
+ assert_match "'01:03:05'", yaml
87
+ assert_equal '01:03:05', Psych.load(yaml)
88
+ end
89
+
90
+ def test_nonascii_string_as_binary
91
+ string = "hello \x80 world!"
92
+ string.force_encoding 'ascii-8bit'
93
+ yml = Psych.dump string
94
+ assert_match(/binary/, yml)
95
+ assert_equal string, Psych.load(yml)
96
+ end
97
+
98
+ def test_binary_string_null
99
+ string = "\x00"
100
+ yml = Psych.dump string
101
+ assert_match(/binary/, yml)
102
+ assert_equal string, Psych.load(yml)
103
+ end
104
+
105
+ def test_binary_string
106
+ string = binary_string
107
+ yml = Psych.dump string
108
+ assert_match(/binary/, yml)
109
+ assert_equal string, Psych.load(yml)
110
+ end
111
+
112
+ def test_non_binary_string
113
+ string = binary_string(0.29)
114
+ yml = Psych.dump string
115
+ refute_match(/binary/, yml)
116
+ assert_equal string, Psych.load(yml)
117
+ end
118
+
119
+ def test_ascii_only_8bit_string
120
+ string = "abc".encode(Encoding::ASCII_8BIT)
121
+ yml = Psych.dump string
122
+ refute_match(/binary/, yml)
123
+ assert_equal string, Psych.load(yml)
124
+ end
125
+
126
+ def test_string_with_ivars
127
+ food = "is delicious"
128
+ ivar = "on rock and roll"
129
+ food.instance_variable_set(:@we_built_this_city, ivar)
130
+
131
+ str = Psych.load Psych.dump food
132
+ assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
133
+ end
134
+
135
+ def test_binary
136
+ string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*')
137
+ assert_cycle string
138
+ end
139
+
140
+ def test_float_confusion
141
+ assert_cycle '1.'
142
+ end
143
+
144
+ def binary_string percentage = 0.31, length = 100
145
+ string = ''
146
+ (percentage * length).to_i.times do |i|
147
+ string << "\b"
148
+ end
149
+ string << 'a' * (length - string.length)
150
+ string
151
+ end
152
+ end
153
+ end