Skip to content

Commit fd9eadd

Browse files
committed
Move LITERALMATCH consant out of CodeObjects
1 parent d51391e commit fd9eadd

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

lib/yard/code_objects/base.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def push(value)
6363
# Regular expression to match a fully qualified method def (self.foo, Class.foo).
6464
METHODMATCH = /(?:(?:#{NAMESPACEMATCH}|[a-z]\w*)\s*(?:#{CSEPQ}|#{NSEPQ})\s*)?#{METHODNAMEMATCH}/
6565

66-
# Regular expression to match symbol and string literals
67-
LITERALMATCH = /:\w+|'[^']*'|"[^"]*"/
68-
6966
# All builtin Ruby exception classes for inheritance tree.
7067
BUILTIN_EXCEPTIONS = ["ArgumentError", "ClosedQueueError", "EncodingError",
7168
"EOFError", "Exception", "FiberError", "FloatDomainError", "IndexError",

lib/yard/tags/types_explainer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
module YARD
55
module Tags
66
class TypesExplainer
7+
# Regular expression to match symbol and string literals
8+
LITERALMATCH = /:\w+|'[^']*'|"[^"]*"/
9+
710
# (see Tag#explain_types)
811
# @param types [Array<String>] a list of types to parse and summarize
912
def self.explain(*types)

spec/code_objects/constants_spec.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,6 @@ def silence_warnings
5656
end
5757
end
5858

59-
describe :LITERALMATCH do
60-
it "matches symbol literals" do
61-
expect(":symbol"[CodeObjects::LITERALMATCH]).to eq ":symbol"
62-
expect(":some_symbol"[CodeObjects::LITERALMATCH]).to eq ":some_symbol"
63-
expect("not_a_symbol"[CodeObjects::LITERALMATCH]).to be nil
64-
end
65-
66-
it "matches single-quoted string literals" do
67-
expect("'string'"[CodeObjects::LITERALMATCH]).to eq "'string'"
68-
expect("'some string with spaces'"[CodeObjects::LITERALMATCH]).to eq "'some string with spaces'"
69-
expect("not_quoted"[CodeObjects::LITERALMATCH]).to be nil
70-
end
71-
72-
it "matches double-quoted string literals" do
73-
expect('"string"'[CodeObjects::LITERALMATCH]).to eq '"string"'
74-
expect('"some string with spaces"'[CodeObjects::LITERALMATCH]).to eq '"some string with spaces"'
75-
expect("not_quoted"[CodeObjects::LITERALMATCH]).to be nil
76-
end
77-
end
78-
7959
describe :BUILTIN_EXCEPTIONS do
8060
it "includes all base exceptions" do
8161
bad_names = []

spec/tags/types_explainer_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ def parse_fail(types)
1717
expect { parse(types) }.to raise_error(SyntaxError)
1818
end
1919

20+
describe :LITERALMATCH do
21+
it "matches symbol literals" do
22+
expect(":symbol"[described_class::LITERALMATCH]).to eq ":symbol"
23+
expect(":some_symbol"[described_class::LITERALMATCH]).to eq ":some_symbol"
24+
expect("not_a_symbol"[described_class::LITERALMATCH]).to be nil
25+
end
26+
27+
it "matches single-quoted string literals" do
28+
expect("'string'"[described_class::LITERALMATCH]).to eq "'string'"
29+
expect("'some string with spaces'"[described_class::LITERALMATCH]).to eq "'some string with spaces'"
30+
expect("not_quoted"[described_class::LITERALMATCH]).to be nil
31+
end
32+
33+
it "matches double-quoted string literals" do
34+
expect('"string"'[described_class::LITERALMATCH]).to eq '"string"'
35+
expect('"some string with spaces"'[described_class::LITERALMATCH]).to eq '"some string with spaces"'
36+
expect("not_quoted"[described_class::LITERALMATCH]).to be nil
37+
end
38+
end
39+
2040
describe Type, '#to_s' do
2141
before { @t = Type.new(nil) }
2242

0 commit comments

Comments
 (0)