mustermann 3.0.3 → 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.
- checksums.yaml +4 -4
- data/README.md +113 -1
- data/lib/mustermann/ast/expander.rb +4 -5
- data/lib/mustermann/ast/parser.rb +2 -3
- data/lib/mustermann/ast/translator.rb +4 -5
- data/lib/mustermann/expander.rb +1 -1
- data/lib/mustermann/pattern.rb +1 -1
- data/lib/mustermann/rails.rb +47 -0
- data/lib/mustermann/sinatra/safe_renderer.rb +1 -1
- data/lib/mustermann/version.rb +1 -1
- data/lib/mustermann/versions.rb +47 -0
- data/lib/mustermann.rb +0 -9
- metadata +7 -42
- data/bench/capturing.rb +0 -57
- data/bench/regexp.rb +0 -21
- data/bench/simple_vs_sinatra.rb +0 -23
- data/bench/template_vs_addressable.rb +0 -26
- data/bench/uri_parser_object.rb +0 -16
- data/mustermann.gemspec +0 -18
- data/spec/ast_spec.rb +0 -15
- data/spec/composite_spec.rb +0 -163
- data/spec/concat_spec.rb +0 -127
- data/spec/equality_map_spec.rb +0 -42
- data/spec/expander_spec.rb +0 -123
- data/spec/identity_spec.rb +0 -127
- data/spec/mapper_spec.rb +0 -77
- data/spec/mustermann_spec.rb +0 -81
- data/spec/pattern_spec.rb +0 -54
- data/spec/regexp_based_spec.rb +0 -9
- data/spec/regular_spec.rb +0 -119
- data/spec/simple_match_spec.rb +0 -11
- data/spec/sinatra_spec.rb +0 -836
- data/spec/to_pattern_spec.rb +0 -70
data/spec/mustermann_spec.rb
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'support'
|
|
3
|
-
require 'mustermann'
|
|
4
|
-
require 'sinatra/base'
|
|
5
|
-
|
|
6
|
-
describe Mustermann do
|
|
7
|
-
describe :new do
|
|
8
|
-
context "string argument" do
|
|
9
|
-
example { Mustermann.new('') .should be_a(Mustermann::Sinatra) }
|
|
10
|
-
example { Mustermann.new('', type: :identity) .should be_a(Mustermann::Identity) }
|
|
11
|
-
example { Mustermann.new('', type: :rails) .should be_a(Mustermann::Rails) }
|
|
12
|
-
example { Mustermann.new('', type: :shell) .should be_a(Mustermann::Shell) }
|
|
13
|
-
example { Mustermann.new('', type: :sinatra) .should be_a(Mustermann::Sinatra) }
|
|
14
|
-
example { Mustermann.new('', type: :simple) .should be_a(Mustermann::Simple) }
|
|
15
|
-
example { Mustermann.new('', type: :template) .should be_a(Mustermann::Template) }
|
|
16
|
-
|
|
17
|
-
example { expect { Mustermann.new('', foo: :bar) }.to raise_error(ArgumentError, "unsupported option :foo for Mustermann::Sinatra") }
|
|
18
|
-
example { expect { Mustermann.new('', type: :ast) }.to raise_error(ArgumentError, "unsupported type :ast (cannot load such file -- mustermann/ast)") }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "pattern argument" do
|
|
22
|
-
subject(:pattern) { Mustermann.new('') }
|
|
23
|
-
example { Mustermann.new(pattern).should be == pattern }
|
|
24
|
-
example { Mustermann.new(pattern, type: :rails).should be_a(Mustermann::Sinatra) }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "regexp argument" do
|
|
28
|
-
example { Mustermann.new(//) .should be_a(Mustermann::Regular) }
|
|
29
|
-
example { Mustermann.new(//, type: :rails) .should be_a(Mustermann::Regular) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
context "argument implementing #to_pattern" do
|
|
33
|
-
subject(:pattern) { Class.new { def to_pattern(**o) Mustermann.new('foo', **o) end }.new }
|
|
34
|
-
example { Mustermann.new(pattern) .should be_a(Mustermann::Sinatra) }
|
|
35
|
-
example { Mustermann.new(pattern, type: :rails) .should be_a(Mustermann::Rails) }
|
|
36
|
-
example { Mustermann.new(pattern).to_s.should be == 'foo' }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "multiple arguments" do
|
|
40
|
-
example { Mustermann.new(':a', ':b/:a') .should be_a(Mustermann::Composite) }
|
|
41
|
-
example { Mustermann.new(':a', ':b/:a').patterns.first .should be_a(Mustermann::Sinatra) }
|
|
42
|
-
example { Mustermann.new(':a', ':b/:a').operator .should be == :| }
|
|
43
|
-
example { Mustermann.new(':a', ':b/:a', operator: :&).operator .should be == :& }
|
|
44
|
-
example { Mustermann.new(':a', ':b/:a', greedy: true) .should be_a(Mustermann::Composite) }
|
|
45
|
-
|
|
46
|
-
example { Mustermann.new('/foo', ':bar') .should be_a(Mustermann::Sinatra) }
|
|
47
|
-
example { Mustermann.new('/foo', ':bar').to_s .should be == "/foo|{bar}" }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "invalid arguments" do
|
|
51
|
-
it "raise a TypeError for unsupported types" do
|
|
52
|
-
expect { Mustermann.new(10) }.to raise_error(TypeError, /(Integer|Fixnum) can't be coerced into Mustermann::Pattern/)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe :[] do
|
|
58
|
-
example { Mustermann[:identity] .should be == Mustermann::Identity }
|
|
59
|
-
example { Mustermann[:rails] .should be == Mustermann::Rails }
|
|
60
|
-
example { Mustermann[:shell] .should be == Mustermann::Shell }
|
|
61
|
-
example { Mustermann[:sinatra] .should be == Mustermann::Sinatra }
|
|
62
|
-
example { Mustermann[:simple] .should be == Mustermann::Simple }
|
|
63
|
-
example { Mustermann[:template] .should be == Mustermann::Template }
|
|
64
|
-
|
|
65
|
-
example { expect { Mustermann[:ast] }.to raise_error(ArgumentError, "unsupported type :ast (cannot load such file -- mustermann/ast)") }
|
|
66
|
-
example { expect { Mustermann[:expander] }.to raise_error(ArgumentError, "unsupported type :expander") }
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe :extend_object do
|
|
70
|
-
context 'special behavior for Sinatra only' do
|
|
71
|
-
example { Object .new.extend(Mustermann).should be_a(Mustermann) }
|
|
72
|
-
example { Class .new.extend(Mustermann).should be_a(Mustermann) }
|
|
73
|
-
|
|
74
|
-
example { expect { Sinatra.new.extend(Mustermann) }.to raise_error(RuntimeError, "Mustermann extension for Sinatra has been extracted into its own gem. More information at https://github.com/sinatra/mustermann-sinatra-extension") }
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe :=== do
|
|
79
|
-
example { Mustermann.should be === Mustermann.new("") }
|
|
80
|
-
end
|
|
81
|
-
end
|
data/spec/pattern_spec.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'support'
|
|
3
|
-
require 'mustermann/pattern'
|
|
4
|
-
require 'mustermann/sinatra'
|
|
5
|
-
require 'mustermann/rails'
|
|
6
|
-
|
|
7
|
-
describe Mustermann::Pattern do
|
|
8
|
-
describe :=== do
|
|
9
|
-
it 'raises a NotImplementedError when used directly' do
|
|
10
|
-
expect { Mustermann::Pattern.new("") === "" }.to raise_error(NotImplementedError)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe :initialize do
|
|
15
|
-
it 'raises an ArgumentError for unknown options' do
|
|
16
|
-
expect { Mustermann::Pattern.new("", foo: :bar) }.to raise_error(ArgumentError)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'does not complain about unknown options if ignore_unknown_options is enabled' do
|
|
20
|
-
expect { Mustermann::Pattern.new("", foo: :bar, ignore_unknown_options: true) }.not_to raise_error
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe :respond_to? do
|
|
25
|
-
subject(:pattern) { Mustermann::Pattern.new("") }
|
|
26
|
-
|
|
27
|
-
it { should_not respond_to(:expand) }
|
|
28
|
-
it { should_not respond_to(:to_templates) }
|
|
29
|
-
|
|
30
|
-
it { expect { pattern.expand } .to raise_error(NotImplementedError) }
|
|
31
|
-
it { expect { pattern.to_templates } .to raise_error(NotImplementedError) }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe :== do
|
|
35
|
-
example { Mustermann::Pattern.new('/foo') .should be == Mustermann::Pattern.new('/foo') }
|
|
36
|
-
example { Mustermann::Pattern.new('/foo') .should_not be == Mustermann::Pattern.new('/bar') }
|
|
37
|
-
example { Mustermann::Sinatra.new('/foo') .should be == Mustermann::Sinatra.new('/foo') }
|
|
38
|
-
example { Mustermann::Rails.new('/foo') .should_not be == Mustermann::Sinatra.new('/foo') }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe :eql? do
|
|
42
|
-
example { Mustermann::Pattern.new('/foo') .should be_eql Mustermann::Pattern.new('/foo') }
|
|
43
|
-
example { Mustermann::Pattern.new('/foo') .should_not be_eql Mustermann::Pattern.new('/bar') }
|
|
44
|
-
example { Mustermann::Sinatra.new('/foo') .should be_eql Mustermann::Sinatra.new('/foo') }
|
|
45
|
-
example { Mustermann::Rails.new('/foo') .should_not be_eql Mustermann::Sinatra.new('/foo') }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe :equal? do
|
|
49
|
-
example { Mustermann::Pattern.new('/foo') .should be_equal Mustermann::Pattern.new('/foo') }
|
|
50
|
-
example { Mustermann::Pattern.new('/foo') .should_not be_equal Mustermann::Pattern.new('/bar') }
|
|
51
|
-
example { Mustermann::Sinatra.new('/foo') .should be_equal Mustermann::Sinatra.new('/foo') }
|
|
52
|
-
example { Mustermann::Rails.new('/foo') .should_not be_equal Mustermann::Sinatra.new('/foo') }
|
|
53
|
-
end
|
|
54
|
-
end
|
data/spec/regexp_based_spec.rb
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'support'
|
|
3
|
-
require 'mustermann/regexp_based'
|
|
4
|
-
|
|
5
|
-
describe Mustermann::RegexpBased do
|
|
6
|
-
it 'raises a NotImplementedError when used directly' do
|
|
7
|
-
expect { Mustermann::RegexpBased.new("") === "" }.to raise_error(NotImplementedError)
|
|
8
|
-
end
|
|
9
|
-
end
|
data/spec/regular_spec.rb
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'support'
|
|
3
|
-
require 'timeout'
|
|
4
|
-
require 'mustermann/regular'
|
|
5
|
-
|
|
6
|
-
describe Mustermann::Regular do
|
|
7
|
-
extend Support::Pattern
|
|
8
|
-
|
|
9
|
-
pattern '' do
|
|
10
|
-
it { should match('') }
|
|
11
|
-
it { should_not match('/') }
|
|
12
|
-
|
|
13
|
-
it { should_not respond_to(:expand) }
|
|
14
|
-
it { should_not respond_to(:to_templates) }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
pattern '/' do
|
|
18
|
-
it { should match('/') }
|
|
19
|
-
it { should_not match('/foo') }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
pattern '/foo' do
|
|
23
|
-
it { should match('/foo') }
|
|
24
|
-
it { should_not match('/bar') }
|
|
25
|
-
it { should_not match('/foo.bar') }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
pattern '/foo/bar' do
|
|
29
|
-
it { should match('/foo/bar') }
|
|
30
|
-
it { should_not match('/foo%2Fbar') }
|
|
31
|
-
it { should_not match('/foo%2fbar') }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
pattern '/(?<foo>.*)' do
|
|
35
|
-
it { should match('/foo') .capturing foo: 'foo' }
|
|
36
|
-
it { should match('/bar') .capturing foo: 'bar' }
|
|
37
|
-
it { should match('/foo.bar') .capturing foo: 'foo.bar' }
|
|
38
|
-
it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
|
|
39
|
-
it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
context 'with Regexp::EXTENDED' do
|
|
44
|
-
let(:pattern) {
|
|
45
|
-
%r{
|
|
46
|
-
\/compare\/ # match any URL beginning with \/compare\/
|
|
47
|
-
(.+) # extract the full path (including any directories)
|
|
48
|
-
\/ # match the final slash
|
|
49
|
-
([^.]+) # match the first SHA1
|
|
50
|
-
\.{2,3} # match .. or ...
|
|
51
|
-
(.+) # match the second SHA1
|
|
52
|
-
}x
|
|
53
|
-
}
|
|
54
|
-
example { expect { Timeout.timeout(1){ Mustermann::Regular.new(pattern) }}.not_to raise_error }
|
|
55
|
-
it { expect(Mustermann::Regular.new(pattern)).to match('/compare/foo/bar..baz') }
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe :check_achnors do
|
|
59
|
-
context 'raises on anchors' do
|
|
60
|
-
example { expect { Mustermann::Regular.new('^foo') }.to raise_error(Mustermann::CompileError) }
|
|
61
|
-
example { expect { Mustermann::Regular.new('foo$') }.to raise_error(Mustermann::CompileError) }
|
|
62
|
-
example { expect { Mustermann::Regular.new('\Afoo') }.to raise_error(Mustermann::CompileError) }
|
|
63
|
-
example { expect { Mustermann::Regular.new('foo\Z') }.to raise_error(Mustermann::CompileError) }
|
|
64
|
-
example { expect { Mustermann::Regular.new('foo\z') }.to raise_error(Mustermann::CompileError) }
|
|
65
|
-
example { expect { Mustermann::Regular.new(/^foo/) }.to raise_error(Mustermann::CompileError) }
|
|
66
|
-
example { expect { Mustermann::Regular.new(/foo$/) }.to raise_error(Mustermann::CompileError) }
|
|
67
|
-
example { expect { Mustermann::Regular.new(/\Afoo/) }.to raise_error(Mustermann::CompileError) }
|
|
68
|
-
example { expect { Mustermann::Regular.new(/foo\Z/) }.to raise_error(Mustermann::CompileError) }
|
|
69
|
-
example { expect { Mustermann::Regular.new(/foo\z/) }.to raise_error(Mustermann::CompileError) }
|
|
70
|
-
example { expect { Mustermann::Regular.new('[^f]') }.not_to raise_error }
|
|
71
|
-
example { expect { Mustermann::Regular.new('\\\A') }.not_to raise_error }
|
|
72
|
-
example { expect { Mustermann::Regular.new('[[:digit:]]') }.not_to raise_error }
|
|
73
|
-
example { expect { Mustermann::Regular.new(/[^f]/) }.not_to raise_error }
|
|
74
|
-
example { expect { Mustermann::Regular.new(/\\A/) }.not_to raise_error }
|
|
75
|
-
example { expect { Mustermann::Regular.new(/[[:digit:]]/) }.not_to raise_error }
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
context 'with check_anchors disabled' do
|
|
79
|
-
example { expect { Mustermann::Regular.new('^foo', check_anchors: false) }.not_to raise_error }
|
|
80
|
-
example { expect { Mustermann::Regular.new('foo$', check_anchors: false) }.not_to raise_error }
|
|
81
|
-
example { expect { Mustermann::Regular.new('\Afoo', check_anchors: false) }.not_to raise_error }
|
|
82
|
-
example { expect { Mustermann::Regular.new('foo\Z', check_anchors: false) }.not_to raise_error }
|
|
83
|
-
example { expect { Mustermann::Regular.new('foo\z', check_anchors: false) }.not_to raise_error }
|
|
84
|
-
example { expect { Mustermann::Regular.new(/^foo/, check_anchors: false) }.not_to raise_error }
|
|
85
|
-
example { expect { Mustermann::Regular.new(/foo$/, check_anchors: false) }.not_to raise_error }
|
|
86
|
-
example { expect { Mustermann::Regular.new(/\Afoo/, check_anchors: false) }.not_to raise_error }
|
|
87
|
-
example { expect { Mustermann::Regular.new(/foo\Z/, check_anchors: false) }.not_to raise_error }
|
|
88
|
-
example { expect { Mustermann::Regular.new(/foo\z/, check_anchors: false) }.not_to raise_error }
|
|
89
|
-
example { expect { Mustermann::Regular.new('[^f]', check_anchors: false) }.not_to raise_error }
|
|
90
|
-
example { expect { Mustermann::Regular.new('\\\A', check_anchors: false) }.not_to raise_error }
|
|
91
|
-
example { expect { Mustermann::Regular.new('[[:digit:]]', check_anchors: false) }.not_to raise_error }
|
|
92
|
-
example { expect { Mustermann::Regular.new(/[^f]/, check_anchors: false) }.not_to raise_error }
|
|
93
|
-
example { expect { Mustermann::Regular.new(/\\A/, check_anchors: false) }.not_to raise_error }
|
|
94
|
-
example { expect { Mustermann::Regular.new(/[[:digit:]]/, check_anchors: false) }.not_to raise_error }
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "peeking" do
|
|
99
|
-
subject(:pattern) { Mustermann::Regular.new("(?<name>[^/]+)") }
|
|
100
|
-
|
|
101
|
-
describe :peek_size do
|
|
102
|
-
example { pattern.peek_size("foo bar/blah") .should be == "foo bar".size }
|
|
103
|
-
example { pattern.peek_size("foo%20bar/blah") .should be == "foo%20bar".size }
|
|
104
|
-
example { pattern.peek_size("/foo bar") .should be_nil }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe :peek_match do
|
|
108
|
-
example { pattern.peek_match("foo bar/blah") .to_s .should be == "foo bar" }
|
|
109
|
-
example { pattern.peek_match("foo%20bar/blah") .to_s .should be == "foo%20bar" }
|
|
110
|
-
example { pattern.peek_match("/foo bar") .should be_nil }
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
describe :peek_params do
|
|
114
|
-
example { pattern.peek_params("foo bar/blah") .should be == [{"name" => "foo bar"}, "foo bar".size] }
|
|
115
|
-
example { pattern.peek_params("foo%20bar/blah") .should be == [{"name" => "foo bar"}, "foo%20bar".size] }
|
|
116
|
-
example { pattern.peek_params("/foo bar") .should be_nil }
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
data/spec/simple_match_spec.rb
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'support'
|
|
3
|
-
require 'mustermann/simple_match'
|
|
4
|
-
|
|
5
|
-
describe Mustermann::SimpleMatch do
|
|
6
|
-
subject { Mustermann::SimpleMatch.new('example') }
|
|
7
|
-
its(:to_s) { should be == 'example' }
|
|
8
|
-
its(:names) { should be == [] }
|
|
9
|
-
its(:captures) { should be == [] }
|
|
10
|
-
example { subject[1].should be == nil }
|
|
11
|
-
end
|