mustermann 1.0.2.rc1 → 1.0.2.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +799 -230
  3. data/{mustermann/bench → bench}/capturing.rb +0 -0
  4. data/{mustermann/bench → bench}/regexp.rb +0 -0
  5. data/{mustermann/bench → bench}/simple_vs_sinatra.rb +0 -0
  6. data/{mustermann/bench → bench}/template_vs_addressable.rb +0 -0
  7. data/{mustermann/lib → lib}/mustermann.rb +0 -0
  8. data/{mustermann/lib → lib}/mustermann/ast/boundaries.rb +0 -0
  9. data/{mustermann/lib → lib}/mustermann/ast/compiler.rb +0 -0
  10. data/{mustermann/lib → lib}/mustermann/ast/expander.rb +0 -0
  11. data/{mustermann/lib → lib}/mustermann/ast/node.rb +0 -0
  12. data/{mustermann/lib → lib}/mustermann/ast/param_scanner.rb +0 -0
  13. data/{mustermann/lib → lib}/mustermann/ast/parser.rb +0 -0
  14. data/{mustermann/lib → lib}/mustermann/ast/pattern.rb +0 -0
  15. data/{mustermann/lib → lib}/mustermann/ast/template_generator.rb +0 -0
  16. data/{mustermann/lib → lib}/mustermann/ast/transformer.rb +0 -0
  17. data/{mustermann/lib → lib}/mustermann/ast/translator.rb +0 -0
  18. data/{mustermann/lib → lib}/mustermann/ast/validation.rb +0 -0
  19. data/{mustermann/lib → lib}/mustermann/caster.rb +0 -0
  20. data/{mustermann/lib → lib}/mustermann/composite.rb +0 -0
  21. data/{mustermann/lib → lib}/mustermann/concat.rb +0 -0
  22. data/{mustermann/lib → lib}/mustermann/equality_map.rb +0 -0
  23. data/{mustermann/lib → lib}/mustermann/error.rb +0 -0
  24. data/{mustermann/lib → lib}/mustermann/expander.rb +0 -0
  25. data/{mustermann/lib → lib}/mustermann/extension.rb +0 -0
  26. data/{mustermann/lib → lib}/mustermann/identity.rb +0 -0
  27. data/{mustermann/lib → lib}/mustermann/mapper.rb +0 -0
  28. data/{mustermann/lib → lib}/mustermann/pattern.rb +0 -0
  29. data/{mustermann/lib → lib}/mustermann/pattern_cache.rb +0 -0
  30. data/{mustermann/lib → lib}/mustermann/regexp.rb +0 -0
  31. data/{mustermann/lib → lib}/mustermann/regexp_based.rb +0 -0
  32. data/{mustermann/lib → lib}/mustermann/regular.rb +0 -0
  33. data/{mustermann/lib → lib}/mustermann/simple_match.rb +0 -0
  34. data/{mustermann/lib → lib}/mustermann/sinatra.rb +0 -0
  35. data/{mustermann/lib → lib}/mustermann/sinatra/parser.rb +0 -0
  36. data/{mustermann/lib → lib}/mustermann/sinatra/safe_renderer.rb +0 -0
  37. data/{mustermann/lib → lib}/mustermann/sinatra/try_convert.rb +0 -0
  38. data/{mustermann/lib → lib}/mustermann/to_pattern.rb +0 -0
  39. data/{mustermann/lib → lib}/mustermann/version.rb +1 -1
  40. data/{mustermann/mustermann.gemspec → mustermann.gemspec} +0 -0
  41. data/{mustermann/spec → spec}/ast_spec.rb +0 -0
  42. data/{mustermann/spec → spec}/composite_spec.rb +0 -0
  43. data/{mustermann/spec → spec}/concat_spec.rb +0 -0
  44. data/{mustermann/spec → spec}/equality_map_spec.rb +0 -0
  45. data/{mustermann/spec → spec}/expander_spec.rb +0 -0
  46. data/{mustermann/spec → spec}/extension_spec.rb +0 -0
  47. data/{mustermann/spec → spec}/identity_spec.rb +0 -0
  48. data/{mustermann/spec → spec}/mapper_spec.rb +0 -0
  49. data/{mustermann/spec → spec}/mustermann_spec.rb +0 -0
  50. data/{mustermann/spec → spec}/pattern_spec.rb +0 -0
  51. data/{mustermann/spec → spec}/regexp_based_spec.rb +0 -0
  52. data/{mustermann/spec → spec}/regular_spec.rb +0 -0
  53. data/{mustermann/spec → spec}/simple_match_spec.rb +0 -0
  54. data/{mustermann/spec → spec}/sinatra_spec.rb +0 -0
  55. data/{mustermann/spec → spec}/to_pattern_spec.rb +0 -0
  56. metadata +71 -126
  57. data/.gitignore +0 -18
  58. data/.rspec +0 -5
  59. data/.travis.yml +0 -25
  60. data/.yardopts +0 -3
  61. data/Gemfile +0 -7
  62. data/Rakefile +0 -27
  63. data/mustermann-contrib/LICENSE +0 -23
  64. data/mustermann-contrib/README.md +0 -1155
  65. data/mustermann-contrib/examples/highlighting.rb +0 -35
  66. data/mustermann-contrib/highlighting.png +0 -0
  67. data/mustermann-contrib/irb.png +0 -0
  68. data/mustermann-contrib/lib/mustermann/cake.rb +0 -19
  69. data/mustermann-contrib/lib/mustermann/express.rb +0 -38
  70. data/mustermann-contrib/lib/mustermann/file_utils.rb +0 -218
  71. data/mustermann-contrib/lib/mustermann/file_utils/glob_pattern.rb +0 -40
  72. data/mustermann-contrib/lib/mustermann/fileutils.rb +0 -1
  73. data/mustermann-contrib/lib/mustermann/flask.rb +0 -199
  74. data/mustermann-contrib/lib/mustermann/pyramid.rb +0 -29
  75. data/mustermann-contrib/lib/mustermann/rails.rb +0 -47
  76. data/mustermann-contrib/lib/mustermann/shell.rb +0 -57
  77. data/mustermann-contrib/lib/mustermann/simple.rb +0 -51
  78. data/mustermann-contrib/lib/mustermann/string_scanner.rb +0 -314
  79. data/mustermann-contrib/lib/mustermann/strscan.rb +0 -1
  80. data/mustermann-contrib/lib/mustermann/template.rb +0 -63
  81. data/mustermann-contrib/lib/mustermann/uri_template.rb +0 -1
  82. data/mustermann-contrib/lib/mustermann/versions.rb +0 -47
  83. data/mustermann-contrib/lib/mustermann/visualizer.rb +0 -39
  84. data/mustermann-contrib/lib/mustermann/visualizer/highlight.rb +0 -138
  85. data/mustermann-contrib/lib/mustermann/visualizer/highlighter.rb +0 -38
  86. data/mustermann-contrib/lib/mustermann/visualizer/highlighter/ad_hoc.rb +0 -95
  87. data/mustermann-contrib/lib/mustermann/visualizer/highlighter/ast.rb +0 -103
  88. data/mustermann-contrib/lib/mustermann/visualizer/highlighter/composite.rb +0 -46
  89. data/mustermann-contrib/lib/mustermann/visualizer/highlighter/dummy.rb +0 -19
  90. data/mustermann-contrib/lib/mustermann/visualizer/highlighter/regular.rb +0 -105
  91. data/mustermann-contrib/lib/mustermann/visualizer/pattern_extension.rb +0 -69
  92. data/mustermann-contrib/lib/mustermann/visualizer/renderer/ansi.rb +0 -24
  93. data/mustermann-contrib/lib/mustermann/visualizer/renderer/generic.rb +0 -47
  94. data/mustermann-contrib/lib/mustermann/visualizer/renderer/hansi_template.rb +0 -35
  95. data/mustermann-contrib/lib/mustermann/visualizer/renderer/html.rb +0 -51
  96. data/mustermann-contrib/lib/mustermann/visualizer/renderer/sexp.rb +0 -38
  97. data/mustermann-contrib/lib/mustermann/visualizer/tree.rb +0 -64
  98. data/mustermann-contrib/lib/mustermann/visualizer/tree_renderer.rb +0 -79
  99. data/mustermann-contrib/mustermann-contrib.gemspec +0 -19
  100. data/mustermann-contrib/spec/cake_spec.rb +0 -91
  101. data/mustermann-contrib/spec/express_spec.rb +0 -210
  102. data/mustermann-contrib/spec/file_utils_spec.rb +0 -120
  103. data/mustermann-contrib/spec/flask_spec.rb +0 -362
  104. data/mustermann-contrib/spec/flask_subclass_spec.rb +0 -369
  105. data/mustermann-contrib/spec/pattern_extension_spec.rb +0 -50
  106. data/mustermann-contrib/spec/pyramid_spec.rb +0 -102
  107. data/mustermann-contrib/spec/rails_spec.rb +0 -648
  108. data/mustermann-contrib/spec/shell_spec.rb +0 -148
  109. data/mustermann-contrib/spec/simple_spec.rb +0 -269
  110. data/mustermann-contrib/spec/string_scanner_spec.rb +0 -272
  111. data/mustermann-contrib/spec/template_spec.rb +0 -842
  112. data/mustermann-contrib/spec/visualizer_spec.rb +0 -199
  113. data/mustermann-contrib/theme.png +0 -0
  114. data/mustermann-contrib/tree.png +0 -0
  115. data/mustermann/LICENSE +0 -23
  116. data/mustermann/README.md +0 -853
  117. data/support/lib/support.rb +0 -7
  118. data/support/lib/support/coverage.rb +0 -23
  119. data/support/lib/support/env.rb +0 -19
  120. data/support/lib/support/expand_matcher.rb +0 -28
  121. data/support/lib/support/generate_template_matcher.rb +0 -27
  122. data/support/lib/support/match_matcher.rb +0 -39
  123. data/support/lib/support/pattern.rb +0 -42
  124. data/support/lib/support/projects.rb +0 -20
  125. data/support/lib/support/scan_matcher.rb +0 -63
  126. data/support/support.gemspec +0 -27
