motion-strscan 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +63 -0
  3. data/lib/motion-strscan/string.rb +20 -0
  4. data/lib/motion-strscan/strscan.rb +676 -0
  5. data/lib/motion-strscan/version.rb +3 -0
  6. data/lib/motion-strscan.rb +8 -0
  7. data/spec/helpers/it_behaves_like.rb +27 -0
  8. data/spec/string_spec/_shared/slice.rb +244 -0
  9. data/spec/string_spec/byteslice_spec.rb +21 -0
  10. data/spec/strscan_spec/_shared/bol.rb +25 -0
  11. data/spec/strscan_spec/_shared/concat.rb +31 -0
  12. data/spec/strscan_spec/_shared/eos.rb +17 -0
  13. data/spec/strscan_spec/_shared/extract_range.rb +22 -0
  14. data/spec/strscan_spec/_shared/extract_range_matched.rb +22 -0
  15. data/spec/strscan_spec/_shared/get_byte.rb +28 -0
  16. data/spec/strscan_spec/_shared/matched_size.rb +21 -0
  17. data/spec/strscan_spec/_shared/peek.rb +44 -0
  18. data/spec/strscan_spec/_shared/pos.rb +83 -0
  19. data/spec/strscan_spec/_shared/rest_size.rb +18 -0
  20. data/spec/strscan_spec/_shared/terminate.rb +17 -0
  21. data/spec/strscan_spec/append_spec.rb +7 -0
  22. data/spec/strscan_spec/beginning_of_line_spec.rb +3 -0
  23. data/spec/strscan_spec/bol_spec.rb +3 -0
  24. data/spec/strscan_spec/check_spec.rb +13 -0
  25. data/spec/strscan_spec/check_until_spec.rb +14 -0
  26. data/spec/strscan_spec/clear_spec.rb +21 -0
  27. data/spec/strscan_spec/concat_spec.rb +7 -0
  28. data/spec/strscan_spec/dup_spec.rb +36 -0
  29. data/spec/strscan_spec/element_reference_spec.rb +46 -0
  30. data/spec/strscan_spec/empty_spec.rb +21 -0
  31. data/spec/strscan_spec/eos_spec.rb +3 -0
  32. data/spec/strscan_spec/exist_spec.rb +21 -0
  33. data/spec/strscan_spec/get_byte_spec.rb +3 -0
  34. data/spec/strscan_spec/getbyte_spec.rb +23 -0
  35. data/spec/strscan_spec/getch_spec.rb +41 -0
  36. data/spec/strscan_spec/initialize_spec.rb +25 -0
  37. data/spec/strscan_spec/inspect_spec.rb +17 -0
  38. data/spec/strscan_spec/match_spec.rb +25 -0
  39. data/spec/strscan_spec/matched_size_spec.rb +3 -0
  40. data/spec/strscan_spec/matched_spec.rb +37 -0
  41. data/spec/strscan_spec/matchedsize_spec.rb +23 -0
  42. data/spec/strscan_spec/must_C_version_spec.rb +5 -0
  43. data/spec/strscan_spec/peek_spec.rb +4 -0
  44. data/spec/strscan_spec/peep_spec.rb +21 -0
  45. data/spec/strscan_spec/pointer_spec.rb +7 -0
  46. data/spec/strscan_spec/pos_spec.rb +7 -0
  47. data/spec/strscan_spec/post_match_spec.rb +24 -0
  48. data/spec/strscan_spec/pre_match_spec.rb +37 -0
  49. data/spec/strscan_spec/reset_spec.rb +12 -0
  50. data/spec/strscan_spec/rest_size_spec.rb +3 -0
  51. data/spec/strscan_spec/rest_spec.rb +44 -0
  52. data/spec/strscan_spec/restsize_spec.rb +21 -0
  53. data/spec/strscan_spec/scan_full_spec.rb +27 -0
  54. data/spec/strscan_spec/scan_spec.rb +50 -0
  55. data/spec/strscan_spec/scan_until_spec.rb +20 -0
  56. data/spec/strscan_spec/search_full_spec.rb +27 -0
  57. data/spec/strscan_spec/skip_spec.rb +15 -0
  58. data/spec/strscan_spec/skip_until_spec.rb +15 -0
  59. data/spec/strscan_spec/string_spec.rb +37 -0
  60. data/spec/strscan_spec/terminate_spec.rb +3 -0
  61. data/spec/strscan_spec/unscan_spec.rb +26 -0
  62. metadata +172 -0
