gisele 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +73 -44
- data/Gemfile.lock +1 -0
- data/examples/meeting-scheduler/MeetingScheduling.gis +23 -23
- data/examples/rectal-cancer-pathway/RectalCancerPathway.gis +64 -0
- data/gisele.noespec +1 -1
- data/lib/gisele/command.rb +6 -4
- data/lib/gisele/language/ast/case_st.rb +14 -0
- data/lib/gisele/language/ast/else_clause.rb +14 -0
- data/lib/gisele/language/ast/node.rb +3 -1
- data/lib/gisele/language/ast/{unit.rb → unit_def.rb} +2 -2
- data/lib/gisele/language/dot.yml +1 -1
- data/lib/gisele/language/elsif_flattener.rb +35 -0
- data/lib/gisele/language/if_to_case.rb +63 -0
- data/lib/gisele/language/rewriter/helper.rb +41 -0
- data/lib/gisele/language/rewriter/scoping.rb +34 -0
- data/lib/gisele/language/rewriter/work_on_nodes.rb +30 -0
- data/lib/gisele/language/rewriter.rb +60 -0
- data/lib/gisele/language/sugar_removal.rb +2 -64
- data/lib/gisele/language/syntax/case_st.rb +19 -0
- data/lib/gisele/language/syntax/grammar.citrus +61 -28
- data/lib/gisele/language/syntax/node.rb +3 -3
- data/lib/gisele/language/syntax/task_def.rb +5 -4
- data/lib/gisele/language/syntax/{unit.rb → unit_def.rb} +3 -3
- data/lib/gisele/language/syntax/when_clause.rb +16 -0
- data/lib/gisele/language/to_graph.rb +43 -16
- data/lib/gisele/language.rb +25 -1
- data/lib/gisele/version.rb +1 -1
- data/spec/command/main/gisele_ast_ruby.stdout +29 -35
- data/spec/command/main/gisele_graph.stdout +24 -14
- data/spec/command/main/gisele_help.stdout +1 -1
- data/spec/command/main/gisele_no_sugar.cmd +1 -1
- data/spec/command/main/gisele_no_sugar.stdout +119 -25
- data/spec/command/main/gisele_version.stdout +1 -1
- data/spec/fixtures/tasks/complete.gis +24 -2
- data/spec/fixtures/tasks/simple.ast +29 -35
- data/spec/fixtures/tasks/simple.gis +7 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/language/ast/test_node.rb +10 -11
- data/spec/unit/language/rewriter/test_helper.rb +87 -0
- data/spec/unit/language/rewriter/test_scoping.rb +46 -0
- data/spec/unit/language/rewriter/test_work_on_nodes.rb +45 -0
- data/spec/unit/language/syntax/grammar/test_bool_expr.rb +34 -0
- data/spec/unit/language/syntax/grammar/test_boolean_literal.rb +17 -0
- data/spec/unit/language/syntax/grammar/test_case_st.rb +60 -0
- data/spec/unit/language/syntax/grammar/test_event.rb +18 -0
- data/spec/unit/language/syntax/grammar/test_event_name.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_event_set.rb +27 -0
- data/spec/unit/language/syntax/grammar/test_fluent_def.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_if_st.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_par_st.rb +11 -0
- data/spec/unit/language/syntax/grammar/test_process_statement.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_seq_st.rb +11 -0
- data/spec/unit/language/syntax/grammar/test_spaces.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_spacing.rb +18 -0
- data/spec/unit/language/syntax/grammar/test_task_def.rb +35 -0
- data/spec/unit/language/syntax/grammar/test_task_name.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_task_start_or_end.rb +17 -0
- data/spec/unit/language/syntax/grammar/test_trackvar_def.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_unit_def.rb +29 -0
- data/spec/unit/language/syntax/grammar/test_variable_name.rb +30 -0
- data/spec/unit/language/syntax/grammar/test_when_clause.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_while_st.rb +11 -0
- data/spec/unit/language/syntax/to_ast/test_bool_expr.rb +28 -0
- data/spec/unit/language/syntax/to_ast/test_case_st.rb +47 -0
- data/spec/unit/language/syntax/to_ast/test_else_clause.rb +13 -0
- data/spec/unit/language/syntax/to_ast/test_elsif_clause.rb +15 -0
- data/spec/unit/language/syntax/to_ast/test_event_set.rb +24 -0
- data/spec/unit/language/syntax/to_ast/test_fluent_def.rb +26 -0
- data/spec/unit/language/syntax/to_ast/test_if_st.rb +39 -0
- data/spec/unit/language/syntax/to_ast/test_par_st.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_seq_st.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_task_call_st.rb +10 -0
- data/spec/unit/language/syntax/to_ast/test_task_def.rb +44 -0
- data/spec/unit/language/syntax/to_ast/test_trackvar_def.rb +26 -0
- data/spec/unit/language/syntax/to_ast/test_unit_def.rb +28 -0
- data/spec/unit/language/syntax/to_ast/test_var_ref.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_when_clause.rb +15 -0
- data/spec/unit/language/syntax/to_ast/test_while_st.rb +24 -0
- data/spec/unit/language/test_ast.rb +4 -4
- data/spec/unit/language/test_elsif_flattener.rb +90 -0
- data/spec/unit/language/test_if_to_case.rb +107 -0
- data/spec/unit/language/{test_transformer.rb → test_rewriter.rb} +24 -11
- data/spec/unit/language/test_syntax.rb +1 -1
- data/spec/unit/language/test_to_graph.rb +9 -2
- metadata +120 -34
- data/lib/gisele/language/syntax/task_refinement.rb +0 -15
- data/lib/gisele/language/syntax/task_signature.rb +0 -15
- data/lib/gisele/language/transformer.rb +0 -38
- data/spec/unit/language/sugar_removal/test_if_to_guarded_commands.rb +0 -110
- data/spec/unit/language/syntax/test_grammar.rb +0 -317
- data/spec/unit/language/syntax/test_to_ast.rb +0 -257
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'case_st' do
|
4
|
+
|
5
|
+
it 'supports a single when clause' do
|
6
|
+
expr = <<-CASE_ST.strip
|
7
|
+
case
|
8
|
+
when goodCond
|
9
|
+
Task1
|
10
|
+
end
|
11
|
+
CASE_ST
|
12
|
+
parse(expr, :case_st).should eq(expr)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'supports boolean expressions in when clauses' do
|
16
|
+
expr = <<-CASE_ST.strip
|
17
|
+
case
|
18
|
+
when not(goodCond) or badCond
|
19
|
+
Task1
|
20
|
+
end
|
21
|
+
CASE_ST
|
22
|
+
parse(expr, :case_st).should eq(expr)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'supports a multiple when clauses' do
|
26
|
+
expr = <<-CASE_ST.strip
|
27
|
+
case
|
28
|
+
when goodCond
|
29
|
+
Task1
|
30
|
+
when badCond
|
31
|
+
Task2
|
32
|
+
end
|
33
|
+
CASE_ST
|
34
|
+
parse(expr, :case_st).should eq(expr)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'supports an else clause' do
|
38
|
+
expr = <<-CASE_ST.strip
|
39
|
+
case
|
40
|
+
when goodCond
|
41
|
+
Task1
|
42
|
+
else
|
43
|
+
Task2
|
44
|
+
end
|
45
|
+
CASE_ST
|
46
|
+
parse(expr, :case_st).should eq(expr)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'supports an optional variable name' do
|
50
|
+
expr = <<-CASE_ST.strip
|
51
|
+
case someVariable
|
52
|
+
when goodCond
|
53
|
+
Task1
|
54
|
+
end
|
55
|
+
CASE_ST
|
56
|
+
parse(expr, :case_st).should eq(expr)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'event' do
|
4
|
+
|
5
|
+
it 'parses correct events' do
|
6
|
+
parse('Task:start', :event).should eq('Task:start')
|
7
|
+
parse('Task:end', :event).should eq('Task:end')
|
8
|
+
parse('an_event', :event).should eq('an_event')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'raises on invalid event names' do
|
12
|
+
lambda{
|
13
|
+
parse('Task', :event)
|
14
|
+
}.should raise_error(Citrus::ParseError)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'event_name' do
|
4
|
+
|
5
|
+
it 'parses correct event names' do
|
6
|
+
parse('a', :event_name).should eq('a')
|
7
|
+
parse('event', :event_name).should eq('event')
|
8
|
+
parse('event_name', :event_name).should eq('event_name')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'raises on invalid variable names' do
|
12
|
+
lambda{
|
13
|
+
parse('NotAnEventName', :event_name)
|
14
|
+
}.should raise_error(Citrus::ParseError)
|
15
|
+
lambda{
|
16
|
+
parse('notAnEventName', :event_name)
|
17
|
+
}.should raise_error(Citrus::ParseError)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'event_set' do
|
4
|
+
|
5
|
+
it 'parses empty sets' do
|
6
|
+
parse('{}', :event_set).should eq('{}')
|
7
|
+
parse('{ }', :event_set).should eq('{ }')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'parses event singletons' do
|
11
|
+
parse('{Task:start}', :event_set).should eq('{Task:start}')
|
12
|
+
parse('{ Task:start }', :event_set).should eq('{ Task:start }')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'parses event sets' do
|
16
|
+
parse('{Task:start, Task:end}', :event_set).should eq('{Task:start, Task:end}')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'recognizes invalid events in the set' do
|
20
|
+
lambda{
|
21
|
+
parse('{Task:start, NotAnEvent}', :event_set)
|
22
|
+
}.should raise_error(Citrus::ParseError)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'fluent_def' do
|
4
|
+
|
5
|
+
it 'parses valid fluent definitions' do
|
6
|
+
defn = 'fluent diagKnown {Diagnosis:start}, {Treatment:end} initially false'
|
7
|
+
parse(defn, :fluent_def).should eq(defn)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'supports a missing initial value' do
|
11
|
+
defn = 'fluent diagKnown {Diagnosis:start}, {Treatment:end}'
|
12
|
+
parse(defn, :fluent_def).should eq(defn)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'supports empty sets for events' do
|
16
|
+
defn = 'fluent diagKnown {}, {} initially true'
|
17
|
+
parse(defn, :fluent_def).should eq(defn)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'if_st' do
|
4
|
+
|
5
|
+
it 'parses a single if statement' do
|
6
|
+
expr = 'if goodCond Task end'
|
7
|
+
parse(expr, :if_st).should eq(expr)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'supports an optional else' do
|
11
|
+
expr = 'if goodCond GoodTask else BadTask end'
|
12
|
+
parse(expr, :if_st).should eq(expr)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'supports an optional elsif clauses' do
|
16
|
+
expr = 'if goodCond GoodTask elsif otherCond OtherTask elsif yetAnother BadTask end'
|
17
|
+
parse(expr, :if_st).should eq(expr)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'process_statement' do
|
4
|
+
|
5
|
+
it 'parses a simple process statement' do
|
6
|
+
expr = <<-PROCESS.strip
|
7
|
+
DoSomething
|
8
|
+
if goodCond
|
9
|
+
DoForGood
|
10
|
+
else
|
11
|
+
DoForBad
|
12
|
+
end
|
13
|
+
CleanDesk
|
14
|
+
PROCESS
|
15
|
+
parse(expr, :process_statement).should eq(expr)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'spaces' do
|
4
|
+
|
5
|
+
it 'parses all kind of spaces' do
|
6
|
+
parse(' ', :spaces).should eq(' ')
|
7
|
+
parse("\t", :spaces).should eq("\t")
|
8
|
+
parse("\n", :spaces).should eq("\n")
|
9
|
+
parse(" \t\n", :spaces).should eq(" \t\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'enforces mandatory spacing' do
|
13
|
+
lambda{
|
14
|
+
parse('', :spaces)
|
15
|
+
}.should raise_error(Citrus::ParseError)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'spacing' do
|
4
|
+
|
5
|
+
it 'parses all kind of spaces' do
|
6
|
+
parse(' ', :spacing).should eq(' ')
|
7
|
+
parse("\t", :spacing).should eq("\t")
|
8
|
+
parse("\n", :spacing).should eq("\n")
|
9
|
+
parse(" \t\n", :spacing).should eq(" \t\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'does not enforces mandatory spacing' do
|
13
|
+
parse('', :spacing).should eq('')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'task_def' do
|
4
|
+
|
5
|
+
it 'parses a simple implicit task definition' do
|
6
|
+
taskdef = <<-TASKDEF.strip
|
7
|
+
task Process
|
8
|
+
Diagnosis
|
9
|
+
end
|
10
|
+
TASKDEF
|
11
|
+
parse(taskdef, :task_def).should eq(taskdef)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'allows any statement' do
|
15
|
+
taskdef = <<-TASKDEF.strip
|
16
|
+
task Process
|
17
|
+
while true Diagnosis end
|
18
|
+
end
|
19
|
+
TASKDEF
|
20
|
+
parse(taskdef, :task_def).should eq(taskdef)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'supports optional variable definitions in the signature' do
|
24
|
+
taskdef = <<-TASKDEF.strip
|
25
|
+
task Process
|
26
|
+
fluent diagKnown {Diagnosis:start}, {} initially false
|
27
|
+
trackvar mplus {Diagnosis:end}
|
28
|
+
Diagnosis
|
29
|
+
end
|
30
|
+
TASKDEF
|
31
|
+
parse(taskdef, :task_def).should eq(taskdef)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar,'task_name' do
|
4
|
+
|
5
|
+
it 'parses correct task names' do
|
6
|
+
parse('A', :task_name).should eq('A')
|
7
|
+
parse('Diagnosis', :task_name).should eq('Diagnosis')
|
8
|
+
parse('TaskName', :task_name).should eq('TaskName')
|
9
|
+
parse('Task_Name', :task_name).should eq('Task_Name')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'raises on invalid task names' do
|
13
|
+
lambda{
|
14
|
+
parse('not_a_task_name', :task_name)
|
15
|
+
}.should raise_error(Citrus::ParseError)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'task_start_or_end' do
|
4
|
+
|
5
|
+
it 'parses correct event names' do
|
6
|
+
parse('Task:start', :task_start_or_end).should eq('Task:start')
|
7
|
+
parse('Task:end', :task_start_or_end).should eq('Task:end')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'raises on simple task names' do
|
11
|
+
lambda{
|
12
|
+
parse('Task', :task_start_or_end)
|
13
|
+
}.should raise_error(Citrus::ParseError)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'trackvar_def' do
|
4
|
+
|
5
|
+
it 'parses valid tracking variable definitions' do
|
6
|
+
defn = 'trackvar plateletLow {BloodTest:end}'
|
7
|
+
parse(defn, :trackvar_def).should eq(defn)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'supports an optional initial value' do
|
11
|
+
defn = 'trackvar plateletLow {BloodTest:end} initially false'
|
12
|
+
parse(defn, :trackvar_def).should eq(defn)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'supports optional obsolete events' do
|
16
|
+
defn = 'trackvar plateletLow {BloodTest:end}, {Chemotherapy:end}'
|
17
|
+
parse(defn, :trackvar_def).should eq(defn)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'unit' do
|
4
|
+
|
5
|
+
it 'parses a single task definition' do
|
6
|
+
expr = <<-UNIT.strip
|
7
|
+
task Task1 end
|
8
|
+
UNIT
|
9
|
+
parse(expr, :unit_def).should eq(expr)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts multiple task definitions' do
|
13
|
+
expr = <<-UNIT.strip
|
14
|
+
task Task1 end
|
15
|
+
task Task2 end
|
16
|
+
UNIT
|
17
|
+
parse(expr, :unit_def).should eq(expr)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'allows trailing spaces' do
|
21
|
+
expr = <<-UNIT
|
22
|
+
task Task1 end
|
23
|
+
task Task2 end
|
24
|
+
UNIT
|
25
|
+
parse(expr, :unit_def).should eq(expr)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'variable_name' do
|
4
|
+
|
5
|
+
it 'parses correct variable names' do
|
6
|
+
parse('a', :variable_name).should eq('a')
|
7
|
+
parse('diagnosis', :variable_name).should eq('diagnosis')
|
8
|
+
parse('varName', :variable_name).should eq('varName')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not allow reserved words' do
|
12
|
+
Gisele::Language::RESERVED_WORDS.each do |word|
|
13
|
+
lambda{
|
14
|
+
parse(word.to_s + " ", :variable_name)
|
15
|
+
}.should raise_error(Citrus::ParseError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allows a reserved word as prefix' do
|
20
|
+
parse('ifSomething', :variable_name).should eq('ifSomething')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'raises on invalid variable names' do
|
24
|
+
lambda{
|
25
|
+
parse('NotAVarName', :variable_name)
|
26
|
+
}.should raise_error(Citrus::ParseError)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe Grammar, 'when_clause' do
|
4
|
+
|
5
|
+
it 'parses a single when clause statement' do
|
6
|
+
expr = 'when goodCond Task'
|
7
|
+
parse(expr, :when_clause).should eq(expr)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'supports a boolean expression' do
|
11
|
+
expr = 'when not(goodCond and badCond) Task'
|
12
|
+
parse(expr, :when_clause).should eq(expr)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'supports an complex process statement' do
|
16
|
+
expr = 'when goodCond Task1 par Task2 Task3 end'
|
17
|
+
parse(expr, :when_clause).should eq(expr)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe BoolExpr, "to_ast" do
|
4
|
+
|
5
|
+
it 'returns expected ast on simple expressions' do
|
6
|
+
expected = \
|
7
|
+
[:bool_expr, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]]]
|
8
|
+
ast("diagKnown and platLow", :bool_expr).should eq(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'respects priorities' do
|
12
|
+
expected = [:bool_expr,
|
13
|
+
[:bool_or, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]], [:var_ref, "platHigh"]]]
|
14
|
+
ast("diagKnown and platLow or platHigh", :bool_expr).should eq(expected)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'supports double negations' do
|
18
|
+
expected = [:bool_expr, [:bool_not, [:bool_not, [:var_ref, "diagKnown"]]]]
|
19
|
+
ast("not not(diagKnown)", :bool_expr).should eq(expected)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'makes boolean literals explicit' do
|
23
|
+
ast("true", :bool_expr).should eq([:bool_expr, [:bool_lit, true]])
|
24
|
+
ast("false", :bool_expr).should eq([:bool_expr, [:bool_lit, false]])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe CaseSt, "to_ast" do
|
4
|
+
|
5
|
+
it 'arranges when clauses as expected' do
|
6
|
+
expr = <<-CASE_ST.strip
|
7
|
+
case
|
8
|
+
when good
|
9
|
+
Task1
|
10
|
+
when bad
|
11
|
+
Task2
|
12
|
+
end
|
13
|
+
CASE_ST
|
14
|
+
when_clause1 = ast("when good Task1", :when_clause)
|
15
|
+
when_clause2 = ast("when bad Task2", :when_clause)
|
16
|
+
expected = [:case_st, nil, when_clause1, when_clause2]
|
17
|
+
ast(expr, :case_st).should eq(expected)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'puts the else clause at the end' do
|
21
|
+
expr = <<-CASE_ST.strip
|
22
|
+
case
|
23
|
+
when good
|
24
|
+
Task1
|
25
|
+
else
|
26
|
+
Task2
|
27
|
+
end
|
28
|
+
CASE_ST
|
29
|
+
when_clause = ast("when good Task1", :when_clause)
|
30
|
+
else_clause = ast("else Task2", :else_clause)
|
31
|
+
expected = [:case_st, nil, when_clause, else_clause]
|
32
|
+
ast(expr, :case_st).should eq(expected)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'supports an optional variable name' do
|
36
|
+
expr = <<-CASE_ST.strip
|
37
|
+
case someVariable
|
38
|
+
when good
|
39
|
+
Task1
|
40
|
+
end
|
41
|
+
CASE_ST
|
42
|
+
expected = [:var_ref, "someVariable"]
|
43
|
+
ast(expr, :case_st)[1].should eq(expected)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe ElseClause, "to_ast" do
|
4
|
+
|
5
|
+
it 'parses as expected' do
|
6
|
+
expr = "else Task1"
|
7
|
+
expected = \
|
8
|
+
[:else_clause, [:task_call_st, "Task1"]]
|
9
|
+
ast(expr, :else_clause).should eq(expected)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe ElsifClause, "to_ast" do
|
4
|
+
|
5
|
+
it 'parses as expected' do
|
6
|
+
expr = "elsif goodCond Task1"
|
7
|
+
expected = \
|
8
|
+
[:elsif_clause,
|
9
|
+
[:bool_expr, [:var_ref, "goodCond"]],
|
10
|
+
[:task_call_st, "Task1"]]
|
11
|
+
ast(expr, :elsif_clause).should eq(expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe EventSet, "to_ast" do
|
4
|
+
|
5
|
+
it 'converts empty lists as expected' do
|
6
|
+
expr = '{ }'
|
7
|
+
expected = [:event_set]
|
8
|
+
ast(expr, :event_set).should eq(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'converts singleton lists as expected' do
|
12
|
+
expr = '{Diagnosis:start}'
|
13
|
+
expected = [:event_set, "Diagnosis:start"]
|
14
|
+
ast(expr, :event_set).should eq(expected)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'converts non empty lists as expected' do
|
18
|
+
expr = '{Diagnosis:start, an_event, another_one}'
|
19
|
+
expected = [:event_set, "Diagnosis:start", "an_event", "another_one"]
|
20
|
+
ast(expr, :event_set).should eq(expected)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe FluentDef, "to_ast" do
|
4
|
+
|
5
|
+
it 'converts fluent definitions as expected' do
|
6
|
+
defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end} initially false"
|
7
|
+
expected = [:fluent,
|
8
|
+
"diagKnown",
|
9
|
+
[:event_set, "Diagnosis:start", "diagnosis"],
|
10
|
+
[:event_set, "Treatment:end"],
|
11
|
+
false]
|
12
|
+
ast(defn, :fluent_def).should eq(expected)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not require the initial value' do
|
16
|
+
defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end}"
|
17
|
+
expected = [:fluent,
|
18
|
+
"diagKnown",
|
19
|
+
[:event_set, "Diagnosis:start", "diagnosis"],
|
20
|
+
[:event_set, "Treatment:end"],
|
21
|
+
nil]
|
22
|
+
ast(defn, :fluent_def).should eq(expected)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe IfSt, "to_ast" do
|
4
|
+
|
5
|
+
it 'parses as expected' do
|
6
|
+
expr = "if goodCond Task1 end"
|
7
|
+
expected = \
|
8
|
+
[:if_st,
|
9
|
+
[:bool_expr, [:var_ref, "goodCond"]],
|
10
|
+
[:task_call_st, "Task1"]]
|
11
|
+
ast(expr, :if_st).should eq(expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'supports a else clause' do
|
15
|
+
expr = "if goodCond Task1 else Task2 end"
|
16
|
+
expected = \
|
17
|
+
[:if_st,
|
18
|
+
[:bool_expr, [:var_ref, "goodCond"]],
|
19
|
+
[:task_call_st, "Task1"],
|
20
|
+
[:else_clause, [:task_call_st, "Task2"]] ]
|
21
|
+
ast(expr, :if_st).should eq(expected)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'supports elsif clauses' do
|
25
|
+
expr = "if goodCond Task1 elsif otherCond Task2 elsif stillAnother Task3 else Task4 end"
|
26
|
+
expected = \
|
27
|
+
[:if_st,
|
28
|
+
[:bool_expr, [:var_ref, "goodCond"]], [:task_call_st, "Task1"],
|
29
|
+
[:elsif_clause,
|
30
|
+
[:bool_expr, [:var_ref, "otherCond"]], [:task_call_st, "Task2"]],
|
31
|
+
[:elsif_clause,
|
32
|
+
[:bool_expr, [:var_ref, "stillAnother"]], [:task_call_st, "Task3"]],
|
33
|
+
[:else_clause,
|
34
|
+
[:task_call_st, "Task4"]] ]
|
35
|
+
ast(expr, :if_st).should eq(expected)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Gisele::Language::Syntax
|
3
|
+
describe ParSt, "to_ast" do
|
4
|
+
|
5
|
+
it 'parses as expected' do
|
6
|
+
expr = "par Task1 Task2 end"
|
7
|
+
expected = [:par_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]
|
8
|
+
ast(expr, :par_st).should eq(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|