sequence 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,204 @@
1
+ # Copyright (C) 2006 Caleb Clausen
2
+ # Distributed under the terms of Ruby's license.
3
+ $VERBOSE=1
4
+
5
+ require 'test/unit'
6
+ require 'sequence/indexed'
7
+
8
+ module Sequence::StringLike
9
+ public :group_anchors
10
+ end
11
+
12
+ class SimpleScanUntil < Test::Unit::TestCase
13
+ def test_scan_until
14
+
15
+ cu= Sequence::Indexed.new('1234')
16
+
17
+ # assert_equal '#Sequence::OfString: @data="1234" @pos=0 >', cu.inspect
18
+ assert cu.is_a?(Sequence::OfString)
19
+ assert_equal ["1234",0], cu.instance_eval{[@data,@pos]}
20
+
21
+
22
+ _=cu.scan_until(/3/)
23
+ assert_equal '123',_
24
+ assert_equal 3, cu.pos
25
+ assert_equal '4', cu.last_match.post_match.read(1)
26
+ assert_equal 3, cu.pos
27
+ end
28
+ end
29
+
30
+ class GroupAnchorsExhaustive < Test::Unit::TestCase
31
+ def setup; @cu= Sequence::OfString.new'' end
32
+
33
+ def test_unnamed
34
+ assert_nothing_thrown do
35
+
36
+ _=@cu.group_anchors(/asdfdfs$/,nil)
37
+ assert_equal "[/(?-mix:asdfdfs(?=\n))/, []]", _.inspect
38
+
39
+ _=@cu.group_anchors(/asdf(df)s$/,nil)
40
+ assert_equal "[/(?-mix:asdf(df)s(?=\n))/, []]", _.inspect
41
+
42
+ _=@cu.group_anchors(/(\Z|asdf(df)s)$/,nil)
43
+ assert_equal "[/(?-mix:((?!)|asdf(df)s)(?=\n))/, []]", _.inspect
44
+
45
+ _=@cu.group_anchors(/(\Z|asdf(df)s)$/,nil)
46
+ assert_equal "[/(?-mix:((?!)|asdf(df)s)(?=\n))/, []]", _.inspect
47
+
48
+ _=@cu.group_anchors(/(\Z|asdf(df)s)$/,true)
49
+ assert_equal "[/(\\Z|asdf(df)s)$/, []]", _.inspect
50
+
51
+ _=@cu.group_anchors(/(\A|^asdf(df)s)/,true)
52
+ assert_equal "[/(?-mix:((?!)|(^)asdf(df)s))/, [2]]", _.inspect
53
+
54
+ _=@cu.group_anchors(/(\A|^asdf(df)s)/,nil)
55
+ assert_equal "[/(\\A|^asdf(df)s)/, []]", _.inspect
56
+
57
+
58
+ _=@cu.group_anchors(/(\A|^asdf(df)s)/,true)
59
+ assert_equal "[/(?-mix:((?!)|(^)asdf(df)s))/, [2]]", _.inspect
60
+
61
+
62
+ _=@cu.group_anchors(/(\A|\^asdf(df)s)/,true)
63
+ assert_equal "[/(?-mix:((?!)|\\^asdf(df)s))/, []]", _.inspect
64
+
65
+ _=@cu.group_anchors(/(\\A|^asdf(df)s)/,nil)
66
+ assert_equal "[/(\\\\A|^asdf(df)s)/, []]", _.inspect
67
+
68
+ _=@cu.group_anchors(/(\\A|^asdf(df)s)/,true)
69
+ assert_equal "[/(?-mix:(\\\\A|(^)asdf(df)s))/, [2]]", _.inspect
70
+
71
+
72
+ _=@cu.group_anchors(/([\A]|^asdf(df)s)/,true)
73
+ assert_equal "[/(?-mix:([\\A]|(^)asdf(df)s))/, [2]]", _.inspect
74
+
75
+ _=@cu.group_anchors(/(\A|[z^]asdf(df)s)/,nil)
76
+ assert_equal "[/(\\A|[z^]asdf(df)s)/, []]", _.inspect
77
+
78
+ _=@cu.group_anchors(/(\A|[z^]asdf(df)s)/,true)
79
+ assert_equal "[/(?-mix:((?!)|[z^]asdf(df)s))/, []]", _.inspect
80
+
81
+ _=@cu.group_anchors(/([\A]|^asdf(df)s)/,nil)
82
+ assert_equal "[/([\\A]|^asdf(df)s)/, []]", _.inspect
83
+
84
+
85
+ oldVERBOSE=$VERBOSE
86
+ $VERBOSE=nil
87
+ eval <<'END'
88
+ _=@cu.group_anchors(/([\A[]|^asdf(df)s)/,true)
89
+ assert_equal "[/(?-mix:([\\A[]|(^)asdf(df)s))/, [2]]", _.inspect
90
+
91
+ _=@cu.group_anchors(/(\A|[z^[]asdf(df)s)/,nil)
92
+ assert_equal "[/(\\A|[z^[]asdf(df)s)/, []]", _.inspect
93
+
94
+ _=@cu.group_anchors(/(\A|[z^[]asdf(df)s)/,true)
95
+ assert_equal "[/(?-mix:((?!)|[z^[]asdf(df)s))/, []]", _.inspect
96
+
97
+ _=@cu.group_anchors(/([\A[]|^asdf(df)s)/,nil)
98
+ assert_equal "[/([\\A[]|^asdf(df)s)/, []]", _.inspect
99
+ END
100
+ $VERBOSE=oldVERBOSE
101
+
102
+ _=@cu.group_anchors(/([\A\[]|^asdf(df)s)/,true)
103
+ assert_equal "[/(?-mix:([\\A\\[]|(^)asdf(df)s))/, [2]]", _.inspect
104
+
105
+ _=@cu.group_anchors(/(\A|[z^\[]asdf(df)s)/,nil)
106
+ assert_equal "[/(\\A|[z^\\[]asdf(df)s)/, []]", _.inspect
107
+
108
+ _=@cu.group_anchors(/(\A|[z^\[]asdf(df)s)/,true)
109
+ assert_equal "[/(?-mix:((?!)|[z^\\[]asdf(df)s))/, []]", _.inspect
110
+
111
+ _=@cu.group_anchors(/([\A\[]|^asdf(df)s)/,nil)
112
+ assert_equal "[/([\\A\\[]|^asdf(df)s)/, []]", _.inspect
113
+
114
+
115
+ _=@cu.group_anchors(/([\A(]|^asdf(df)s)/,true)
116
+ assert_equal "[/(?-mix:([\\A(]|(^)asdf(df)s))/, [2]]", _.inspect
117
+
118
+ _=@cu.group_anchors(/(\A|[z^(]asdf(df)s)/,nil)
119
+ assert_equal "[/(\\A|[z^(]asdf(df)s)/, []]", _.inspect
120
+
121
+ _=@cu.group_anchors(/(\A|[z^(]asdf(df)s)/,true)
122
+ assert_equal "[/(?-mix:((?!)|[z^(]asdf(df)s))/, []]", _.inspect
123
+
124
+ _=@cu.group_anchors(/([\A(]|^asdf(df)s)/,nil)
125
+ assert_equal "[/([\\A(]|^asdf(df)s)/, []]", _.inspect
126
+
127
+
128
+ _=@cu.group_anchors(/([\A)]|^asdf(df)s)/,true)
129
+ assert_equal "[/(?-mix:([\\A)]|(^)asdf(df)s))/, [2]]", _.inspect
130
+
131
+ _=@cu.group_anchors(/(\A|[z^)]asdf(df)s)/,nil)
132
+ assert_equal "[/(\\A|[z^)]asdf(df)s)/, []]", _.inspect
133
+
134
+ _=@cu.group_anchors(/(\A|[z^)]asdf(df)s)/,true)
135
+ assert_equal "[/(?-mix:((?!)|[z^)]asdf(df)s))/, []]", _.inspect
136
+
137
+ _=@cu.group_anchors(/([\A)]|^asdf(df)s)/,nil)
138
+ assert_equal "[/([\\A)]|^asdf(df)s)/, []]", _.inspect
139
+
140
+
141
+ _=@cu.group_anchors(/([\A\]]|^asdf(df)s)/,true)
142
+ assert_equal "[/(?-mix:([\\A\\]]|(^)asdf(df)s))/, [2]]", _.inspect
143
+
144
+ _=@cu.group_anchors(/(\A|[z^\]]asdf(df)s)/,nil)
145
+ assert_equal "[/(\\A|[z^\\]]asdf(df)s)/, []]", _.inspect
146
+
147
+ _=@cu.group_anchors(/(\A|[z^\]]asdf(df)s)/,true)
148
+ assert_equal "[/(?-mix:((?!)|[z^\\]]asdf(df)s))/, []]", _.inspect
149
+
150
+ _=@cu.group_anchors(/([\A\]]|^asdf(df)s)/,nil)
151
+ assert_equal "[/([\\A\\]]|^asdf(df)s)/, []]", _.inspect
152
+
153
+
154
+ _=@cu.group_anchors(/fdgdsfgdsf/,nil)
155
+ assert_equal "[/fdgdsfgdsf/, []]", _.inspect
156
+
157
+ _=@cu.group_anchors(/fdgdsfgdsf/,true)
158
+ assert_equal "[/fdgdsfgdsf/, []]", _.inspect
159
+
160
+ end
161
+ end
162
+ end
163
+ class BasicMatchData < Test::Unit::TestCase
164
+ def setup
165
+ @cu="".to_sequence
166
+ end
167
+
168
+ def test_unnamed
169
+
170
+
171
+
172
+ _=md=(//.match'')
173
+
174
+ _=md= Sequence::StringLike::CorrectedMatchData.new
175
+
176
+ _=md.begins=[10,20,30,40,50]
177
+ assert_equal "[10, 20, 30, 40, 50]", _.inspect
178
+
179
+ _=md.ends=[15,25,35,45,55]
180
+ assert_equal "[15, 25, 35, 45, 55]", _.inspect
181
+
182
+ _=md.groups=%w[abcde fghij klmno pqrst uvwxy]
183
+ assert_equal "[\"abcde\", \"fghij\", \"klmno\", \"pqrst\", \"uvwxy\"]", _.inspect
184
+
185
+ _=md=@cu.fixup_match_result( md,[1,3],3,:post) do end
186
+
187
+ _=md.begin 0
188
+ assert_equal "13", _.inspect
189
+
190
+ _=md.begin 1
191
+ assert_equal "33", _.inspect
192
+
193
+ _=md.begin 2
194
+ assert_equal "53", _.inspect
195
+
196
+ _=md.begin 5
197
+ assert_equal "nil", _.inspect
198
+
199
+ _=md.begin 4
200
+ assert_equal "nil", _.inspect
201
+
202
+ assert_equal ["abcde", "klmno", "uvwxy"],md.to_a
203
+ end
204
+ end
@@ -0,0 +1,106 @@
1
+ #eric's original test code; I can't say I understand it
2
+ BEGIN{exit}
3
+ #!/bin/env ruby
4
+ #
5
+ # $Id$
6
+ #
7
+ # Run this to test non-circular sequences.
8
+ # Here is a list of the optional arguments:
9
+ #
10
+ # <iterations> : approximate number of times to test each method
11
+ # <seed> : seed for random number generation (0: none)
12
+ # <classRE> : regular expression for the classes to test ('': all)
13
+ # <methodRE> : regular expression for the methods to test ('': all)
14
+ # <flags> : Combination of bits for various flags
15
+ # 1 : disable testing of positions
16
+ # 2 : only test with strings/characters
17
+ #
18
+ # All of the standar Test::Unit auto runner options apply. The --verbose=<level>
19
+ # option is especially useful. Here are the various levels:
20
+ #
21
+ # s[ilent] : don't display anything
22
+ # p[rogress] : show a progress bar. Upon fail, show the test and seed.
23
+ # n[ormal] : show each method (and args) tested
24
+ # v[erbose] : show each method and the object state (inspect)
25
+ #
26
+ # If you want to see a demo for a particular method, usually a good command
27
+ # line would be something like this:
28
+ #
29
+ # ruby sequence/test_sequences.rb --verbose=v 10 0 Indexed '^(<method>|close)$'
30
+
31
+ require 'sequence/test'
32
+ require 'sequence/indexed'
33
+ require 'sequence/shifting'
34
+ require 'sequence/split'
35
+ require 'sequence/linked'
36
+ require 'sequence/buffered'
37
+ require 'sequence/lined'
38
+ require 'sequence/reversed'
39
+ require 'stringio'
40
+ require 'sequence/io'
41
+
42
+ # :stopdoc:
43
+
44
+ class Sequence
45
+ class Test
46
+ class Sequence < Test
47
+ def self.suite
48
+ # @reject = /to_s/ # because of Sequence::Lined
49
+ $0==__FILE__ ? super(*ARGV) : super()
50
+ end
51
+ def self.seed(before,after)
52
+ seqs = [
53
+ (before+after).to_sequence(before.size),
54
+ Sequence::Shifting.new(after+before,after.size),
55
+ Sequence::Split.new(before.clone,after.reverse),
56
+ Sequence::Linked.new(before.clone,after.reverse),
57
+ Sequence.new(Sequence::Indexed.new(before+after,before.size)),
58
+ Sequence::Buffered.new(
59
+ Sequence::Indexed.new(after.clone),
60
+ Sequence::Indexed.new(before.clone,before.size),
61
+ before.size
62
+ ),
63
+ Sequence::Reversed.new(Sequence::Indexed.new((before+after).reverse,after.size)),
64
+ ]
65
+ if @string = String===before
66
+ io=StringIO.new(before+after)
67
+ io.pos=before.size
68
+ seqs << io.to_sequence
69
+ seqs << Sequence::Buffered.new(
70
+ StringIO.new(after),
71
+ Sequence::Indexed.new(before.clone,before.size),
72
+ before.size
73
+ )
74
+ end
75
+ if rand(2).zero?
76
+ @use_positions = false
77
+ seqs << Sequence.new(Sequence::Indexed.new(before+after,before.size)).position
78
+ else
79
+ @use_positions = @flags[0].zero?
80
+ end
81
+ seqs
82
+ end
83
+ def self.plant
84
+ @characters = @flags[1].nonzero?||rand(2).zero?
85
+ super
86
+ end
87
+ def self.elements
88
+ @flags[1].nonzero? ? [?A,?B,?C] : @characters ? [?\n,?\0,?0] : [false,"",[]]
89
+ end
90
+ def self.empty
91
+ @characters&&(@flags[1].nonzero?||rand(2).zero?) ? "" : []
92
+ end
93
+ def self.reject(name,*args,&block)
94
+ case name
95
+ when :scan_pattern then !@string
96
+ when :scan_pattern_until then !@string
97
+ when :scan_pattern_while then !@string
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # :startdoc:
105
+
106
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: sequence
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2006-10-05 00:00:00 -07:00
8
+ summary: A single api for reading and writing sequential data types.
9
+ require_paths:
10
+ - lib
11
+ - test
12
+ email: sequence-owner @at@ inforadical .dot. net
13
+ homepage: http://sequence.rubyforge.org/
14
+ rubyforge_project: sequence
15
+ description: A unified wrapper api for accessing data in Strings, Arrays, Files, IOs, and Enumerations. Each sequence encapsulates some data and a current position within it. There are methods for moving the position, reading and writing data (with or without moving the position) forward or backward from the current position (or anywhere at all), scanning for patterns (like StringScanner, but it works in Files too, among others), and saving a position that will remain valid even after data is deleted or inserted elsewhere within the sequence. There are also some utility classes for making sequences reversed or circular, turning one-way sequences into two-way, buffering, and making sequences that are subsets or aggregations of existing sequences.
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Caleb Clausen
32
+ files:
33
+ - lib/assert.rb
34
+ - lib/sequence.rb
35
+ - lib/sequence/arraylike.rb
36
+ - lib/sequence/buffered.rb
37
+ - lib/sequence/circular.rb
38
+ - lib/sequence/enum.rb
39
+ - lib/sequence/file.rb
40
+ - lib/sequence/functional.rb
41
+ - lib/sequence/generator.rb
42
+ - lib/sequence/indexed.rb
43
+ - lib/sequence/io.rb
44
+ - lib/sequence/list.rb
45
+ - lib/sequence/ofhash.rb
46
+ - lib/sequence/ofobjectivars.rb
47
+ - lib/sequence/ofobjectmethods.rb
48
+ - lib/sequence/position.rb
49
+ - lib/sequence/reversed.rb
50
+ - lib/sequence/shifting.rb
51
+ - lib/sequence/singleitem.rb
52
+ - lib/sequence/stringlike.rb
53
+ - lib/sequence/subseq.rb
54
+ - lib/sequence/usedata.rb
55
+ - lib/sequence/version.rb
56
+ - lib/weakrefset.rb
57
+ - test/test.rb
58
+ - test/test_all.rb
59
+ - test/test_changes.rb
60
+ - test/test_circulars.rb
61
+ - test/test_rexscan.rb
62
+ - test/test_seqrex.rb
63
+ - test/test_sequences.rb
64
+ - Rakefile
65
+ - Manifest.txt
66
+ - README.txt
67
+ - COPYING
68
+ - GPL
69
+ test_files:
70
+ - test/test_all.rb
71
+ rdoc_options: []
72
+
73
+ extra_rdoc_files: []
74
+
75
+ executables: []
76
+
77
+ extensions: []
78
+
79
+ requirements: []
80
+
81
+ dependencies:
82
+ - !ruby/object:Gem::Dependency
83
+ name: hoe
84
+ version_requirement:
85
+ version_requirements: !ruby/object:Gem::Version::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.5
90
+ version: