forked from whitequark/parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_parser.rb
122 lines (105 loc) · 2.7 KB
/
test_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# encoding: utf-8
# frozen_string_literal: true
require 'helper'
require 'parse_helper'
Parser::Builders::Default.modernize
class TestParser < Minitest::Test
include ParseHelper
def parser_for_ruby_version(version)
parser = super
parser.diagnostics.all_errors_are_fatal = true
%w(foo bar baz).each do |metasyntactic_var|
parser.static_env.declare(metasyntactic_var)
end
parser
end
SINCE_NEXT = %w(next)
def test_meth_ref__27
assert_parses(
s(:meth_ref, s(:lvar, :foo), :bar),
%q{foo.:bar},
%q{ ^^ dot
| ~~~ selector
|~~~~~~~~ expression},
SINCE_NEXT)
assert_parses(
s(:meth_ref, s(:lvar, :foo), :+@),
%q{foo.:+@},
%q{ ^^ dot
| ~~ selector
|~~~~~~~ expression},
SINCE_NEXT)
end
def test_meth_ref__before_27
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tCOLON' }],
%q{foo.:bar},
%q{ ^ location },
ALL_VERSIONS - SINCE_NEXT)
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tCOLON' }],
%q{foo.:+@},
%q{ ^ location },
ALL_VERSIONS - SINCE_NEXT)
end
def test_meth_ref_unsupported_newlines
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tCOLON' }],
%Q{foo. :+},
%q{ ^ location},
SINCE_NEXT)
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tCOLON' }],
%Q{foo.: +},
%q{ ^ location},
SINCE_NEXT)
end
def test_endless_method
assert_parses(
s(:def_e, :foo,
s(:args),
s(:int, 42)),
%q{def foo = 42},
%q{~~~ keyword
| ~~~ name
| ^ assignment
|~~~~~~~~~~~~ expression},
SINCE_NEXT)
assert_parses(
s(:def_e, :inc,
s(:args, s(:arg, :x)),
s(:send,
s(:lvar, :x), :+,
s(:int, 1))),
%q{def inc(x) = x + 1},
%q{~~~ keyword
| ~~~ name
| ^ assignment
|~~~~~~~~~~~~~~~~~~ expression},
SINCE_NEXT)
assert_parses(
s(:defs_e, s(:send, nil, :obj), :foo,
s(:args),
s(:int, 42)),
%q{def obj.foo = 42},
%q{~~~ keyword
| ^ operator
| ~~~ name
| ^ assignment
|~~~~~~~~~~~~~~~~ expression},
SINCE_NEXT)
assert_parses(
s(:defs_e, s(:send, nil, :obj), :inc,
s(:args, s(:arg, :x)),
s(:send,
s(:lvar, :x), :+,
s(:int, 1))),
%q{def obj.inc(x) = x + 1},
%q{~~~ keyword
| ~~~ name
| ^ operator
| ^ assignment
|~~~~~~~~~~~~~~~~~~~~~~ expression},
SINCE_NEXT)
end
end