mustermann 3.0.4 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,163 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann'
4
-
5
- describe Mustermann::Composite do
6
- describe :new do
7
- example 'with no argument' do
8
- expect { Mustermann::Composite.new }.
9
- to raise_error(ArgumentError, 'cannot create empty composite pattern')
10
- end
11
-
12
- example 'with one argument' do
13
- pattern = Mustermann.new('/foo')
14
- Mustermann::Composite.new(pattern).should be == pattern
15
- end
16
-
17
- example 'with supported type specific arguments' do
18
- Mustermann::Composite.new("/a", "/b", greedy: true)
19
- end
20
-
21
- example 'with unsupported type specific arguments' do
22
- expect { Mustermann::Composite.new("/a", "/b", greedy: true, type: :identity) }.to raise_error(ArgumentError)
23
- end
24
- end
25
-
26
- context :| do
27
- subject(:pattern) { Mustermann.new('/foo/:name', '/:first/:second') }
28
-
29
- describe :== do
30
- example { subject.should be == subject }
31
- example { subject.should be == Mustermann.new('/foo/:name', '/:first/:second') }
32
- example { subject.should_not be == Mustermann.new('/foo/:name') }
33
- example { subject.should_not be == Mustermann.new('/foo/:name', '/:first/:second', operator: :&) }
34
- end
35
-
36
- describe :=== do
37
- example { subject.should be === "/foo/bar" }
38
- example { subject.should be === "/fox/bar" }
39
- example { subject.should_not be === "/foo" }
40
- end
41
-
42
- describe :params do
43
- example { subject.params("/foo/bar") .should be == { "name" => "bar" } }
44
- example { subject.params("/fox/bar") .should be == { "first" => "fox", "second" => "bar" } }
45
- example { subject.params("/foo") .should be_nil }
46
- end
47
-
48
- describe :=== do
49
- example { subject.should match("/foo/bar") }
50
- example { subject.should match("/fox/bar") }
51
- example { subject.should_not match("/foo") }
52
- end
53
-
54
- describe :expand do
55
- example { subject.should respond_to(:expand) }
56
- example { subject.expand(name: 'bar') .should be == '/foo/bar' }
57
- example { subject.expand(first: 'fox', second: 'bar') .should be == '/fox/bar' }
58
-
59
- context "without expandable patterns" do
60
- subject(:pattern) { Mustermann.new('/foo/:name', '/:first/:second', type: :simple) }
61
- example { subject.should_not respond_to(:expand) }
62
- example { expect { subject.expand(name: 'bar') }.to raise_error(NotImplementedError) }
63
- end
64
- end
65
-
66
- describe :to_templates do
67
- example { should respond_to(:to_templates) }
68
- example { should generate_templates('/foo/{name}', '/{first}/{second}') }
69
-
70
- context "without patterns implementing to_templates" do
71
- subject(:pattern) { Mustermann.new('/foo/:name', '/:first/:second', type: :simple) }
72
- example { should_not respond_to(:to_templates) }
73
- example { expect { subject.to_templates }.to raise_error(NotImplementedError) }
74
- end
75
- end
76
-
77
- describe :eql? do
78
- example { should be_eql(pattern) }
79
- example { should be_eql(Mustermann.new('/foo/:name', '/:first/:second', operator: :|)) }
80
- example { should_not be_eql(Mustermann.new('/bar/:name', '/:first/:second', operator: :|)) }
81
- example { should_not be_eql(Mustermann.new('/foo/:name', '/:first/:second', operator: :&)) }
82
- end
83
- end
84
-
85
- context :& do
86
- subject(:pattern) { Mustermann.new('/foo/:name', '/:first/:second', operator: :&) }
87
-
88
- describe :== do
89
- example { subject.should be == subject }
90
- example { subject.should be == Mustermann.new('/foo/:name', '/:first/:second', operator: :&) }
91
- example { subject.should_not be == Mustermann.new('/foo/:name') }
92
- example { subject.should_not be == Mustermann.new('/foo/:name', '/:first/:second') }
93
- end
94
-
95
- describe :=== do
96
- example { subject.should be === "/foo/bar" }
97
- example { subject.should_not be === "/fox/bar" }
98
- example { subject.should_not be === "/foo" }
99
- end
100
-
101
- describe :params do
102
- example { subject.params("/foo/bar") .should be == { "name" => "bar" } }
103
- example { subject.params("/fox/bar") .should be_nil }
104
- example { subject.params("/foo") .should be_nil }
105
- end
106
-
107
- describe :match do
108
- example { subject.should match("/foo/bar") }
109
- example { subject.should_not match("/fox/bar") }
110
- example { subject.should_not match("/foo") }
111
- end
112
-
113
- describe :expand do
114
- example { subject.should_not respond_to(:expand) }
115
- example { expect { subject.expand(name: 'bar') }.to raise_error(NotImplementedError) }
116
- end
117
- end
118
-
119
- context :^ do
120
- subject(:pattern) { Mustermann.new('/foo/:name', '/:first/:second', operator: :^) }
121
-
122
- describe :== do
123
- example { subject.should be == subject }
124
- example { subject.should_not be == Mustermann.new('/foo/:name', '/:first/:second') }
125
- example { subject.should_not be == Mustermann.new('/foo/:name') }
126
- example { subject.should_not be == Mustermann.new('/foo/:name', '/:first/:second', operator: :&) }
127
- end
128
-
129
- describe :=== do
130
- example { subject.should_not be === "/foo/bar" }
131
- example { subject.should be === "/fox/bar" }
132
- example { subject.should_not be === "/foo" }
133
- end
134
-
135
- describe :params do
136
- example { subject.params("/foo/bar") .should be_nil }
137
- example { subject.params("/fox/bar") .should be == { "first" => "fox", "second" => "bar" } }
138
- example { subject.params("/foo") .should be_nil }
139
- end
140
-
141
- describe :match do
142
- example { subject.should_not match("/foo/bar") }
143
- example { subject.should match("/fox/bar") }
144
- example { subject.should_not match("/foo") }
145
- end
146
-
147
- describe :expand do
148
- example { subject.should_not respond_to(:expand) }
149
- example { expect { subject.expand(name: 'bar') }.to raise_error(NotImplementedError) }
150
- end
151
- end
152
-
153
- describe :inspect do
154
- let(:sinatra) { Mustermann.new('x') }
155
- let(:shell) { Mustermann.new('x', type: :shell) }
156
- let(:identity) { Mustermann.new('x', type: :identity) }
157
-
158
- example { (sinatra | shell) .inspect.should include('(sinatra:"x" | shell:"x")') }
159
- example { (sinatra ^ shell) .inspect.should include('(sinatra:"x" ^ shell:"x")') }
160
- example { (sinatra | shell | identity) .inspect.should include('(sinatra:"x" | shell:"x" | identity:"x")') }
161
- example { (sinatra | shell & identity) .inspect.should include('(sinatra:"x" | (shell:"x" & identity:"x"))') }
162
- end
163
- end
data/spec/concat_spec.rb DELETED
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann'
4
-
5
- describe Mustermann::Concat do
6
- describe Mustermann::Concat::Native do
7
- context "sinatra + sinatra" do
8
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar") }
9
- its(:class) { should be == Mustermann::Sinatra }
10
- its(:to_s) { should be == "/{foo}/{bar}" }
11
- end
12
-
13
- context "sinatra + string" do
14
- subject(:pattern) { Mustermann.new("/:foo") + "/:bar" }
15
- its(:class) { should be == Mustermann::Sinatra }
16
- its(:to_s) { should be == "/{foo}/\\:bar" }
17
- end
18
-
19
- context "regular + regular" do
20
- subject(:pattern) { Mustermann.new(/foo/) + Mustermann.new(/bar/) }
21
- its(:class) { should be == Mustermann::Regular }
22
- its(:to_s) { should be == "foobar" }
23
- end
24
-
25
- context "sinatra + rails" do
26
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails) }
27
- its(:class) { should be == Mustermann::Sinatra }
28
- its(:to_s) { should be == "/{foo}/{bar}" }
29
- end
30
-
31
- context "sinatra + flask" do
32
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/<bar>", type: :flask) }
33
- its(:class) { should be == Mustermann::Sinatra }
34
- its(:to_s) { should be == "/{foo}/{bar}" }
35
- end
36
-
37
- context "sinatra + flask (typed)" do
38
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/<int:bar>", type: :flask) }
39
- its(:class) { should be == Mustermann::Concat }
40
- its(:to_s) { should be == '(sinatra:"/:foo" + flask:"/<int:bar>")' }
41
- end
42
-
43
- context "sinatra + sinatra (different options)" do
44
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", uri_decode: false) }
45
- its(:class) { should be == Mustermann::Concat }
46
- its(:to_s) { should be == '(sinatra:"/:foo" + sinatra:"/:bar")' }
47
- end
48
-
49
- context "sinatra + rails (different options)" do
50
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails, uri_decode: false) }
51
- its(:class) { should be == Mustermann::Concat }
52
- its(:to_s) { should be == '(sinatra:"/:foo" + rails:"/:bar")' }
53
- end
54
-
55
- context "sinatra + rails (different options) + sinatra" do
56
- subject(:pattern) { Mustermann.new("/:foo") + Mustermann.new("/:bar", type: :rails, uri_decode: false) + Mustermann.new("/:baz") }
57
- its(:class) { should be == Mustermann::Concat }
58
- its(:to_s) { should be == '(sinatra:"/:foo" + rails:"/:bar" + sinatra:"/:baz")' }
59
- end
60
-
61
- context "sinatra + (sinatra + regular)" do
62
- subject(:pattern) { Mustermann.new("/foo") + (Mustermann.new("/bar") + Mustermann.new(/baz/)) }
63
- its(:class) { should be == Mustermann::Concat }
64
- its(:to_s) { should be == '(sinatra:"/foo/bar" + regular:"baz")' }
65
- end
66
-
67
- context "sinatra + (sinatra + rails (different options) + sinatra)" do
68
- subject(:pattern) { Mustermann.new("/foo") + (Mustermann.new("/bar") + Mustermann.new("/baz", type: :rails, uri_decode: false) + Mustermann.new("/boo")) }
69
- its(:class) { should be == Mustermann::Concat }
70
- its(:to_s) { should be == '(sinatra:"/foo/bar" + rails:"/baz" + sinatra:"/boo")' }
71
- end
72
- end
73
-
74
- subject(:pattern) { Mustermann::Concat.new("/:foo", "/:bar") }
75
-
76
- describe :=== do
77
- example { (pattern === "/foo/bar") .should be true }
78
- example { (pattern === "/foo/bar/") .should be false }
79
- example { (pattern === "/foo") .should be false }
80
- end
81
-
82
- describe :match do
83
- it { should match("/foo/bar").capturing(foo: "foo", bar: "bar") }
84
- it { should_not match("/foo/bar/") }
85
- it { should_not match("/foo/") }
86
- end
87
-
88
- describe :params do
89
- example { pattern.params("/foo/bar") .should be == { "foo" => "foo", "bar" => "bar" }}
90
- example { pattern.params("/foo/bar/") .should be_nil }
91
- example { pattern.params("/foo") .should be_nil }
92
- end
93
-
94
- describe :peek do
95
- example { pattern.peek("/foo/bar/baz") .should be == "/foo/bar" }
96
- example { pattern.peek("/foo") .should be_nil }
97
- end
98
-
99
- describe :peek_params do
100
- example { pattern.peek_params("/foo/bar/baz") .should be == [{ "foo" => "foo", "bar" => "bar" }, 8]}
101
- example { pattern.peek_params("/foo") .should be_nil }
102
- end
103
-
104
- describe :peek_match do
105
- example { pattern.peek_match("/foo/bar/baz").to_s .should be == "/foo/bar" }
106
- example { pattern.peek_match("/foo") .should be_nil }
107
- end
108
-
109
- describe :peek_size do
110
- example { pattern.peek_size("/foo/bar/baz") .should be == 8 }
111
- example { pattern.peek_size("/foo") .should be_nil }
112
- end
113
-
114
- describe :expand do
115
- it { should expand(foo: :bar, bar: :foo) .to('/bar/foo') }
116
- it { should expand(:append, foo: :bar, bar: :foo, baz: 42) .to('/bar/foo?baz=42') }
117
- it { should_not expand(foo: :bar) }
118
- end
119
-
120
- describe :to_templates do
121
- subject(:pattern) { Mustermann::Concat.new("/:foo|:bar", "(/:baz)?") }
122
- it { should generate_template("/{foo}/{baz}") }
123
- it { should generate_template("{bar}/{baz}") }
124
- it { should generate_template("/{foo}") }
125
- it { should generate_template("{bar}") }
126
- end
127
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/equality_map'
4
-
5
- RSpec.describe Mustermann::EqualityMap do
6
- before { GC.disable }
7
- after { GC.enable }
8
-
9
- describe :fetch do
10
- subject { Mustermann::EqualityMap.new }
11
- specify 'with existing entry' do
12
- next if subject.is_a? Hash
13
- subject.fetch("foo") { "foo" }
14
- result = subject.fetch("foo") { "bar" }
15
- expect(result).to be == "foo"
16
- end
17
-
18
- specify 'with GC-removed entry' do
19
- next if subject.is_a? Hash
20
- subject.fetch(String.new('foo')) { "foo" }
21
- expect(subject.map).to receive(:[]).and_return(nil)
22
- result = subject.fetch(String.new('foo')) { "bar" }
23
- expect(result).to be == "bar"
24
- end
25
-
26
- specify 'allows a frozen key and value' do
27
- next if subject.is_a? Hash
28
- key = "foo".freeze
29
- value = "bar".freeze
30
- subject.fetch(key) { value }
31
- result = subject.fetch("foo".dup) { raise "not executed" }
32
- expect(result).to be == value
33
- expect(result).not_to equal value
34
- end
35
-
36
- specify 'allows only a single argument to be compatible with Hash#fetch' do
37
- expect {
38
- subject.fetch("foo", "bar", "baz") { "value" }
39
- }.to raise_error(ArgumentError)
40
- end
41
- end
42
- end
@@ -1,123 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/expander'
4
-
5
- describe Mustermann::Expander do
6
- it 'expands a pattern' do
7
- expander = Mustermann::Expander.new("/:foo.jpg")
8
- expander.expand(foo: 42).should be == "/42.jpg"
9
- end
10
-
11
- it 'expands multiple patterns' do
12
- expander = Mustermann::Expander.new << "/:foo.:ext" << "/:foo"
13
- expander.expand(foo: 42, ext: 'jpg').should be == "/42.jpg"
14
- expander.expand(foo: 23).should be == "/23"
15
- end
16
-
17
- it 'supports setting pattern options' do
18
- expander = Mustermann::Expander.new(type: :rails) << "/:foo(.:ext)" << "/:bar"
19
- expander.expand(foo: 42, ext: 'jpg').should be == "/42.jpg"
20
- expander.expand(foo: 42).should be == "/42"
21
- end
22
-
23
- it 'supports combining different pattern styles' do
24
- expander = Mustermann::Expander.new << Mustermann.new("/:foo(.:ext)", type: :rails) << Mustermann.new("/:bar", type: :sinatra)
25
- expander.expand(foo: 'pony', ext: 'jpg').should be == '/pony.jpg'
26
- expander.expand(bar: 23).should be == "/23"
27
- end
28
-
29
- it 'ignores nil values' do
30
- expander = Mustermann::Expander.new << Mustermann.new("/:foo(.:ext)?")
31
- expander.expand(foo: 'pony', ext: nil).should be == '/pony'
32
- end
33
-
34
- it 'supports splat' do
35
- expander = Mustermann::Expander.new << Mustermann.new("/foo/*/baz")
36
- expander.expand(splat: 'bar').should be == '/foo/bar/baz'
37
- end
38
-
39
- it 'supports multiple splats' do
40
- expander = Mustermann::Expander.new << Mustermann.new("/foo/*/bar/*")
41
- expander.expand(splat: [123, 456]).should be == '/foo/123/bar/456'
42
- end
43
-
44
- it 'supports identity patterns' do
45
- expander = Mustermann::Expander.new('/:foo', type: :identity)
46
- expander.expand.should be == '/:foo'
47
- end
48
-
49
- describe :additional_values do
50
- context "illegal value" do
51
- example { expect { Mustermann::Expander.new(additional_values: :foo) }.to raise_error(ArgumentError) }
52
- example { expect { Mustermann::Expander.new('/').expand(:foo, a: 10) }.to raise_error(ArgumentError) }
53
- end
54
-
55
- context :raise do
56
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :raise) }
57
- example { expander.expand(a: ?a).should be == '/a' }
58
- example { expect { expander.expand(a: ?a, b: ?b) }.to raise_error(Mustermann::ExpandError) }
59
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
60
- end
61
-
62
- context :ignore do
63
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :ignore) }
64
- example { expander.expand(a: ?a).should be == '/a' }
65
- example { expander.expand(a: ?a, b: ?b).should be == '/a' }
66
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
67
- example { expect { expander.expand(b: ?b, c: []) }.to raise_error(Mustermann::ExpandError) }
68
- example { expect { expander.expand(b: ?b, c: [], d: ?d) }.to raise_error(Mustermann::ExpandError) }
69
- end
70
-
71
- context :append do
72
- subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :append) }
73
- example { expander.expand(a: ?a).should be == '/a' }
74
- example { expander.expand(a: ?a, b: ?b).should be == '/a?b=b' }
75
- example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
76
- end
77
- end
78
-
79
- describe :cast do
80
- subject(:expander) { Mustermann::Expander.new('/:a(/:b)?') }
81
-
82
- example { expander.cast { "FOOBAR" }.expand(a: "foo") .should be == "/FOOBAR" }
83
- example { expander.cast { |v| v.upcase }.expand(a: "foo") .should be == "/FOO" }
84
- example { expander.cast { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/BAR" }
85
- example { expander.cast(:a) { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/bar" }
86
- example { expander.cast(:a, :b) { |v| v.upcase }.expand(a: "foo", b: "bar") .should be == "/FOO/BAR" }
87
- example { expander.cast(Integer) { |k,v| "#{k}_#{v}" }.expand(a: "foo", b: 42) .should be == "/foo/b_42" }
88
-
89
- example do
90
- expander.cast(:a) { |v| v.upcase }
91
- expander.cast(:b) { |v| v.downcase }
92
- expander.expand(a: "fOo", b: "bAr").should be == "/FOO/bar"
93
- end
94
- end
95
-
96
- describe :== do
97
- example { Mustermann::Expander.new('/foo') .should be == Mustermann::Expander.new('/foo') }
98
- example { Mustermann::Expander.new('/foo') .should_not be == Mustermann::Expander.new('/bar') }
99
- example { Mustermann::Expander.new('/foo', type: :rails) .should be == Mustermann::Expander.new('/foo', type: :rails) }
100
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be == Mustermann::Expander.new('/foo', type: :sinatra) }
101
- end
102
-
103
- describe :hash do
104
- example { Mustermann::Expander.new('/foo') .hash.should be == Mustermann::Expander.new('/foo').hash }
105
- example { Mustermann::Expander.new('/foo') .hash.should_not be == Mustermann::Expander.new('/bar').hash }
106
- example { Mustermann::Expander.new('/foo', type: :rails) .hash.should be == Mustermann::Expander.new('/foo', type: :rails).hash }
107
- example { Mustermann::Expander.new('/foo', type: :rails) .hash.should_not be == Mustermann::Expander.new('/foo', type: :sinatra).hash }
108
- end
109
-
110
- describe :eql? do
111
- example { Mustermann::Expander.new('/foo') .should be_eql Mustermann::Expander.new('/foo') }
112
- example { Mustermann::Expander.new('/foo') .should_not be_eql Mustermann::Expander.new('/bar') }
113
- example { Mustermann::Expander.new('/foo', type: :rails) .should be_eql Mustermann::Expander.new('/foo', type: :rails) }
114
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_eql Mustermann::Expander.new('/foo', type: :sinatra) }
115
- end
116
-
117
- describe :equal? do
118
- example { Mustermann::Expander.new('/foo') .should_not be_equal Mustermann::Expander.new('/foo') }
119
- example { Mustermann::Expander.new('/foo') .should_not be_equal Mustermann::Expander.new('/bar') }
120
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_equal Mustermann::Expander.new('/foo', type: :rails) }
121
- example { Mustermann::Expander.new('/foo', type: :rails) .should_not be_equal Mustermann::Expander.new('/foo', type: :sinatra) }
122
- end
123
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/identity'
4
-
5
- describe Mustermann::Identity do
6
- extend Support::Pattern
7
-
8
- pattern '' do
9
- it { should match('') }
10
- it { should_not match('/') }
11
-
12
- it { should respond_to(:expand) }
13
- it { should respond_to(:to_templates) }
14
-
15
-
16
- it { should generate_template('') }
17
- it { should expand.to('') }
18
- it { should expand(:ignore, a: 10).to('') }
19
- it { should expand(:append, a: 10).to('?a=10') }
20
- it { should_not expand(:raise, a: 10) }
21
- it { should_not expand(a: 10) }
22
-
23
- example do
24
- pattern.match('').inspect.should be == '#<Mustermann::SimpleMatch "">'
25
- end
26
- end
27
-
28
- pattern '/' do
29
- it { should match('/') }
30
- it { should_not match('/foo') }
31
-
32
- example { pattern.params('/').should be == {} }
33
- example { pattern.params('').should be_nil }
34
-
35
- it { should generate_template('/') }
36
- it { should expand.to('/') }
37
- end
38
-
39
- pattern '/foo' do
40
- it { should match('/foo') }
41
- it { should_not match('/bar') }
42
- it { should_not match('/foo.bar') }
43
- end
44
-
45
- pattern '/foo/bar' do
46
- it { should match('/foo/bar') }
47
- it { should match('/foo%2Fbar') }
48
- it { should match('/foo%2fbar') }
49
- end
50
-
51
- pattern '/:foo' do
52
- it { should match('/:foo') }
53
- it { should match('/%3Afoo') }
54
- it { should_not match('/foo') }
55
- it { should_not match('/foo?') }
56
- it { should_not match('/foo/bar') }
57
- it { should_not match('/') }
58
- it { should_not match('/foo/') }
59
-
60
- it { should generate_template('/:foo') }
61
- it { should expand.to('/:foo') }
62
- end
63
-
64
- pattern '/föö' do
65
- it { should match("/f%C3%B6%C3%B6") }
66
- end
67
-
68
- pattern '/test$/' do
69
- it { should match('/test$/') }
70
- end
71
-
72
- pattern '/te+st/' do
73
- it { should match('/te+st/') }
74
- it { should_not match('/test/') }
75
- it { should_not match('/teest/') }
76
- end
77
-
78
- pattern "/path with spaces" do
79
- it { should match('/path%20with%20spaces') }
80
- it { should_not match('/path%2Bwith%2Bspaces') }
81
- it { should_not match('/path+with+spaces') }
82
- it { should generate_template('/path%20with%20spaces') }
83
- end
84
-
85
- pattern '/foo&bar' do
86
- it { should match('/foo&bar') }
87
- end
88
-
89
- pattern '/test.bar' do
90
- it { should match('/test.bar') }
91
- it { should_not match('/test0bar') }
92
- end
93
-
94
- pattern '/foo/bar', uri_decode: false do
95
- it { should match('/foo/bar') }
96
- it { should_not match('/foo%2Fbar') }
97
- it { should_not match('/foo%2fbar') }
98
- end
99
-
100
- pattern "/path with spaces", uri_decode: false do
101
- it { should_not match('/path%20with%20spaces') }
102
- it { should_not match('/path%2Bwith%2Bspaces') }
103
- it { should_not match('/path+with+spaces') }
104
- end
105
-
106
- context "peeking" do
107
- subject(:pattern) { Mustermann::Identity.new("foo bar") }
108
-
109
- describe :peek_size do
110
- example { pattern.peek_size("foo bar blah") .should be == "foo bar".size }
111
- example { pattern.peek_size("foo%20bar blah") .should be == "foo%20bar".size }
112
- example { pattern.peek_size("foobar") .should be_nil }
113
- end
114
-
115
- describe :peek_match do
116
- example { pattern.peek_match("foo bar blah").to_s .should be == "foo bar" }
117
- example { pattern.peek_match("foo%20bar blah").to_s .should be == "foo%20bar" }
118
- example { pattern.peek_match("foobar") .should be_nil }
119
- end
120
-
121
- describe :peek_params do
122
- example { pattern.peek_params("foo bar blah") .should be == [{}, "foo bar".size] }
123
- example { pattern.peek_params("foo%20bar blah") .should be == [{}, "foo%20bar".size] }
124
- example { pattern.peek_params("foobar") .should be_nil }
125
- end
126
- end
127
- end
data/spec/mapper_spec.rb DELETED
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'support'
3
- require 'mustermann/mapper'
4
-
5
- describe Mustermann::Mapper do
6
- describe :initialize do
7
- context 'accepts a block with no arguments, using the return value' do
8
- subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) {{ "/foo" => "/bar" }}}
9
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
10
- example { mapper['/foo'].should be == '/bar' }
11
- example { mapper['/fox'].should be == '/fox' }
12
- end
13
-
14
- context 'accepts a block with argument, passes instance to it' do
15
- subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise) { |m| m["/foo"] = "/bar" }}
16
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
17
- example { mapper['/foo'].should be == '/bar' }
18
- example { mapper['/fox'].should be == '/fox' }
19
- end
20
-
21
- context 'accepts mappings followed by options' do
22
- subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise) }
23
- its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
24
- example { mapper['/foo'].should be == '/bar' }
25
- example { mapper['/fox'].should be == '/fox' }
26
- end
27
-
28
- context 'allows specifying type' do
29
- subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise, type: :rails) }
30
- its(:to_h) { should be == { Mustermann.new("/foo", type: :rails) => Mustermann::Expander.new("/bar", type: :rails) } }
31
- example { mapper['/foo'].should be == '/bar' }
32
- example { mapper['/fox'].should be == '/fox' }
33
- end
34
- end
35
-
36
- describe :convert do
37
- subject(:mapper) { Mustermann::Mapper.new }
38
-
39
- context 'it maps params' do
40
- before { mapper["/:a"] = "/:a.html" }
41
- example { mapper["/foo"] .should be == "/foo.html" }
42
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
43
- end
44
-
45
- context 'it supports named splats' do
46
- before { mapper["/*a"] = "/*a.html" }
47
- example { mapper["/foo"] .should be == "/foo.html" }
48
- example { mapper["/foo/bar"] .should be == "/foo/bar.html" }
49
- end
50
-
51
- context 'can map from patterns' do
52
- before { mapper[Mustermann.new("/:a")] = "/:a.html" }
53
- example { mapper["/foo"] .should be == "/foo.html" }
54
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
55
- end
56
-
57
- context 'can map to patterns' do
58
- before { mapper[Mustermann.new("/:a")] = Mustermann.new("/:a.html") }
59
- example { mapper["/foo"] .should be == "/foo.html" }
60
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
61
- end
62
-
63
- context 'can map to expanders' do
64
- before { mapper[Mustermann.new("/:a")] = Mustermann::Expander.new("/:a.html") }
65
- example { mapper["/foo"] .should be == "/foo.html" }
66
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
67
- end
68
-
69
- context 'can map to array' do
70
- before { mapper["/:a"] = ["/:a.html", "/:a.:f"] }
71
- example { mapper["/foo"] .should be == "/foo.html" }
72
- example { mapper["/foo", "f" => 'x'] .should be == "/foo.x" }
73
- example { mapper["/foo", f: 'x'] .should be == "/foo.x" }
74
- example { mapper["/foo/bar"] .should be == "/foo/bar" }
75
- end
76
- end
77
- end