/
structural_parser_spec.rb
67 lines (58 loc) · 2.36 KB
/
structural_parser_spec.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
require_relative 'spec_helper'
describe Parsers::StructuralParser do
before do
@parser = Parsers::AnnotationParser.new
end
describe 'a simple, full structural constraint' do
it 'is parsed into a single constraint' do
'#write(String, Fixnum=) -> NilClass'.should parse_to(
Types::StructuralType.new('write',
[Types::ClassType.new('String', :covariant),
Types::ClassType.new('Fixnum', :invariant)],
Types::ClassType.new('NilClass', :covariant)))
end
it 'parses with an empty arg list' do
'#write() -> NilClass'.should parse_to(
Types::StructuralType.new('write',
[], Types::ClassType.new('NilClass', :covariant)))
end
end
describe 'a full structural constraint in Go-style' do
it 'is parsed into the equivalent constraint' do
'#write(String) NilClass'.should parse_to(
Types::StructuralType.new('write',
[Types::ClassType.new('String', :covariant)],
Types::ClassType.new('NilClass', :covariant)))
end
it 'parses with an empty arg list' do
'#write() NilClass'.should parse_to(
Types::StructuralType.new('write',
[], Types::ClassType.new('NilClass', :covariant)))
end
end
describe 'a structural constraint without a return type' do
it 'is parsed into a constraint with an empty return type constraint set' do
'#write(String, Fixnum=)'.should parse_to(
Types::StructuralType.new('write',
[Types::ClassType.new('String', :covariant),
Types::ClassType.new('Fixnum', :invariant)],
[]))
end
it 'parses with an empty arg list' do
'#write()'.should parse_to(
Types::StructuralType.new('write', [], []))
end
end
describe 'a structural constraint with an elided argument list' do
it 'is parsed into a constraint with an empty return type and argument constraint set' do
'#write->Fixnum-'.should parse_to(
Types::StructuralType.new('write', [],
Types::ClassType.new('Fixnum', :contravariant)))
end
end
describe 'a structural constraint with no arguments or return types specified' do
it 'is parsed into a constraint with an empty return type and argument constraint set' do
'#write'.should parse_to(Types::StructuralType.new('write', [], []))
end
end
end