template-ruby-parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.overcommit.yml +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +32 -0
- data/bin/code-parser +27 -0
- data/bin/format +3 -0
- data/bin/template-parser +27 -0
- data/docs/class.code +9 -0
- data/docs/meetup.code +14 -0
- data/docs/rain.code +23 -0
- data/docs/slack.code +17 -0
- data/docs/stripe.code +7 -0
- data/docs/twitter.code +7 -0
- data/lib/code/parser/addition.rb +13 -0
- data/lib/code/parser/and_operator.rb +13 -0
- data/lib/code/parser/bitwise_and.rb +13 -0
- data/lib/code/parser/bitwise_or.rb +13 -0
- data/lib/code/parser/boolean.rb +13 -0
- data/lib/code/parser/call.rb +174 -0
- data/lib/code/parser/chained_call.rb +41 -0
- data/lib/code/parser/class.rb +56 -0
- data/lib/code/parser/code.rb +20 -0
- data/lib/code/parser/comments.rb +46 -0
- data/lib/code/parser/dictionnary.rb +48 -0
- data/lib/code/parser/equal.rb +39 -0
- data/lib/code/parser/equality.rb +20 -0
- data/lib/code/parser/error/syntax_error.rb +36 -0
- data/lib/code/parser/error.rb +6 -0
- data/lib/code/parser/function.rb +109 -0
- data/lib/code/parser/greater_than.rb +13 -0
- data/lib/code/parser/group.rb +15 -0
- data/lib/code/parser/identifier.rb +54 -0
- data/lib/code/parser/if.rb +81 -0
- data/lib/code/parser/if_modifier.rb +39 -0
- data/lib/code/parser/list.rb +20 -0
- data/lib/code/parser/multiplication.rb +13 -0
- data/lib/code/parser/negation.rb +18 -0
- data/lib/code/parser/not_keyword.rb +24 -0
- data/lib/code/parser/nothing.rb +13 -0
- data/lib/code/parser/number.rb +39 -0
- data/lib/code/parser/operation.rb +44 -0
- data/lib/code/parser/or_keyword.rb +13 -0
- data/lib/code/parser/or_operator.rb +13 -0
- data/lib/code/parser/power.rb +33 -0
- data/lib/code/parser/range.rb +13 -0
- data/lib/code/parser/rescue.rb +38 -0
- data/lib/code/parser/shift.rb +13 -0
- data/lib/code/parser/statement.rb +9 -0
- data/lib/code/parser/string.rb +61 -0
- data/lib/code/parser/ternary.rb +73 -0
- data/lib/code/parser/unary_minus.rb +23 -0
- data/lib/code/parser/while.rb +36 -0
- data/lib/code/parser.rb +237 -0
- data/lib/code-ruby-parser.rb +7 -0
- data/lib/code.rb +2 -0
- data/lib/template/parser.rb +32 -0
- data/lib/template-ruby-parser.rb +7 -0
- data/lib/template.rb +2 -0
- data/spec/code/parser/addition_spec.rb +26 -0
- data/spec/code/parser/and_operator_spec.rb +26 -0
- data/spec/code/parser/bitwise_and_spec.rb +26 -0
- data/spec/code/parser/bitwise_or_spec.rb +26 -0
- data/spec/code/parser/boolean_spec.rb +13 -0
- data/spec/code/parser/call_spec.rb +52 -0
- data/spec/code/parser/chained_call_spec.rb +33 -0
- data/spec/code/parser/class_spec.rb +32 -0
- data/spec/code/parser/code_spec.rb +13 -0
- data/spec/code/parser/dictionnary_spec.rb +40 -0
- data/spec/code/parser/equal_spec.rb +42 -0
- data/spec/code/parser/equality_spec.rb +26 -0
- data/spec/code/parser/function_spec.rb +43 -0
- data/spec/code/parser/greater_than_spec.rb +26 -0
- data/spec/code/parser/group_spec.rb +13 -0
- data/spec/code/parser/if_modifier_spec.rb +26 -0
- data/spec/code/parser/if_spec.rb +39 -0
- data/spec/code/parser/list_spec.rb +27 -0
- data/spec/code/parser/multiplication_spec.rb +26 -0
- data/spec/code/parser/negation_spec.rb +13 -0
- data/spec/code/parser/not_keyword_spec.rb +21 -0
- data/spec/code/parser/nothing_spec.rb +20 -0
- data/spec/code/parser/number_spec.rb +24 -0
- data/spec/code/parser/or_keyword_spec.rb +26 -0
- data/spec/code/parser/or_operator_spec.rb +26 -0
- data/spec/code/parser/power_spec.rb +21 -0
- data/spec/code/parser/range_spec.rb +21 -0
- data/spec/code/parser/rescue_spec.rb +26 -0
- data/spec/code/parser/shift_spec.rb +26 -0
- data/spec/code/parser/string_spec.rb +27 -0
- data/spec/code/parser/ternary_spec.rb +26 -0
- data/spec/code/parser/unary_minus_spec.rb +21 -0
- data/spec/code/parser/while_spec.rb +32 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/template/parser_spec.rb +13 -0
- data/template-ruby-parser.gemspec +16 -0
- metadata +171 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"a",
|
8
|
+
"admin?",
|
9
|
+
"update!",
|
10
|
+
"*args",
|
11
|
+
"**kargs",
|
12
|
+
"&block",
|
13
|
+
"update!(user)",
|
14
|
+
"puts(1)",
|
15
|
+
"print(1)",
|
16
|
+
"defined?(a)",
|
17
|
+
"each{}",
|
18
|
+
"each do end",
|
19
|
+
"render(a, *b, **c, &d) { |e, *f, **g, &h| puts(e) }",
|
20
|
+
"&render {}"
|
21
|
+
].each do |input|
|
22
|
+
context input do
|
23
|
+
let!(:input) { input }
|
24
|
+
|
25
|
+
it { expect { subject }.to_not raise_error }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
[
|
30
|
+
"update! /* cool */ { }",
|
31
|
+
"each{/* cool */}",
|
32
|
+
"render(/* cool */ a)",
|
33
|
+
"render(a /* cool */)",
|
34
|
+
"render(a, /* cool */ b)",
|
35
|
+
"render(a, b /* cool */)",
|
36
|
+
"render(/* cool */ a: 1)",
|
37
|
+
"render(a: 1 /* cool */)",
|
38
|
+
"render(a: 1, /* cool */ b: 2)",
|
39
|
+
"render(a: 1, b: 2 /* cool */)",
|
40
|
+
"render { /* cool */ |a, b| }",
|
41
|
+
"render { |/* cool */ a, b| }",
|
42
|
+
"render { |a /* cool */, b| }",
|
43
|
+
"render { |a: 1, /* cool */ b: 2| }",
|
44
|
+
"render { |a: 1, b: 2 /* cool */| }"
|
45
|
+
].each do |input|
|
46
|
+
context input do
|
47
|
+
let!(:input) { input }
|
48
|
+
|
49
|
+
it { expect(subject.to_json).to include("cool") }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"a.b",
|
8
|
+
"a.b.c",
|
9
|
+
"a(1).b.c(2)",
|
10
|
+
"user.first_name",
|
11
|
+
"User.all",
|
12
|
+
"User::Email.first",
|
13
|
+
"User.each do |user| user.update(created_at: Time.now) end"
|
14
|
+
].each do |input|
|
15
|
+
context input do
|
16
|
+
let!(:input) { input }
|
17
|
+
|
18
|
+
it { expect { subject }.to_not raise_error }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
[
|
23
|
+
"a /* cool */ . b",
|
24
|
+
"a . /* cool */ b",
|
25
|
+
"a . # cool\n /* cool */ b"
|
26
|
+
].each do |input|
|
27
|
+
context input do
|
28
|
+
let!(:input) { input }
|
29
|
+
|
30
|
+
it { expect(subject.to_json).to include("cool") }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"class A",
|
8
|
+
"class A self.b = 1",
|
9
|
+
"class A < B",
|
10
|
+
"class A end",
|
11
|
+
"class A self.b = 1 end",
|
12
|
+
"class A < B end"
|
13
|
+
].each do |input|
|
14
|
+
context input do
|
15
|
+
let!(:input) { input }
|
16
|
+
|
17
|
+
it { expect { subject }.to_not raise_error }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
[
|
22
|
+
"class /* cool */ A",
|
23
|
+
"class A /* cool */ < B",
|
24
|
+
"class A </* cool */ B"
|
25
|
+
].each do |input|
|
26
|
+
context input do
|
27
|
+
let!(:input) { input }
|
28
|
+
|
29
|
+
it { expect(subject.to_json).to include("cool") }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["nothing", "nothing null nil"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"{}",
|
8
|
+
"{a:1}",
|
9
|
+
"{ a: 1 }",
|
10
|
+
"{ :a => 1 }",
|
11
|
+
"{ :a => 1, b: 2 }",
|
12
|
+
"{ :a => 1, b: { c: 2 } }"
|
13
|
+
].each do |input|
|
14
|
+
context input do
|
15
|
+
let!(:input) { input }
|
16
|
+
|
17
|
+
it { expect { subject }.to_not raise_error }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
[
|
22
|
+
"{ /* cool */ }",
|
23
|
+
"{ a /* cool */ : 1",
|
24
|
+
"{ a /* cool */ => 1",
|
25
|
+
"{ a: 1 /* cool */ }",
|
26
|
+
"{ a: 1, /* cool */ b: 2 }",
|
27
|
+
"{ a: 1, b /* cool */ : 2 }",
|
28
|
+
"{ a: 1, b /* cool */ => 2 }",
|
29
|
+
"{ a: 1, b => /* cool */ 2 }",
|
30
|
+
"{ a: 1, b => 2 /* cool */ }",
|
31
|
+
"{ /* cool */ **kargs }",
|
32
|
+
"{ **kargs /* cool */ }"
|
33
|
+
].each do |input|
|
34
|
+
context input do
|
35
|
+
let!(:input) { input }
|
36
|
+
|
37
|
+
it { expect(subject.to_json).to include("cool") }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"a = 1",
|
8
|
+
"a += 1",
|
9
|
+
"a -= 1",
|
10
|
+
"a *= 1",
|
11
|
+
"a /= 1",
|
12
|
+
"a <<= 1",
|
13
|
+
"a >>= 1",
|
14
|
+
"a &= 1",
|
15
|
+
"a |= 1",
|
16
|
+
"a ^= 1",
|
17
|
+
"a %= 1",
|
18
|
+
"a ||= 1",
|
19
|
+
"a &&= 1",
|
20
|
+
"a = b = 1",
|
21
|
+
"a = b += c"
|
22
|
+
].each do |input|
|
23
|
+
context input do
|
24
|
+
let!(:input) { input }
|
25
|
+
|
26
|
+
it { expect { subject }.to_not raise_error }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
[
|
31
|
+
"a /* cool */ = 1",
|
32
|
+
"a += /* cool */ 1",
|
33
|
+
"a = b -= /* cool */ 1",
|
34
|
+
"a = b /* cool */ *= 1"
|
35
|
+
].each do |input|
|
36
|
+
context input do
|
37
|
+
let!(:input) { input }
|
38
|
+
|
39
|
+
it { expect(subject.to_json).to include("cool") }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a == b", "a != b", "a > 1 == true", "a == b == c"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ == b",
|
16
|
+
"a == /* cool */ b",
|
17
|
+
"a == b /* cool */ == c",
|
18
|
+
"a == b == /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"()=>{}",
|
8
|
+
"() => {}",
|
9
|
+
"(a, b) => { add(a, b) }",
|
10
|
+
"(a, b = 1, c:, d: 2, *e, **f) => { }",
|
11
|
+
"(a?, b! = 1, c?:, d?: 2, *e?, *f!, **g?, **h!) => { }"
|
12
|
+
].each do |input|
|
13
|
+
context input do
|
14
|
+
let!(:input) { input }
|
15
|
+
|
16
|
+
it { expect { subject }.to_not raise_error }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
[
|
21
|
+
"(/* cool */)=>{}",
|
22
|
+
"(/* cool */ a)=>{}",
|
23
|
+
"(/* cool */ a:)=>{}",
|
24
|
+
"(a /* cool */ )=>{}",
|
25
|
+
"(a /* cool */ :)=>{}",
|
26
|
+
"(a /* cool */ => 1)=>{}",
|
27
|
+
"(a = /* cool */ 1)=>{}",
|
28
|
+
"(a = 1 /* cool */)=>{}",
|
29
|
+
"(a, /* cool */ b)=>{}",
|
30
|
+
"(a, b /* cool */)=>{}",
|
31
|
+
"(a, b /* cool */ = 1)=>{}",
|
32
|
+
"(a, b: /* cool */)=>{}",
|
33
|
+
"() /* cool */ => {}",
|
34
|
+
"() => /* cool */ {}",
|
35
|
+
"() => { /* cool */ }"
|
36
|
+
].each do |input|
|
37
|
+
context input do
|
38
|
+
let!(:input) { input }
|
39
|
+
|
40
|
+
it { expect(subject.to_json).to include("cool") }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a > b", "a > b > c", "a < b", "a >= b", "a <= b"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ > b",
|
16
|
+
"a < /* cool */ b",
|
17
|
+
"a > b < c /* cool */",
|
18
|
+
"a < b > /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["()", "(true nothing)", "(true (nothing))"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a if b", "a if b if c", "a unless b"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ if b",
|
16
|
+
"a if /* cool */ b",
|
17
|
+
"a if b if c /* cool */",
|
18
|
+
"a unless b if /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"if b",
|
8
|
+
"if a b",
|
9
|
+
"if a end",
|
10
|
+
"if b a end",
|
11
|
+
"if a b else c",
|
12
|
+
"if a b elsif c d else e",
|
13
|
+
"if a b else if c d",
|
14
|
+
"if a b else unless c d"
|
15
|
+
].each do |input|
|
16
|
+
context input do
|
17
|
+
let!(:input) { input }
|
18
|
+
|
19
|
+
it { expect { subject }.to_not raise_error }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
[
|
24
|
+
"if /* cool */ a",
|
25
|
+
"if a /* cool */ b",
|
26
|
+
"if a b /* cool */ else c",
|
27
|
+
"if a b else /* cool */ c",
|
28
|
+
"if a b elsif /* cool */ c d else e",
|
29
|
+
"if a b else /* cool */ if c d",
|
30
|
+
"if a b else if /* cool */ c d",
|
31
|
+
"if a b else unless /* cool */ c d"
|
32
|
+
].each do |input|
|
33
|
+
context input do
|
34
|
+
let!(:input) { input }
|
35
|
+
|
36
|
+
it { expect(subject.to_json).to include("cool") }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["[]", "[1]", "[1,2]", "[1,[true]]"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"[ /* cool */ ]",
|
16
|
+
"[ /* cool */ 1 ]",
|
17
|
+
"[ 1 /* cool */ ]",
|
18
|
+
"[ 1, /* cool */ 2 ]",
|
19
|
+
"[ 1, 2 /* cool */ ]"
|
20
|
+
].each do |input|
|
21
|
+
context input do
|
22
|
+
let!(:input) { input }
|
23
|
+
|
24
|
+
it { expect(subject.to_json).to include("cool") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a * b", "a / b", "(a / b) / c", "a / (b / c)"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ * b",
|
16
|
+
"a * /* cool */ b",
|
17
|
+
"a * b * c /* cool */",
|
18
|
+
"a * b * /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["not a", "not not a"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
["not /* cool */ a", "not not /* cool */ a"].each do |input|
|
15
|
+
context input do
|
16
|
+
let!(:input) { input }
|
17
|
+
|
18
|
+
it { expect(subject.to_json).to include("cool") }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
[
|
7
|
+
"nothing",
|
8
|
+
"null",
|
9
|
+
"nil",
|
10
|
+
" nothing",
|
11
|
+
" \n null ",
|
12
|
+
"nil \n "
|
13
|
+
].each do |input|
|
14
|
+
context input do
|
15
|
+
let!(:input) { input }
|
16
|
+
|
17
|
+
it { expect { subject }.to_not raise_error }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
%w[
|
7
|
+
1
|
8
|
+
100
|
9
|
+
0
|
10
|
+
1_000
|
11
|
+
1.34
|
12
|
+
1_000.300_400
|
13
|
+
0x10
|
14
|
+
0o10
|
15
|
+
0b10
|
16
|
+
0b1_0000_0000
|
17
|
+
].each do |input|
|
18
|
+
context input do
|
19
|
+
let!(:input) { input }
|
20
|
+
|
21
|
+
it { expect { subject }.to_not raise_error }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a or b", "a and b", "a or b or c", "a and b and c"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ and b",
|
16
|
+
"a and /* cool */ b",
|
17
|
+
"a or b or c /* cool */",
|
18
|
+
"a or b or /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a || b", "a || b || c"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ || b",
|
16
|
+
"a || /* cool */ b",
|
17
|
+
"a || b || c /* cool */",
|
18
|
+
"a || b || /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a ** b", "a ** b ** c ** d"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
["1 /* cool */ ** 2", "1 ** /* cool */ 2"].each do |input|
|
15
|
+
context input do
|
16
|
+
let!(:input) { input }
|
17
|
+
|
18
|
+
it { expect(subject.to_json).to include("cool") }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a..b"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
["a /* cool */ .. b", "a .. /* cool */ b"].each do |input|
|
15
|
+
context input do
|
16
|
+
let!(:input) { input }
|
17
|
+
|
18
|
+
it { expect(subject.to_json).to include("cool") }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["0/0 rescue a", "0/0 rescue 0/0 rescue 'nope'"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ rescue b",
|
16
|
+
"a rescue /* cool */ b",
|
17
|
+
"a rescue b /* cool */ rescue c",
|
18
|
+
"a rescue b eescue /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::Code::Parser do
|
4
|
+
subject { ::Code::Parser.parse(input) }
|
5
|
+
|
6
|
+
["a << b", "a >> b", "(a << b) >> c", "a << (b >> c)"].each do |input|
|
7
|
+
context input do
|
8
|
+
let!(:input) { input }
|
9
|
+
|
10
|
+
it { expect { subject }.to_not raise_error }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
[
|
15
|
+
"a /* cool */ << b",
|
16
|
+
"a >> /* cool */ b",
|
17
|
+
"a << b >> c /* cool */",
|
18
|
+
"a >> b << /* cool */ c"
|
19
|
+
].each do |input|
|
20
|
+
context input do
|
21
|
+
let!(:input) { input }
|
22
|
+
|
23
|
+
it { expect(subject.to_json).to include("cool") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|