@@ -1,362 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/flask'
4
-
5
- describe Mustermann::Flask do
6
- extend Support::Pattern
7
-
8
- pattern '' do
9
- it { should match('') }
10
- it { should_not match('/') }
11
-
12
- it { should expand.to('') }
13
- it { should_not expand(a: 1) }
14
-
15
- it { should generate_template('') }
16
-
17
- it { should respond_to(:expand) }
18
- it { should respond_to(:to_templates) }
19
- end
20
-
21
- pattern '/' do
22
- it { should match('/') }
23
- it { should_not match('/foo') }
24
-
25
- it { should expand.to('/') }
26
- it { should_not expand(a: 1) }
27
- end
28
-
29
- pattern '/foo' do
30
- it { should match('/foo') }
31
- it { should_not match('/bar') }
32
- it { should_not match('/foo.bar') }
33
-
34
- it { should expand.to('/foo') }
35
- it { should_not expand(a: 1) }
36
- end
37
-
38
- pattern '/foo/bar' do
39
- it { should match('/foo/bar') }
40
- it { should_not match('/foo%2Fbar') }
41
- it { should_not match('/foo%2fbar') }
42
-
43
- it { should expand.to('/foo/bar') }
44
- it { should_not expand(a: 1) }
45
- end
46
-
47
- pattern '/<foo>' do
48
- it { should match('/foo') .capturing foo: 'foo' }
49
- it { should match('/bar') .capturing foo: 'bar' }
50
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
51
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
52
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
53
-
54
- it { should_not match('/foo?') }
55
- it { should_not match('/foo/bar') }
56
- it { should_not match('/') }
57
- it { should_not match('/foo/') }
58
-
59
- example { pattern.params('/foo') .should be == {"foo" => "foo"} }
60
- example { pattern.params('/f%20o') .should be == {"foo" => "f o"} }
61
- example { pattern.params('').should be_nil }
62
-
63
- it { should expand(foo: 'bar') .to('/bar') }
64
- it { should expand(foo: 'b r') .to('/b%20r') }
65
- it { should expand(foo: 'foo/bar') .to('/foo%2Fbar') }
66
-
67
- it { should_not expand(foo: 'foo', bar: 'bar') }
68
- it { should_not expand(bar: 'bar') }
69
- it { should_not expand }
70
-
71
- it { should generate_template('/{foo}') }
72
- end
73
-
74
- pattern '/<string:foo>' do
75
- it { should match('/foo') .capturing foo: 'foo' }
76
- it { should match('/bar') .capturing foo: 'bar' }
77
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
78
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
79
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
80
-
81
- it { should_not match('/foo?') }
82
- it { should_not match('/foo/bar') }
83
- it { should_not match('/') }
84
- it { should_not match('/foo/') }
85
-
86
- example { pattern.params('/foo') .should be == {"foo" => "foo"} }
87
- example { pattern.params('/f%20o') .should be == {"foo" => "f o"} }
88
- example { pattern.params('').should be_nil }
89
-
90
- it { should expand(foo: 'bar') .to('/bar') }
91
- it { should expand(foo: 'b r') .to('/b%20r') }
92
- it { should expand(foo: 'foo/bar') .to('/foo%2Fbar') }
93
-
94
- it { should_not expand(foo: 'foo', bar: 'bar') }
95
- it { should_not expand(bar: 'bar') }
96
- it { should_not expand }
97
-
98
- it { should generate_template('/{foo}') }
99
- end
100
-
101
- pattern '/<string(minlength=2):foo>' do
102
- it { should match('/foo') .capturing foo: 'foo' }
103
- it { should match('/bar') .capturing foo: 'bar' }
104
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
105
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
106
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
107
-
108
- it { should_not match('/f') }
109
- it { should_not match('/foo?') }
110
- it { should_not match('/foo/bar') }
111
- it { should_not match('/') }
112
- it { should_not match('/foo/') }
113
-
114
- it { should generate_template('/{foo}') }
115
- end
116
-
117
- pattern '/<string(maxlength=3):foo>' do
118
- it { should match('/f') .capturing foo: 'f' }
119
- it { should match('/fo') .capturing foo: 'fo' }
120
- it { should match('/foo') .capturing foo: 'foo' }
121
- it { should match('/bar') .capturing foo: 'bar' }
122
-
123
- it { should_not match('/fooo') }
124
- it { should_not match('/foo.bar') }
125
- it { should_not match('/foo?') }
126
- it { should_not match('/foo/bar') }
127
- it { should_not match('/') }
128
- it { should_not match('/foo/') }
129
-
130
- it { should generate_template('/{foo}') }
131
- end
132
-
133
- pattern '/<string(length=3):foo>' do
134
- it { should match('/foo') .capturing foo: 'foo' }
135
- it { should match('/bar') .capturing foo: 'bar' }
136
-
137
- it { should_not match('/f') }
138
- it { should_not match('/fo') }
139
- it { should_not match('/fooo') }
140
- it { should_not match('/foo.bar') }
141
- it { should_not match('/foo?') }
142
- it { should_not match('/foo/bar') }
143
- it { should_not match('/') }
144
- it { should_not match('/foo/') }
145
-
146
- it { should generate_template('/{foo}') }
147
- end
148
-
149
- pattern '/<int:foo>' do
150
- it { should match('/42').capturing foo: '42' }
151
-
152
- it { should_not match('/1.0') }
153
- it { should_not match('/.5') }
154
- it { should_not match('/foo') }
155
- it { should_not match('/bar') }
156
- it { should_not match('/foo.bar') }
157
- it { should_not match('/%0Afoo') }
158
- it { should_not match('/foo%2Fbar') }
159
-
160
- it { should_not match('/foo?') }
161
- it { should_not match('/foo/bar') }
162
- it { should_not match('/') }
163
- it { should_not match('/foo/') }
164
-
165
- example { pattern.params('/42').should be == {"foo" => 42} }
166
- it { should expand(foo: 12).to('/12') }
167
- it { should generate_template('/{foo}') }
168
- end
169
-
170
- pattern '/<int:foo>' do
171
- it { should match('/42').capturing foo: '42' }
172
-
173
- it { should_not match('/1.0') }
174
- it { should_not match('/.5') }
175
- it { should_not match('/foo') }
176
- it { should_not match('/bar') }
177
- it { should_not match('/foo.bar') }
178
- it { should_not match('/%0Afoo') }
179
- it { should_not match('/foo%2Fbar') }
180
-
181
- it { should_not match('/foo?') }
182
- it { should_not match('/foo/bar') }
183
- it { should_not match('/') }
184
- it { should_not match('/foo/') }
185
-
186
- example { pattern.params('/42').should be == {"foo" => 42} }
187
- it { should expand(foo: 12).to('/12') }
188
- it { should generate_template('/{foo}') }
189
- end
190
-
191
- pattern '/<any(foo,bar):foo>' do
192
- it { should match('/foo') .capturing foo: 'foo' }
193
- it { should match('/bar') .capturing foo: 'bar' }
194
-
195
- it { should_not match('/f') }
196
- it { should_not match('/fo') }
197
- it { should_not match('/fooo') }
198
- it { should_not match('/foo.bar') }
199
- it { should_not match('/foo?') }
200
- it { should_not match('/foo/bar') }
201
- it { should_not match('/') }
202
- it { should_not match('/foo/') }
203
- it { should_not match('/baz') }
204
-
205
- it { should generate_template('/{foo}') }
206
- end
207
-
208
- pattern '/<any( foo, bar ):foo>' do
209
- it { should match('/foo') .capturing foo: 'foo' }
210
- it { should match('/bar') .capturing foo: 'bar' }
211
-
212
- it { should_not match('/f') }
213
- it { should_not match('/fo') }
214
- it { should_not match('/fooo') }
215
- it { should_not match('/foo.bar') }
216
- it { should_not match('/foo?') }
217
- it { should_not match('/foo/bar') }
218
- it { should_not match('/') }
219
- it { should_not match('/foo/') }
220
- it { should_not match('/baz') }
221
-
222
- it { should generate_template('/{foo}') }
223
- end
224
-
225
- pattern '/<any(foo, bar, "foo,bar"):foo>' do
226
- it { should match('/foo') .capturing foo: 'foo' }
227
- it { should match('/bar') .capturing foo: 'bar' }
228
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
229
-
230
- it { should_not match('/f') }
231
- it { should_not match('/fo') }
232
- it { should_not match('/fooo') }
233
- it { should_not match('/foo.bar') }
234
- it { should_not match('/foo?') }
235
- it { should_not match('/foo/bar') }
236
- it { should_not match('/') }
237
- it { should_not match('/foo/') }
238
- it { should_not match('/baz') }
239
-
240
- it { should generate_template('/{foo}') }
241
- end
242
-
243
- pattern '/<any(foo, bar, foo\,bar):foo>' do
244
- it { should match('/foo') .capturing foo: 'foo' }
245
- it { should match('/bar') .capturing foo: 'bar' }
246
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
247
-
248
- it { should_not match('/f') }
249
- it { should_not match('/fo') }
250
- it { should_not match('/fooo') }
251
- it { should_not match('/foo.bar') }
252
- it { should_not match('/foo?') }
253
- it { should_not match('/foo/bar') }
254
- it { should_not match('/') }
255
- it { should_not match('/foo/') }
256
- it { should_not match('/baz') }
257
-
258
- it { should generate_template('/{foo}') }
259
- end
260
-
261
- pattern '/<any(foo, bar, "foo\,bar"):foo>' do
262
- it { should match('/foo') .capturing foo: 'foo' }
263
- it { should match('/bar') .capturing foo: 'bar' }
264
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
265
-
266
- it { should_not match('/f') }
267
- it { should_not match('/fo') }
268
- it { should_not match('/fooo') }
269
- it { should_not match('/foo.bar') }
270
- it { should_not match('/foo?') }
271
- it { should_not match('/foo/bar') }
272
- it { should_not match('/') }
273
- it { should_not match('/foo/') }
274
- it { should_not match('/baz') }
275
-
276
- it { should generate_template('/{foo}') }
277
- end
278
-
279
- pattern '/<int(min=5,max=50):foo>' do
280
- example { pattern.params('/42').should be == {"foo" => 42} }
281
- example { pattern.params('/52').should be == {"foo" => 50} }
282
- example { pattern.params('/2').should be == {"foo" => 5} }
283
- end
284
-
285
- pattern '/<float(min=5,max=50.5):foo>' do
286
- example { pattern.params('/42.5').should be == {"foo" => 42.5} }
287
- example { pattern.params('/52.5').should be == {"foo" => 50.5} }
288
- example { pattern.params('/2.5').should be == {"foo" => 5.0} }
289
- end
290
-
291
- pattern '/<prefix>/<float:foo>/<int:bar>' do
292
- it { should match('/foo/42/42') .capturing foo: '42', bar: '42' }
293
- it { should match('/foo/1.0/1') .capturing foo: '1.0', bar: '1' }
294
- it { should match('/foo/.5/0') .capturing foo: '.5', bar: '0' }
295
-
296
- it { should_not match('/foo/1/1.0') }
297
- it { should_not match('/foo/1.0/1.0') }
298
-
299
- it { should generate_template('/{prefix}/{foo}/{bar}') }
300
-
301
- example do
302
- pattern.params('/foo/1.0/1').should be == {
303
- "prefix" => "foo",
304
- "foo" => 1.0,
305
- "bar" => 1
306
- }
307
- end
308
- end
309
-
310
- pattern '/<path:foo>' do
311
- it { should match('/') .capturing foo: '' }
312
- it { should match('/foo') .capturing foo: 'foo' }
313
- it { should match('/foo/bar') .capturing foo: 'foo/bar' }
314
-
315
- it { should expand .to('/') }
316
- it { should expand(foo: nil) .to('/') }
317
- it { should expand(foo: '') .to('/') }
318
- it { should expand(foo: 'foo') .to('/foo') }
319
- it { should expand(foo: 'foo/bar') .to('/foo/bar') }
320
- it { should expand(foo: 'foo.bar') .to('/foo.bar') }
321
-
322
- it { should generate_template('/{+foo}') }
323
- end
324
-
325
- converter = Struct.new(:convert).new(:upcase.to_proc)
326
- pattern '/<foo:bar>', converters: { foo: converter } do
327
- it { should match('/foo').capturing bar: 'foo' }
328
- example { pattern.params('/foo').should be == {"bar" => "FOO"} }
329
- end
330
-
331
- context 'invalid syntax' do
332
- example 'unexpected end of capture' do
333
- expect { Mustermann::Flask.new('foo>bar') }.
334
- to raise_error(Mustermann::ParseError, 'unexpected > while parsing "foo>bar"')
335
- end
336
-
337
- example 'missing end of capture' do
338
- expect { Mustermann::Flask.new('foo<bar') }.
339
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "foo<bar"')
340
- end
341
-
342
- example 'unknown converter' do
343
- expect { Mustermann::Flask.new('foo<bar:name>') }.
344
- to raise_error(Mustermann::ParseError, 'unexpected converter "bar" while parsing "foo<bar:name>"')
345
- end
346
-
347
- example 'broken argument synax' do
348
- expect { Mustermann::Flask.new('<string(length=3=2):foo>') }.
349
- to raise_error(Mustermann::ParseError, 'unexpected = while parsing "<string(length=3=2):foo>"')
350
- end
351
-
352
- example 'missing )' do
353
- expect { Mustermann::Flask.new('<string(foo') }.
354
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "<string(foo"')
355
- end
356
-
357
- example 'missing ""' do
358
- expect { Mustermann::Flask.new('<string("foo') }.
359
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "<string(\\"foo"')
360
- end
361
- end
362
- end
@@ -1,369 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/flask'
4
-
5
- FlaskSubclass ||= Class.new(Mustermann::Flask)
6
- FlaskSubclass.register_converter(:foo) {}
7
-
8
- describe FlaskSubclass do
9
- extend Support::Pattern
10
-
11
- pattern '' do
12
- it { should match('') }
13
- it { should_not match('/') }
14
-
15
- it { should expand.to('') }
16
- it { should_not expand(a: 1) }
17
-
18
- it { should generate_template('') }
19
-
20
- it { should respond_to(:expand) }
21
- it { should respond_to(:to_templates) }
22
- end
23
-
24
- pattern '/' do
25
- it { should match('/') }
26
- it { should_not match('/foo') }
27
-
28
- it { should expand.to('/') }
29
- it { should_not expand(a: 1) }
30
- end
31
-
32
- pattern '/foo' do
33
- it { should match('/foo') }
34
- it { should_not match('/bar') }
35
- it { should_not match('/foo.bar') }
36
-
37
- it { should expand.to('/foo') }
38
- it { should_not expand(a: 1) }
39
- end
40
-
41
- pattern '/foo/bar' do
42
- it { should match('/foo/bar') }
43
- it { should_not match('/foo%2Fbar') }
44
- it { should_not match('/foo%2fbar') }
45
-
46
- it { should expand.to('/foo/bar') }
47
- it { should_not expand(a: 1) }
48
- end
49
-
50
- pattern '/<foo>' do
51
- it { should match('/foo') .capturing foo: 'foo' }
52
- it { should match('/bar') .capturing foo: 'bar' }
53
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
54
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
55
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
56
-
57
- it { should_not match('/foo?') }
58
- it { should_not match('/foo/bar') }
59
- it { should_not match('/') }
60
- it { should_not match('/foo/') }
61
-
62
- example { pattern.params('/foo') .should be == {"foo" => "foo"} }
63
- example { pattern.params('/f%20o') .should be == {"foo" => "f o"} }
64
- example { pattern.params('').should be_nil }
65
-
66
- it { should expand(foo: 'bar') .to('/bar') }
67
- it { should expand(foo: 'b r') .to('/b%20r') }
68
- it { should expand(foo: 'foo/bar') .to('/foo%2Fbar') }
69
-
70
- it { should_not expand(foo: 'foo', bar: 'bar') }
71
- it { should_not expand(bar: 'bar') }
72
- it { should_not expand }
73
-
74
- it { should generate_template('/{foo}') }
75
- end
76
-
77
- pattern '/<string:foo>' do
78
- it { should match('/foo') .capturing foo: 'foo' }
79
- it { should match('/bar') .capturing foo: 'bar' }
80
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
81
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
82
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
83
-
84
- it { should_not match('/foo?') }
85
- it { should_not match('/foo/bar') }
86
- it { should_not match('/') }
87
- it { should_not match('/foo/') }
88
-
89
- example { pattern.params('/foo') .should be == {"foo" => "foo"} }
90
- example { pattern.params('/f%20o') .should be == {"foo" => "f o"} }
91
- example { pattern.params('').should be_nil }
92
-
93
- it { should expand(foo: 'bar') .to('/bar') }
94
- it { should expand(foo: 'b r') .to('/b%20r') }
95
- it { should expand(foo: 'foo/bar') .to('/foo%2Fbar') }
96
-
97
- it { should_not expand(foo: 'foo', bar: 'bar') }
98
- it { should_not expand(bar: 'bar') }
99
- it { should_not expand }
100
-
101
- it { should generate_template('/{foo}') }
102
- end
103
-
104
- pattern '/<string(minlength=2):foo>' do
105
- it { should match('/foo') .capturing foo: 'foo' }
106
- it { should match('/bar') .capturing foo: 'bar' }
107
- it { should match('/foo.bar') .capturing foo: 'foo.bar' }
108
- it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
109
- it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
110
-
111
- it { should_not match('/f') }
112
- it { should_not match('/foo?') }
113
- it { should_not match('/foo/bar') }
114
- it { should_not match('/') }
115
- it { should_not match('/foo/') }
116
-
117
- it { should generate_template('/{foo}') }
118
- end
119
-
120
- pattern '/<string(maxlength=3):foo>' do
121
- it { should match('/f') .capturing foo: 'f' }
122
- it { should match('/fo') .capturing foo: 'fo' }
123
- it { should match('/foo') .capturing foo: 'foo' }
124
- it { should match('/bar') .capturing foo: 'bar' }
125
-
126
- it { should_not match('/fooo') }
127
- it { should_not match('/foo.bar') }
128
- it { should_not match('/foo?') }
129
- it { should_not match('/foo/bar') }
130
- it { should_not match('/') }
131
- it { should_not match('/foo/') }
132
-
133
- it { should generate_template('/{foo}') }
134
- end
135
-
136
- pattern '/<string(length=3):foo>' do
137
- it { should match('/foo') .capturing foo: 'foo' }
138
- it { should match('/bar') .capturing foo: 'bar' }
139
-
140
- it { should_not match('/f') }
141
- it { should_not match('/fo') }
142
- it { should_not match('/fooo') }
143
- it { should_not match('/foo.bar') }
144
- it { should_not match('/foo?') }
145
- it { should_not match('/foo/bar') }
146
- it { should_not match('/') }
147
- it { should_not match('/foo/') }
148
-
149
- it { should generate_template('/{foo}') }
150
- end
151
-
152
- pattern '/<int:foo>' do
153
- it { should match('/42').capturing foo: '42' }
154
-
155
- it { should_not match('/1.0') }
156
- it { should_not match('/.5') }
157
- it { should_not match('/foo') }
158
- it { should_not match('/bar') }
159
- it { should_not match('/foo.bar') }
160
- it { should_not match('/%0Afoo') }
161
- it { should_not match('/foo%2Fbar') }
162
-
163
- it { should_not match('/foo?') }
164
- it { should_not match('/foo/bar') }
165
- it { should_not match('/') }
166
- it { should_not match('/foo/') }
167
-
168
- example { pattern.params('/42').should be == {"foo" => 42} }
169
- it { should expand(foo: 12).to('/12') }
170
- it { should generate_template('/{foo}') }
171
- end
172
-
173
- pattern '/<int:foo>' do
174
- it { should match('/42').capturing foo: '42' }
175
-
176
- it { should_not match('/1.0') }
177
- it { should_not match('/.5') }
178
- it { should_not match('/foo') }
179
- it { should_not match('/bar') }
180
- it { should_not match('/foo.bar') }
181
- it { should_not match('/%0Afoo') }
182
- it { should_not match('/foo%2Fbar') }
183
-
184
- it { should_not match('/foo?') }
185
- it { should_not match('/foo/bar') }
186
- it { should_not match('/') }
187
- it { should_not match('/foo/') }
188
-
189
- example { pattern.params('/42').should be == {"foo" => 42} }
190
- it { should expand(foo: 12).to('/12') }
191
- it { should generate_template('/{foo}') }
192
- end
193
-
194
- pattern '/<any(foo,bar):foo>' do
195
- it { should match('/foo') .capturing foo: 'foo' }
196
- it { should match('/bar') .capturing foo: 'bar' }
197
-
198
- it { should_not match('/f') }
199
- it { should_not match('/fo') }
200
- it { should_not match('/fooo') }
201
- it { should_not match('/foo.bar') }
202
- it { should_not match('/foo?') }
203
- it { should_not match('/foo/bar') }
204
- it { should_not match('/') }
205
- it { should_not match('/foo/') }
206
- it { should_not match('/baz') }
207
-
208
- it { should generate_template('/{foo}') }
209
- end
210
-
211
- pattern '/<any( foo, bar ):foo>' do
212
- it { should match('/foo') .capturing foo: 'foo' }
213
- it { should match('/bar') .capturing foo: 'bar' }
214
-
215
- it { should_not match('/f') }
216
- it { should_not match('/fo') }
217
- it { should_not match('/fooo') }
218
- it { should_not match('/foo.bar') }
219
- it { should_not match('/foo?') }
220
- it { should_not match('/foo/bar') }
221
- it { should_not match('/') }
222
- it { should_not match('/foo/') }
223
- it { should_not match('/baz') }
224
-
225
- it { should generate_template('/{foo}') }
226
- end
227
-
228
- pattern '/<any(foo, bar, "foo,bar"):foo>' do
229
- it { should match('/foo') .capturing foo: 'foo' }
230
- it { should match('/bar') .capturing foo: 'bar' }
231
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
232
-
233
- it { should_not match('/f') }
234
- it { should_not match('/fo') }
235
- it { should_not match('/fooo') }
236
- it { should_not match('/foo.bar') }
237
- it { should_not match('/foo?') }
238
- it { should_not match('/foo/bar') }
239
- it { should_not match('/') }
240
- it { should_not match('/foo/') }
241
- it { should_not match('/baz') }
242
-
243
- it { should generate_template('/{foo}') }
244
- end
245
-
246
- pattern '/<any(foo, bar, foo\,bar):foo>' do
247
- it { should match('/foo') .capturing foo: 'foo' }
248
- it { should match('/bar') .capturing foo: 'bar' }
249
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
250
-
251
- it { should_not match('/f') }
252
- it { should_not match('/fo') }
253
- it { should_not match('/fooo') }
254
- it { should_not match('/foo.bar') }
255
- it { should_not match('/foo?') }
256
- it { should_not match('/foo/bar') }
257
- it { should_not match('/') }
258
- it { should_not match('/foo/') }
259
- it { should_not match('/baz') }
260
-
261
- it { should generate_template('/{foo}') }
262
- end
263
-
264
- pattern '/<any(foo, bar, "foo\,bar"):foo>' do
265
- it { should match('/foo') .capturing foo: 'foo' }
266
- it { should match('/bar') .capturing foo: 'bar' }
267
- it { should match('/foo,bar') .capturing foo: 'foo,bar' }
268
-
269
- it { should_not match('/f') }
270
- it { should_not match('/fo') }
271
- it { should_not match('/fooo') }
272
- it { should_not match('/foo.bar') }
273
- it { should_not match('/foo?') }
274
- it { should_not match('/foo/bar') }
275
- it { should_not match('/') }
276
- it { should_not match('/foo/') }
277
- it { should_not match('/baz') }
278
-
279
- it { should generate_template('/{foo}') }
280
- end
281
-
282
- pattern '/<int(min=5,max=50):foo>' do
283
- example { pattern.params('/42').should be == {"foo" => 42} }
284
- example { pattern.params('/52').should be == {"foo" => 50} }
285
- example { pattern.params('/2').should be == {"foo" => 5} }
286
- end
287
-
288
- pattern '/<float(min=5,max=50.5):foo>' do
289
- example { pattern.params('/42.5').should be == {"foo" => 42.5} }
290
- example { pattern.params('/52.5').should be == {"foo" => 50.5} }
291
- example { pattern.params('/2.5').should be == {"foo" => 5.0} }
292
- end
293
-
294
- pattern '/<prefix>/<float:foo>/<int:bar>' do
295
- it { should match('/foo/42/42') .capturing foo: '42', bar: '42' }
296
- it { should match('/foo/1.0/1') .capturing foo: '1.0', bar: '1' }
297
- it { should match('/foo/.5/0') .capturing foo: '.5', bar: '0' }
298
-
299
- it { should_not match('/foo/1/1.0') }
300
- it { should_not match('/foo/1.0/1.0') }
301
-
302
- it { should generate_template('/{prefix}/{foo}/{bar}') }
303
-
304
- example do
305
- pattern.params('/foo/1.0/1').should be == {
306
- "prefix" => "foo",
307
- "foo" => 1.0,
308
- "bar" => 1
309
- }
310
- end
311
- end
312
-
313
- pattern '/<path:foo>' do
314
- it { should match('/') .capturing foo: '' }
315
- it { should match('/foo') .capturing foo: 'foo' }
316
- it { should match('/foo/bar') .capturing foo: 'foo/bar' }
317
-
318
- it { should expand .to('/') }
319
- it { should expand(foo: nil) .to('/') }
320
- it { should expand(foo: '') .to('/') }
321
- it { should expand(foo: 'foo') .to('/foo') }
322
- it { should expand(foo: 'foo/bar') .to('/foo/bar') }
323
- it { should expand(foo: 'foo.bar') .to('/foo.bar') }
324
-
325
- it { should generate_template('/{+foo}') }
326
- end
327
-
328
- pattern '/<foo:bar>' do
329
- it { should match('/foo').capturing bar: 'foo' }
330
- it { should generate_template('/{bar}') }
331
-
332
- example do
333
- expect { Mustermann::Flask.new('/<foo:bar>') }.to \
334
- raise_error(Mustermann::ParseError, 'unexpected converter "foo" while parsing "/<foo:bar>"')
335
- end
336
- end
337
-
338
- context 'invalid syntax' do
339
- example 'unexpected end of capture' do
340
- expect { FlaskSubclass.new('foo>bar') }.
341
- to raise_error(Mustermann::ParseError, 'unexpected > while parsing "foo>bar"')
342
- end
343
-
344
- example 'missing end of capture' do
345
- expect { FlaskSubclass.new('foo<bar') }.
346
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "foo<bar"')
347
- end
348
-
349
- example 'unknown converter' do
350
- expect { FlaskSubclass.new('foo<bar:name>') }.
351
- to raise_error(Mustermann::ParseError, 'unexpected converter "bar" while parsing "foo<bar:name>"')
352
- end
353
-
354
- example 'broken argument synax' do
355
- expect { FlaskSubclass.new('<string(length=3=2):foo>') }.
356
- to raise_error(Mustermann::ParseError, 'unexpected = while parsing "<string(length=3=2):foo>"')
357
- end
358
-
359
- example 'missing )' do
360
- expect { FlaskSubclass.new('<string(foo') }.
361
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "<string(foo"')
362
- end
363
-
364
- example 'missing ""' do
365
- expect { FlaskSubclass.new('<string("foo') }.
366
- to raise_error(Mustermann::ParseError, 'unexpected end of string while parsing "<string(\\"foo"')
367
- end
368
- end
369
- end