Skip to content

Commit

Permalink
Outputing the function counter to XML.
Browse files Browse the repository at this point in the history
Now, globalFunctions tag appears in the header of the xml output file.
  • Loading branch information
giulianobelinassi committed May 12, 2017
1 parent 717f57f commit 59fe7d9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/kuniri/parser/output_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def handle_cond_loop_and_block(singleElement)
def handle_global_functions(singleElement)
funcs = singleElement.global_functions
len = funcs.length
function_counter_generate(len)
generate_global_functions(funcs) if len.positive?
end

Expand Down Expand Up @@ -117,6 +118,10 @@ def function_behaviour_generate(_pElementName, _pFunction)
raise NotImplementedError
end

def function_counter_generate(_pCounterLabel, _numberOfFunctons)
raise NotImplementedError
end

def global_variable_generate(_pGlobalVariable)
raise NotImplementedError
end
Expand Down
5 changes: 5 additions & 0 deletions lib/kuniri/parser/xml_output_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def function_behaviour_generate(pElementName, pFunction)
end
end

def function_counter_generate(pNumberOfFunctions)
@outputEngine.send('globalFunctions',
counter: pNumberOfFunctions)
end

# @see OutputFormat
def parameters_generate(pParameters)
if pParameters.is_a?Hash
Expand Down
9 changes: 9 additions & 0 deletions spec/parser/xmlSchemaValidate/class_data.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<xs:element name="kuniri">
<xs:complexType>
<xs:sequence>
<xs:element name="globalFunctions" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="counter"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="externRequirementData" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
Expand Down
11 changes: 10 additions & 1 deletion spec/parser/xmlSchemaValidate/fullCodeTwo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="name"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="globalFunctions">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:byte" name="counter"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
11 changes: 10 additions & 1 deletion spec/parser/xmlSchemaValidate/fullCodeWithComments.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="name"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="globalFunctions">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:byte" name="counter"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
9 changes: 9 additions & 0 deletions spec/parser/xmlSchemaValidate/simpleFunction.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<xs:element name="kuniri">
<xs:complexType>
<xs:sequence>
<xs:element name="globalFunctions">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:byte" name="counter"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="functionData" maxOccurs="unbounded" minOccurs="0">
<xs:complexType mixed="true">
<xs:sequence>
Expand Down
2 changes: 2 additions & 0 deletions spec/parser/xml_builder_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@

it "Full global function" do
@builder.kuniri do
globalFunctions :counter => "1"
functionData :name => "xpto", :visibility => "global" do
parameterData :name => "two"
conditionalData :type => "if", :expression => "y == x"
Expand All @@ -223,6 +224,7 @@

output = [@basicHeader,
'<kuniri>',
' <globalFunctions counter="1"/>',
' <functionData name="xpto" visibility="global">',
' <parameterData name="two"/>',
' <conditionalData type="if" expression="y == x"/>',
Expand Down
4 changes: 4 additions & 0 deletions spec/parser/xml_output_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@
expect(@handler.elements[4].attributes['name']).to eq('globalVariable')
end

it 'Verify if the global function counter is correct' do
expect(@handler.elements[8].attributes['counter']).to eq('0')
end

#TODO: FINISH THIS TEST, AFTER FIX THE GLOBAL VARIABLE BUG

after :each do
Expand Down

0 comments on commit 59fe7d9

Please sign in to comment.