@@ -0,0 +1,15 @@
1
+ describe "StringScanner#skip" do
2
+ before do
3
+ @s = StringScanner.new("This is a test")
4
+ end
5
+
6
+ it "returns length of the match" do
7
+ @s.skip(/\w+/).should == 4
8
+ @s.skip(/\s+\w+/).should == 3
9
+ end
10
+
11
+ it "returns nil if there's no match" do
12
+ @s.skip(/\s+/).should == nil
13
+ @s.skip(/\d+/).should == nil
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ describe "StringScanner#skip_until" do
2
+ before do
3
+ @s = StringScanner.new("This is a test")
4
+ end
5
+
6
+ it "returns the number of bytes advanced and advances the scan pointer until pattern is matched and consumed" do
7
+ @s.skip_until(/a/).should == 9
8
+ @s.pos.should == 9
9
+ @s.matched.should == "a"
10
+ end
11
+
12
+ it "returns nil if no match was found" do
13
+ @s.skip_until(/d+/).should == nil
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ describe "StringScanner#string" do
2
+ before do
3
+ @string = "This is a test"
4
+ @s = StringScanner.new(@string)
5
+ end
6
+
7
+ it "returns the string being scanned" do
8
+ @s.string.should == "This is a test"
9
+ @s << " case"
10
+ @s.string.should == "This is a test case"
11
+ end
12
+
13
+ it "returns the identical object passed in" do
14
+ @s.string.equal?(@string).should.be_true
15
+ end
16
+ end
17
+
18
+ describe "StringScanner#string=" do
19
+ before do
20
+ @s = StringScanner.new("This is a test")
21
+ end
22
+
23
+ it "changes the string being scanned to the argument and resets the scanner" do
24
+ @s.string = "Hello world"
25
+ @s.string.should == "Hello world"
26
+ end
27
+
28
+ # TODO it "converts the argument into a string using #to_str" do
29
+ # m = mock(:str)
30
+ #
31
+ # s = "test"
32
+ # m.should.receive(:to_str).and.return(s)
33
+ #
34
+ # @s.string = m
35
+ # @s.string.should == s
36
+ # end
37
+ end
@@ -0,0 +1,3 @@
1
+ describe "StringScanner#terminate" do
2
+ it_behaves_like(:strscan_terminate, :terminate)
3
+ end
@@ -0,0 +1,26 @@
1
+ describe "StringScanner#unscan" do
2
+ before do
3
+ @s = StringScanner.new("This is a test")
4
+ end
5
+
6
+ it "set the scan pointer to the previous position" do
7
+ @s.scan(/This/)
8
+ @s.unscan
9
+ @s.matched.should == nil
10
+ @s.pos.should == 0
11
+ end
12
+
13
+ it "remember only one previous position" do
14
+ pos1 = @s.pos
15
+ @s.scan(/This/)
16
+ pos2 = @s.pos
17
+ @s.scan(/ is/)
18
+ @s.unscan
19
+ @s.pos.should == pos2
20
+ end
21
+
22
+ it "raises a ScanError when the previous match had failed" do
23
+ lambda { @s.unscan }.should.raise(ScanError)
24
+ lambda { @s.scan(/\d/); @s.unscan }.should.raise(ScanError)
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-strscan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Brett Walker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: StringScanner implementation for RubyMotion
28
+ email:
29
+ - github@digitalmoksha.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/motion-strscan.rb
36
+ - lib/motion-strscan/string.rb
37
+ - lib/motion-strscan/strscan.rb
38
+ - lib/motion-strscan/version.rb
39
+ - spec/helpers/it_behaves_like.rb
40
+ - spec/string_spec/_shared/slice.rb
41
+ - spec/string_spec/byteslice_spec.rb
42
+ - spec/strscan_spec/_shared/bol.rb
43
+ - spec/strscan_spec/_shared/concat.rb
44
+ - spec/strscan_spec/_shared/eos.rb
45
+ - spec/strscan_spec/_shared/extract_range.rb
46
+ - spec/strscan_spec/_shared/extract_range_matched.rb
47
+ - spec/strscan_spec/_shared/get_byte.rb
48
+ - spec/strscan_spec/_shared/matched_size.rb
49
+ - spec/strscan_spec/_shared/peek.rb
50
+ - spec/strscan_spec/_shared/pos.rb
51
+ - spec/strscan_spec/_shared/rest_size.rb
52
+ - spec/strscan_spec/_shared/terminate.rb
53
+ - spec/strscan_spec/append_spec.rb
54
+ - spec/strscan_spec/beginning_of_line_spec.rb
55
+ - spec/strscan_spec/bol_spec.rb
56
+ - spec/strscan_spec/check_spec.rb
57
+ - spec/strscan_spec/check_until_spec.rb
58
+ - spec/strscan_spec/clear_spec.rb
59
+ - spec/strscan_spec/concat_spec.rb
60
+ - spec/strscan_spec/dup_spec.rb
61
+ - spec/strscan_spec/element_reference_spec.rb
62
+ - spec/strscan_spec/empty_spec.rb
63
+ - spec/strscan_spec/eos_spec.rb
64
+ - spec/strscan_spec/exist_spec.rb
65
+ - spec/strscan_spec/get_byte_spec.rb
66
+ - spec/strscan_spec/getbyte_spec.rb
67
+ - spec/strscan_spec/getch_spec.rb
68
+ - spec/strscan_spec/initialize_spec.rb
69
+ - spec/strscan_spec/inspect_spec.rb
70
+ - spec/strscan_spec/match_spec.rb
71
+ - spec/strscan_spec/matched_size_spec.rb
72
+ - spec/strscan_spec/matched_spec.rb
73
+ - spec/strscan_spec/matchedsize_spec.rb
74
+ - spec/strscan_spec/must_C_version_spec.rb
75
+ - spec/strscan_spec/peek_spec.rb
76
+ - spec/strscan_spec/peep_spec.rb
77
+ - spec/strscan_spec/pointer_spec.rb
78
+ - spec/strscan_spec/pos_spec.rb
79
+ - spec/strscan_spec/post_match_spec.rb
80
+ - spec/strscan_spec/pre_match_spec.rb
81
+ - spec/strscan_spec/reset_spec.rb
82
+ - spec/strscan_spec/rest_size_spec.rb
83
+ - spec/strscan_spec/rest_spec.rb
84
+ - spec/strscan_spec/restsize_spec.rb
85
+ - spec/strscan_spec/scan_full_spec.rb
86
+ - spec/strscan_spec/scan_spec.rb
87
+ - spec/strscan_spec/scan_until_spec.rb
88
+ - spec/strscan_spec/search_full_spec.rb
89
+ - spec/strscan_spec/skip_spec.rb
90
+ - spec/strscan_spec/skip_until_spec.rb
91
+ - spec/strscan_spec/string_spec.rb
92
+ - spec/strscan_spec/terminate_spec.rb
93
+ - spec/strscan_spec/unscan_spec.rb
94
+ homepage: https://github.com/digitalmoksha/motion-strscan
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: StringScanner implementation for RubyMotion
117
+ test_files:
118
+ - spec/helpers/it_behaves_like.rb
119
+ - spec/string_spec/_shared/slice.rb
120
+ - spec/string_spec/byteslice_spec.rb
121
+ - spec/strscan_spec/_shared/bol.rb
122
+ - spec/strscan_spec/_shared/concat.rb
123
+ - spec/strscan_spec/_shared/eos.rb
124
+ - spec/strscan_spec/_shared/extract_range.rb
125
+ - spec/strscan_spec/_shared/extract_range_matched.rb
126
+ - spec/strscan_spec/_shared/get_byte.rb
127
+ - spec/strscan_spec/_shared/matched_size.rb
128
+ - spec/strscan_spec/_shared/peek.rb
129
+ - spec/strscan_spec/_shared/pos.rb
130
+ - spec/strscan_spec/_shared/rest_size.rb
131
+ - spec/strscan_spec/_shared/terminate.rb
132
+ - spec/strscan_spec/append_spec.rb
133
+ - spec/strscan_spec/beginning_of_line_spec.rb
134
+ - spec/strscan_spec/bol_spec.rb
135
+ - spec/strscan_spec/check_spec.rb
136
+ - spec/strscan_spec/check_until_spec.rb
137
+ - spec/strscan_spec/clear_spec.rb
138
+ - spec/strscan_spec/concat_spec.rb
139
+ - spec/strscan_spec/dup_spec.rb
140
+ - spec/strscan_spec/element_reference_spec.rb
141
+ - spec/strscan_spec/empty_spec.rb
142
+ - spec/strscan_spec/eos_spec.rb
143
+ - spec/strscan_spec/exist_spec.rb
144
+ - spec/strscan_spec/get_byte_spec.rb
145
+ - spec/strscan_spec/getbyte_spec.rb
146
+ - spec/strscan_spec/getch_spec.rb
147
+ - spec/strscan_spec/initialize_spec.rb
148
+ - spec/strscan_spec/inspect_spec.rb
149
+ - spec/strscan_spec/match_spec.rb
150
+ - spec/strscan_spec/matched_size_spec.rb
151
+ - spec/strscan_spec/matched_spec.rb
152
+ - spec/strscan_spec/matchedsize_spec.rb
153
+ - spec/strscan_spec/must_C_version_spec.rb
154
+ - spec/strscan_spec/peek_spec.rb
155
+ - spec/strscan_spec/peep_spec.rb
156
+ - spec/strscan_spec/pointer_spec.rb
157
+ - spec/strscan_spec/pos_spec.rb
158
+ - spec/strscan_spec/post_match_spec.rb
159
+ - spec/strscan_spec/pre_match_spec.rb
160
+ - spec/strscan_spec/reset_spec.rb
161
+ - spec/strscan_spec/rest_size_spec.rb
162
+ - spec/strscan_spec/rest_spec.rb
163
+ - spec/strscan_spec/restsize_spec.rb
164
+ - spec/strscan_spec/scan_full_spec.rb
165
+ - spec/strscan_spec/scan_spec.rb
166
+ - spec/strscan_spec/scan_until_spec.rb
167
+ - spec/strscan_spec/search_full_spec.rb
168
+ - spec/strscan_spec/skip_spec.rb
169
+ - spec/strscan_spec/skip_until_spec.rb
170
+ - spec/strscan_spec/string_spec.rb
171
+ - spec/strscan_spec/terminate_spec.rb
172
+ - spec/strscan_spec/unscan_spec.rb