talk 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +6 -0
- data/Gemfile +10 -0
- data/README.md +6 -0
- data/Rakefile +9 -0
- data/features/class-field.feature +226 -0
- data/features/class.feature +95 -0
- data/features/enumeration-constant.feature +76 -0
- data/features/enumeration.feature +35 -0
- data/features/glossary-term.feature +46 -0
- data/features/glossary.feature +35 -0
- data/features/step_definitions/class-field.rb +74 -0
- data/features/step_definitions/class.rb +50 -0
- data/features/step_definitions/enumeration-constant.rb +42 -0
- data/features/step_definitions/enumeration.rb +29 -0
- data/features/step_definitions/glossary-term.rb +31 -0
- data/features/step_definitions/glossary.rb +23 -0
- data/features/support/env.rb +261 -0
- data/lib/context.rb +282 -0
- data/lib/context_class.rb +224 -0
- data/lib/contexts/README.md +274 -0
- data/lib/contexts/base.rb +6 -0
- data/lib/contexts/boolean.rb +5 -0
- data/lib/contexts/class.rb +11 -0
- data/lib/contexts/constant.rb +5 -0
- data/lib/contexts/enumeration.rb +20 -0
- data/lib/contexts/field.rb +47 -0
- data/lib/contexts/glossary.rb +7 -0
- data/lib/contexts/inherits.rb +3 -0
- data/lib/contexts/map.rb +7 -0
- data/lib/contexts/meta.rb +2 -0
- data/lib/contexts/method.rb +15 -0
- data/lib/contexts/numeric.rb +5 -0
- data/lib/contexts/protocol.rb +8 -0
- data/lib/contexts/reference.rb +6 -0
- data/lib/contexts/string.rb +5 -0
- data/lib/contexts/target.rb +11 -0
- data/lib/contexts/term.rb +11 -0
- data/lib/languages/java/java.rb +145 -0
- data/lib/languages/java/templates/class.java.erb +22 -0
- data/lib/languages/java/templates/enumeration.java.erb +10 -0
- data/lib/languages/java/templates/glossary.java.erb +8 -0
- data/lib/languages/language.rb +172 -0
- data/lib/languages/objc/objc.rb +162 -0
- data/lib/languages/objc/templates/TalkClasses.h.erb +3 -0
- data/lib/languages/objc/templates/TalkClassesForward.h.erb +2 -0
- data/lib/languages/objc/templates/TalkConstants.h.erb +22 -0
- data/lib/languages/objc/templates/TalkObjectList.h.erb +4 -0
- data/lib/languages/objc/templates/class.h.erb +21 -0
- data/lib/languages/objc/templates/class.m.erb +43 -0
- data/lib/parse_error.rb +4 -0
- data/lib/parser.rb +119 -0
- data/lib/registry.rb +151 -0
- data/lib/talk.rb +5 -0
- data/talk.gemspec +18 -0
- metadata +71 -3
@@ -0,0 +1,35 @@
|
|
1
|
+
Feature: @enumeration
|
2
|
+
Scenario Outline: Define an @enumeration with explicit @description
|
3
|
+
Given I define an enumeration named <name> with description <description>
|
4
|
+
When I get the result hash
|
5
|
+
Then there should be an enumeration named <name>
|
6
|
+
And the enumeration named <name> should have description <description>
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
| name | description |
|
10
|
+
| AnEnumeration | This is a test enum |
|
11
|
+
| AnotherEnumeration | Here is another one! |
|
12
|
+
|
13
|
+
|
14
|
+
Scenario Outline: Define an @enumeration with implicit description
|
15
|
+
Given I define an enumeration named <name> with implicit description <description>
|
16
|
+
When I get the result hash
|
17
|
+
Then there should be an enumeration named <name>
|
18
|
+
And the enumeration named <name> should have description <description>
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
| name | description |
|
22
|
+
| AnEnumeration | This is a test enum |
|
23
|
+
| AnotherEnumeration | Here is another one! |
|
24
|
+
|
25
|
+
Scenario: Define an @enumeration with no description
|
26
|
+
Given I define an enumeration named SomeEnumeration
|
27
|
+
But I don't give it a description
|
28
|
+
When I get the result hash
|
29
|
+
Then there should be a parse error
|
30
|
+
|
31
|
+
Scenario: Define an @enumeration with no name
|
32
|
+
Given I define an enumeration
|
33
|
+
But I don't give it a name
|
34
|
+
When I get the result hash
|
35
|
+
Then there should be a parse error
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: @glossary -> @term
|
2
|
+
Scenario Outline: Define an @term with an explicit @description
|
3
|
+
Given I have defined a valid glossary named <glossary>
|
4
|
+
And I define a term named <term> with value <value> and description <description>
|
5
|
+
When I get the result hash
|
6
|
+
Then the glossary <glossary> should contain a term named <term>
|
7
|
+
And the term <term> of glossary <glossary> should have value <value>
|
8
|
+
And the term <term> of glossary <glossary> should have description <description>
|
9
|
+
|
10
|
+
Examples:
|
11
|
+
| glossary | term | value | description |
|
12
|
+
| SomeGlossary | SomeTerm | SomeValue | I am a description |
|
13
|
+
| AnotherGlossary | AnotherTerm | AValue | I am a silly description with a silly hat |
|
14
|
+
|
15
|
+
Scenario Outline: Define an @term with no description
|
16
|
+
Given I have defined a valid glossary named TestGlossary
|
17
|
+
And I define a term named <name> with value <value>
|
18
|
+
But I don't give it a description
|
19
|
+
When I get the result hash
|
20
|
+
Then the glossary TestGlossary should contain a term named <name>
|
21
|
+
And the term <name> of glossary TestGlossary should have value <value>
|
22
|
+
|
23
|
+
Examples:
|
24
|
+
| name | value |
|
25
|
+
| ATerm | AValue |
|
26
|
+
| AnotherTerm | AnotherValue |
|
27
|
+
|
28
|
+
Scenario: Define an @term with no name
|
29
|
+
Given I have defined a valid glossary
|
30
|
+
And I define a term
|
31
|
+
But I don't give it a name
|
32
|
+
When I get the result hash
|
33
|
+
Then there should be a parse error
|
34
|
+
|
35
|
+
Scenario Outline: Define an @term with no value
|
36
|
+
Given I have defined a valid glossary named TestGlossary
|
37
|
+
And I define a term named <name>
|
38
|
+
But I don't give it a name
|
39
|
+
When I get the result hash
|
40
|
+
Then the glossary TestGlossary should contain a term named <name>
|
41
|
+
And the term <name> of glossary TestGlossary should have value <name>
|
42
|
+
|
43
|
+
Examples:
|
44
|
+
| name |
|
45
|
+
| ATerm |
|
46
|
+
| AnotherTerm |
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Feature: @glossary
|
2
|
+
Scenario Outline: Define an @glossary with an explicit @description
|
3
|
+
Given I define a glossary named <name> with description <description>
|
4
|
+
When I get the result hash
|
5
|
+
Then there should be a glossary named <name>
|
6
|
+
And the glossary named <name> should have description <description>
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
| name | description |
|
10
|
+
| AGlossary | A test glossary |
|
11
|
+
| AnotherGlossary | More testing please |
|
12
|
+
|
13
|
+
Scenario Outline: Define an @glossary with an implicit description
|
14
|
+
Given I define a glossary named <name> with implicit description <description>
|
15
|
+
When I get the result hash
|
16
|
+
Then there should be a glossary named <name>
|
17
|
+
And the glossary named <name> should have description <description>
|
18
|
+
|
19
|
+
Examples:
|
20
|
+
| name | description |
|
21
|
+
| AGlossary | A test glossary |
|
22
|
+
| AnotherGlossary | More testing please |
|
23
|
+
|
24
|
+
Scenario: Define an @glossary with no description
|
25
|
+
Given I define a glossary named SomeGlossary
|
26
|
+
But I don't give it a description
|
27
|
+
When I get the result hash
|
28
|
+
Then there should be a parse error
|
29
|
+
|
30
|
+
Scenario: Define an @glossary with no name
|
31
|
+
Given I define a glossary
|
32
|
+
But I don't give it a name
|
33
|
+
When I get the result hash
|
34
|
+
Then there should be a parse error
|
35
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Given(/^I give it a field named (\S+) of type (\S+) and description (.+)$/) do |name, type, description|
|
2
|
+
last_class.add_child(make_field(name, type).add_child(make_description(description)))
|
3
|
+
end
|
4
|
+
|
5
|
+
Then(/^the field (\S+) should have type (\S+) and description (.+)$/) do |name, type, description|
|
6
|
+
field = field_in_result_class("SomeClass", name)
|
7
|
+
expect(field).not_to be_nil
|
8
|
+
expect(field[:description]).to eq(description)
|
9
|
+
expect(field[:type].length).to eq(1)
|
10
|
+
expect(field[:type][0]).to eq(type)
|
11
|
+
end
|
12
|
+
|
13
|
+
Given(/^I give it a field named (\S+) of type (\S+) and implicit description (.+)$/) do |name, type, description|
|
14
|
+
last_class.add_child(make_field(name, type, description))
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^I give it a valid field named (\S+) of type (\S+)$/) do |name, type|
|
18
|
+
last_class.add_child(make_field(name, type, "A description"))
|
19
|
+
end
|
20
|
+
|
21
|
+
Then(/^the field (\S+) should have type (\S+)$/) do |name, type|
|
22
|
+
field = field_in_result_class(last_class.words[0], name)
|
23
|
+
expect(field).not_to be_nil
|
24
|
+
expect(field[:type].length).to eq(1)
|
25
|
+
expect(field[:type][0]).to eq(type)
|
26
|
+
end
|
27
|
+
|
28
|
+
Given(/^I give it a valid field named (\S+)$/) do |name|
|
29
|
+
last_class.add_child(make_field(name, "uint32", "A description"))
|
30
|
+
end
|
31
|
+
|
32
|
+
Given(/^I give (\S+) @see (\S+) (\S+)$/) do |field_name, ref_type, ref_name|
|
33
|
+
last_class.find_child("@field", field_name, 1).add_child(make_see(ref_type, ref_name))
|
34
|
+
end
|
35
|
+
|
36
|
+
Then(/^the field (\S+) should have an @see (\S+) (\S+)$/) do |field_name, ref_type, ref_name|
|
37
|
+
ref_type = "enumeration" if(ref_type) == "enum"
|
38
|
+
result_field = field_in_result_class(last_class.words[0], field_name)
|
39
|
+
expect(result_field[:see]).not_to be_nil
|
40
|
+
|
41
|
+
matches = result_field[:see].select { |x| x[:type] == ref_type and x[:name] == ref_name }
|
42
|
+
expect(matches.length).to eq(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
Given(/^I give (\S+) @caveat (.+)$/) do |field_name, caveat_text|
|
46
|
+
caveat = TalkTag.new("@caveat").add_data(caveat_text)
|
47
|
+
last_class.find_child("@field", field_name, 1).add_child(caveat)
|
48
|
+
end
|
49
|
+
|
50
|
+
Then(/^the field (\S+) should have a @caveat (.+)$/) do |field_name, caveat_text|
|
51
|
+
field = field_in_result_class("SomeClass", field_name)
|
52
|
+
expect(field[:caveat]).to include(caveat_text)
|
53
|
+
end
|
54
|
+
|
55
|
+
Given(/^I give (\S+) @deprecated (.+)$/) do |field_name, deprecation_text|
|
56
|
+
deprecated = TalkTag.new("@deprecated").add_data(deprecation_text)
|
57
|
+
last_class.find_child("@field", field_name, 1).add_child(deprecated)
|
58
|
+
end
|
59
|
+
|
60
|
+
Then(/^the field (\S+) should have @deprecated (.+)$/) do |field_name, deprecation_text|
|
61
|
+
field = field_in_result_class("SomeClass", field_name)
|
62
|
+
expect(field[:deprecated]).to eq(deprecation_text)
|
63
|
+
end
|
64
|
+
|
65
|
+
Given(/^I give (\S+) @version (.+)$/) do |field_name, version_string|
|
66
|
+
version = TalkTag.new("@version").add_data(version_string)
|
67
|
+
last_class.find_child("@field", field_name, 1).add_child(version)
|
68
|
+
end
|
69
|
+
|
70
|
+
Then(/^the field (\S+) should have @version (.+)$/) do |field_name, version_string|
|
71
|
+
field = field_in_result_class("SomeClass", field_name)
|
72
|
+
expect(field[:version]).to eq(version_string)
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Given(/^I have defined a class named (.+)$/) do |class_name|
|
2
|
+
make_class(class_name)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I have given (.+) as a @description$/) do |description|
|
6
|
+
last_class.add_child(make_description(description))
|
7
|
+
end
|
8
|
+
|
9
|
+
Then(/^there should be a class named (.+)$/) do |class_name|
|
10
|
+
expect(result_class(class_name)).not_to be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
Then(/^it should have description (.+)$/) do |description|
|
14
|
+
expect(result_class(last_class)[:description]).to eq(description)
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^I have given (.+) as an implied description$/) do |description|
|
18
|
+
last_class.add_data(description)
|
19
|
+
end
|
20
|
+
|
21
|
+
Given(/^I don't give a description$/) do
|
22
|
+
end
|
23
|
+
|
24
|
+
Given(/^I define another class also named (.+)$/) do |class_name|
|
25
|
+
make_class(class_name).add_data("A description")
|
26
|
+
end
|
27
|
+
|
28
|
+
Given(/^I give it @inherits (.+)$/) do |base_class|
|
29
|
+
last_class.add_child(TalkTag.new("@inherits").add_data(base_class))
|
30
|
+
end
|
31
|
+
|
32
|
+
Then(/^the class (.+) should have @inherits (.+)$/) do |child_class, base_class|
|
33
|
+
expect(result_class(child_class)[:inherits]).to eq(base_class)
|
34
|
+
end
|
35
|
+
|
36
|
+
Given(/^I give it @implement (.+)$/) do |is_implemented|
|
37
|
+
last_class.add_child(TalkTag.new("@implement").add_data(is_implemented))
|
38
|
+
end
|
39
|
+
|
40
|
+
Then(/^the class (.+) should have @implement (.+)$/) do |class_name, is_implemented|
|
41
|
+
implemented = case is_implemented
|
42
|
+
when 'false'
|
43
|
+
false
|
44
|
+
when 'true'
|
45
|
+
true
|
46
|
+
else
|
47
|
+
'wtf'
|
48
|
+
end
|
49
|
+
expect(result_class(class_name)[:implement]).to eq(implemented)
|
50
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Given(/^I define a valid constant named (\S+)$/) do |constant_name|
|
2
|
+
@enumerations.last.add_child(make_constant(constant_name))
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I define a valid constant named (\S+) with value (.+)$/) do |constant_name, value|
|
6
|
+
@enumerations.last.add_child(make_constant(constant_name, value))
|
7
|
+
end
|
8
|
+
|
9
|
+
Given(/^I define a constant named (\S+) with value (\S+) and description (.+)$/) do |constant_name, value, description_text|
|
10
|
+
@enumerations.last.add_child(make_constant(constant_name, value).add_child(make_description(description_text)))
|
11
|
+
end
|
12
|
+
|
13
|
+
Given(/^I define a constant named (\S+) with value (\S+) and implicit description (.+)$/) do |constant_name, value, description_text|
|
14
|
+
@enumerations.last.add_child(make_constant(constant_name, value, description_text))
|
15
|
+
end
|
16
|
+
|
17
|
+
Then(/^the enumeration (\S+) should contain a constant named (\S+)$/) do |enumeration_name, constant_name|
|
18
|
+
enum = result_enumeration(enumeration_name)
|
19
|
+
expect(enum).not_to be_nil
|
20
|
+
|
21
|
+
constant = constant_in_result_enumeration(enum, constant_name)
|
22
|
+
expect(constant).not_to be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
Then(/^the constant (\S+) should have value (.+)$/) do |constant_name, value|
|
26
|
+
enum = result_enumeration(@enumerations.last)
|
27
|
+
constant = constant_in_result_enumeration(enum, constant_name)
|
28
|
+
expect(constant[:value]).to eq(value.to_f)
|
29
|
+
end
|
30
|
+
|
31
|
+
Then(/^the constant (\S+) of enumeration (\S+) should have value (\S+)$/) do |constant_name, enumeration_name, value|
|
32
|
+
enum = result_enumeration(enumeration_name)
|
33
|
+
constant = constant_in_result_enumeration(enum, constant_name)
|
34
|
+
expect(constant[:value]).to eq(value.to_f)
|
35
|
+
end
|
36
|
+
|
37
|
+
Then(/^the constant (\S+) of enumeration (\S+) should have description (.+)$/) do |constant_name, enumeration_name, description_text|
|
38
|
+
enum = result_enumeration(@enumerations.last)
|
39
|
+
constant = constant_in_result_enumeration(enum, constant_name)
|
40
|
+
expect(constant[:description]).to eq(description_text)
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Given(/^I define an enumeration named (\S+) with description (.+)$/) do |enum_name, description_text|
|
2
|
+
make_enumeration(enum_name).add_child(make_description(description_text))
|
3
|
+
end
|
4
|
+
|
5
|
+
Then(/^there should be an enumeration named (\S+)$/) do |enum_name|
|
6
|
+
expect(result_enumeration(enum_name)).not_to be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
Then(/^the enumeration named (\S+) should have description (.+)$/) do |enum_name, description_text|
|
10
|
+
expect(result_enumeration(enum_name)[:description]).to eq(description_text)
|
11
|
+
end
|
12
|
+
|
13
|
+
Given(/^I define an enumeration named (\S+) with implicit description (.+)$/) do |enum_name, description_text|
|
14
|
+
make_enumeration(enum_name).add_data(description_text)
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^I define an enumeration$/) do
|
18
|
+
make_enumeration
|
19
|
+
end
|
20
|
+
|
21
|
+
Given(/^I define an enumeration named (\S+)$/) do |enum_name|
|
22
|
+
make_enumeration(enum_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
Given(/^I don't give it a description$/) do
|
26
|
+
end
|
27
|
+
|
28
|
+
Given(/^I don't give it a name$/) do
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Given(/^I define a term$/) do
|
2
|
+
@glossaries.last.add_child(make_term)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I define a term named (\S+)$/) do |term_name|
|
6
|
+
@glossaries.last.add_child(make_term(term_name))
|
7
|
+
end
|
8
|
+
|
9
|
+
Given(/^I define a term named (\S+) with value (\S+)$/) do |term_name, value|
|
10
|
+
term = make_term(term_name, value)
|
11
|
+
@glossaries.last.add_child(term)
|
12
|
+
end
|
13
|
+
|
14
|
+
Given(/^I define a term named (\S+) with value (\S+) and description (.+)$/) do |term_name, value, description_text|
|
15
|
+
@glossaries.last.add_child(make_term(term_name, value, description_text))
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^the glossary (\S+) should contain a term named (\S+)$/) do |glossary_name, term_name|
|
19
|
+
term = term_in_result_glossary(result_glossary(glossary_name), term_name)
|
20
|
+
expect(term).not_to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^the term (\S+) of glossary (\S+) should have value (\S+)$/) do |term_name, glossary_name, value|
|
24
|
+
term = term_in_result_glossary(result_glossary(glossary_name), term_name)
|
25
|
+
expect(term[:value]).to eq(value)
|
26
|
+
end
|
27
|
+
|
28
|
+
Then(/^the term (\S+) of glossary (\S+) should have description (.+)$/) do |term_name, glossary_name, description_text|
|
29
|
+
term = term_in_result_glossary(result_glossary(glossary_name), term_name)
|
30
|
+
expect(term[:description]).to eq(description_text)
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Given(/^I define a glossary named (\S+) with description (.+)$/) do |glossary_name, description_text|
|
2
|
+
make_glossary(glossary_name).add_child(make_description(description_text))
|
3
|
+
end
|
4
|
+
|
5
|
+
Then(/^there should be a glossary named (\S+)$/) do |glossary_name|
|
6
|
+
expect(result_glossary(glossary_name)).not_to be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
Then(/^the glossary named (\S+) should have description (.+)$/) do |glossary_name, description_text|
|
10
|
+
expect(result_glossary(glossary_name)[:description]).to eq(description_text)
|
11
|
+
end
|
12
|
+
|
13
|
+
Given(/^I define a glossary named (\S+) with implicit description (.+)$/) do |glossary_name, description_text|
|
14
|
+
make_glossary(glossary_name).add_data(description_text)
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^I define a glossary$/) do
|
18
|
+
make_glossary
|
19
|
+
end
|
20
|
+
|
21
|
+
Given(/^I define a glossary named (\S+)$/) do |glossary_name|
|
22
|
+
make_glossary(glossary_name)
|
23
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
2
|
+
lib = File.join(basepath, 'lib')
|
3
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'talk'
|
6
|
+
require 'pp'
|
7
|
+
require 'rspec/expectations'
|
8
|
+
|
9
|
+
class TalkTag
|
10
|
+
attr_reader :children, :words, :tag
|
11
|
+
|
12
|
+
def initialize(tag)
|
13
|
+
@children = []
|
14
|
+
@words = []
|
15
|
+
@tag = tag
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_child(child)
|
19
|
+
@children.push child
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_data(new_words)
|
24
|
+
new_words = new_words.split("\s+") if new_words.is_a? String
|
25
|
+
@words += new_words
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def render(depth=0)
|
30
|
+
indent = "\t" * depth
|
31
|
+
s = "#{indent}#{@tag}\n"
|
32
|
+
s += "#{indent}\t#{@words.join(' ')}\n" unless @words.empty?
|
33
|
+
s += (@children.collect { |x| x.render(depth+1) }).join("\n\n") + "\n" unless @children.empty?
|
34
|
+
|
35
|
+
s
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_child(tag, name=nil, index=0)
|
39
|
+
matches = @children.select { |x| x.tag == tag }
|
40
|
+
matches.select! { |x| x.words[index] == name } unless name.nil?
|
41
|
+
matches.last
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
render
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Define a new @class
|
50
|
+
def make_class(name=nil, description=nil)
|
51
|
+
new_class = TalkTag.new("@class")
|
52
|
+
new_class.add_data(name) unless name.nil?
|
53
|
+
new_class.add_data(description) unless description.nil?
|
54
|
+
@classes.push new_class
|
55
|
+
@last_object = new_class
|
56
|
+
end
|
57
|
+
|
58
|
+
# Define a new @description
|
59
|
+
def make_description(text)
|
60
|
+
@last_object = TalkTag.new("@description").add_data(text)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Define a new @field
|
64
|
+
def make_field(name=nil, type=nil, description=nil)
|
65
|
+
field = TalkTag.new("@field")
|
66
|
+
field.add_data(type) unless type.nil?
|
67
|
+
field.add_data(name) unless name.nil?
|
68
|
+
field.add_data(description) unless description.nil?
|
69
|
+
|
70
|
+
@last_object = field
|
71
|
+
end
|
72
|
+
|
73
|
+
# Define a new @see
|
74
|
+
def make_see(ref_type, ref_name)
|
75
|
+
@last_object = TalkTag.new("@see").add_data([ref_type, ref_name])
|
76
|
+
end
|
77
|
+
|
78
|
+
# Define a new @glossary
|
79
|
+
def make_glossary(name=nil, description=nil)
|
80
|
+
glossary = TalkTag.new("@glossary")
|
81
|
+
glossary.add_data(name) unless name.nil?
|
82
|
+
glossary.add_data(description) unless description.nil?
|
83
|
+
@glossaries.push glossary
|
84
|
+
|
85
|
+
@last_object = glossary
|
86
|
+
end
|
87
|
+
|
88
|
+
# Define a new @term
|
89
|
+
def make_term(name=nil, value=nil, description=nil)
|
90
|
+
term = TalkTag.new("@term")
|
91
|
+
term.add_data(name) unless name.nil?
|
92
|
+
term.add_data(value) unless value.nil?
|
93
|
+
term.add_child(make_description(description)) unless description.nil?
|
94
|
+
|
95
|
+
@last_object = term
|
96
|
+
end
|
97
|
+
|
98
|
+
# Define a new @constant
|
99
|
+
def make_constant(name=nil, value=nil, description=nil)
|
100
|
+
constant = TalkTag.new("@constant")
|
101
|
+
constant.add_data(name) unless name.nil?
|
102
|
+
constant.add_data(value) unless value.nil?
|
103
|
+
constant.add_data(description) unless description.nil?
|
104
|
+
|
105
|
+
@last_object = constant
|
106
|
+
end
|
107
|
+
|
108
|
+
# Define a new @enumeration
|
109
|
+
def make_enumeration(name=nil, description=nil)
|
110
|
+
enumeration = TalkTag.new("@enumeration")
|
111
|
+
enumeration.add_data(name) unless name.nil?
|
112
|
+
enumeration.add_data(description) unless description.nil?
|
113
|
+
@enumerations.push enumeration
|
114
|
+
|
115
|
+
@last_object = enumeration
|
116
|
+
end
|
117
|
+
|
118
|
+
# Find an @class by name
|
119
|
+
def class_named(class_name)
|
120
|
+
@classes.each { |x| return x if x.words[0] == class_name }
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
|
124
|
+
# Find an @enumeration by name
|
125
|
+
def enumeration_named(enumeration_name)
|
126
|
+
@enumerations.each { |x| return x if x.words[0] == enumeration_name }
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
# Find an @glossary by name
|
131
|
+
def glossary_named(glossary_name)
|
132
|
+
@glossaries.each { |x| return x if x.words[0] == glossary_name }
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
|
136
|
+
# Last @class defined via make_class
|
137
|
+
def last_class
|
138
|
+
@classes.nil? ? nil : @classes.last
|
139
|
+
end
|
140
|
+
|
141
|
+
# Last object created using one of the make_* methods
|
142
|
+
def last_object
|
143
|
+
@last_object
|
144
|
+
end
|
145
|
+
|
146
|
+
# Renders actual talk string to give to parser
|
147
|
+
def render
|
148
|
+
all_tags = @classes + @glossaries + @enumerations
|
149
|
+
talk = (all_tags.map { |x| x.to_s }).join("\n\n")
|
150
|
+
end
|
151
|
+
|
152
|
+
# Finds an item with a given name in the specified tag set in the result hash
|
153
|
+
def result_object_named_in_set(basis, set)
|
154
|
+
name = basis
|
155
|
+
name = basis.words[0] if basis.is_a? TalkTag
|
156
|
+
|
157
|
+
@results[set].each do |item|
|
158
|
+
return item if item[:name] == name
|
159
|
+
end
|
160
|
+
|
161
|
+
return nil
|
162
|
+
end
|
163
|
+
|
164
|
+
# Finds a class in the result hash
|
165
|
+
def result_class(cls)
|
166
|
+
result_object_named_in_set(cls, :class)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Finds a class in the result hash
|
170
|
+
def result_enumeration(enum)
|
171
|
+
result_object_named_in_set(enum, :enumeration)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Finds a class in the result hash
|
175
|
+
def result_glossary(glossary)
|
176
|
+
result_object_named_in_set(glossary, :glossary)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Finds a specific field in a result class
|
180
|
+
def field_in_result_class(res_cls, field_name)
|
181
|
+
res_cls = result_class(res_cls) if res_cls.is_a? String
|
182
|
+
return nil if res_cls.nil?
|
183
|
+
|
184
|
+
res_cls[:field].each do |f|
|
185
|
+
return f if f[:name] == field_name
|
186
|
+
end
|
187
|
+
|
188
|
+
nil
|
189
|
+
end
|
190
|
+
|
191
|
+
# Finds a specific term in a result glossary
|
192
|
+
def term_in_result_glossary(res_gloss, term_name)
|
193
|
+
res_gloss = result_glossary(res_gloss) if res_gloss.is_a? String
|
194
|
+
return nil if res_gloss.nil?
|
195
|
+
|
196
|
+
res_gloss[:term].each { |t| return t if t[:name] == term_name }
|
197
|
+
nil
|
198
|
+
end
|
199
|
+
|
200
|
+
# Finds a specific constant in a result enumeration
|
201
|
+
def constant_in_result_enumeration(res_enum, constant_name)
|
202
|
+
res_enum = result_enumeration(res_enum) if res_enum.is_a? String
|
203
|
+
return nil if res_enum.nil?
|
204
|
+
|
205
|
+
res_enum[:constant].each { |t| return t if t[:name] == constant_name }
|
206
|
+
nil
|
207
|
+
end
|
208
|
+
|
209
|
+
# Resets the state so each scenario runs independently
|
210
|
+
def clean_slate
|
211
|
+
@classes = []
|
212
|
+
@glossaries = []
|
213
|
+
@enumerations = []
|
214
|
+
@last_object = nil
|
215
|
+
@parser = Talk::Parser.new
|
216
|
+
@exception = nil
|
217
|
+
Talk::Registry.reset
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
## Generic test cases
|
222
|
+
|
223
|
+
Before do |scenario|
|
224
|
+
clean_slate
|
225
|
+
end
|
226
|
+
|
227
|
+
Given(/^I have defined a valid class$/) do
|
228
|
+
make_class("SomeClass").add_data("A description")
|
229
|
+
end
|
230
|
+
|
231
|
+
Given(/^I have defined a valid class named (\S+)$/) do |class_name|
|
232
|
+
make_class(class_name).add_data("A description")
|
233
|
+
end
|
234
|
+
|
235
|
+
Given(/^I have defined a valid enumeration$/) do
|
236
|
+
make_enumeration("AnEnumeration", "A description")
|
237
|
+
end
|
238
|
+
|
239
|
+
Given(/^I have defined a valid enumeration named (\S+)$/) do |enumeration_name|
|
240
|
+
make_enumeration(enumeration_name, "A description")
|
241
|
+
end
|
242
|
+
|
243
|
+
Given(/^I have defined a valid glossary$/) do
|
244
|
+
make_glossary("AGlossary", "A description")
|
245
|
+
end
|
246
|
+
|
247
|
+
Given(/^I have defined a valid glossary named (\S+)$/) do |glossary_name|
|
248
|
+
make_glossary(glossary_name, "A description")
|
249
|
+
end
|
250
|
+
|
251
|
+
When(/^I get the result hash$/) do
|
252
|
+
begin
|
253
|
+
@parser.parse("scenario.talk", render)
|
254
|
+
@results = @parser.results
|
255
|
+
rescue => @exception
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
Then(/^there should be a parse error$/) do
|
260
|
+
expect(@exception.is_a? Talk::ParseError).to be true
|
261
|
+
end
|