sbyc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/lib/sbyc.rb +1 -1
  2. data/lib/sbyc/codetree.rb +9 -6
  3. data/lib/sbyc/codetree/ast_node.rb +39 -4
  4. data/lib/sbyc/codetree/eval/functional_eval.rb +1 -1
  5. data/lib/sbyc/codetree/eval/object_eval.rb +1 -1
  6. data/lib/sbyc/codetree/name2x.rb +2 -0
  7. data/lib/sbyc/codetree/name2x/delegate.rb +57 -0
  8. data/lib/sbyc/codetree/name2x/module_delegate.rb +25 -0
  9. data/lib/sbyc/codetree/proc_parser.rb +46 -14
  10. data/lib/sbyc/codetree/producing.rb +2 -1
  11. data/lib/sbyc/codetree/producing/producer.rb +12 -0
  12. data/lib/sbyc/codetree/producing/tracing_methods.rb +77 -0
  13. data/test/spec/unit/sbyc/codetree/ast_node/code_inject.spec +57 -0
  14. data/test/spec/unit/sbyc/codetree/ast_node/digest.spec +83 -0
  15. data/test/spec/unit/sbyc/codetree/ast_node/rename.spec +36 -0
  16. data/test/spec/unit/sbyc/codetree/ast_node/to_s.spec +1 -1
  17. data/test/spec/unit/sbyc/codetree/ast_node/visit.spec +2 -2
  18. data/test/spec/unit/sbyc/codetree/name2x/delegate/coerce.spec +38 -0
  19. data/test/spec/unit/sbyc/codetree/name2x/delegate/fetch.spec +15 -0
  20. data/test/spec/unit/sbyc/codetree/name2x/delegate/name2class.spec +31 -0
  21. data/test/spec/unit/sbyc/codetree/name2x/delegate/name2module.spec +31 -0
  22. data/test/spec/unit/sbyc/codetree/name2x/delegate/name2name.spec +31 -0
  23. data/test/spec/unit/sbyc/codetree/name2x/module_delegate/name2class.spec +27 -0
  24. data/test/spec/unit/sbyc/codetree/name2x/module_delegate/name2module.spec +22 -0
  25. data/test/spec/unit/sbyc/codetree/name2x/module_delegate/name2name.spec +18 -0
  26. data/test/spec/unit/sbyc/codetree/parse.spec +32 -0
  27. data/test/spec/unit/sbyc/codetree/proc_parser/expr.spec +1 -1
  28. data/test/spec/unit/sbyc/codetree/proc_parser/parse.spec +34 -1
  29. data/test/spec/unit/sbyc/codetree/producing/producer/add_extension.spec +62 -0
  30. data/test/spec/unit/sbyc/codetree/producing/tracing_methods.spec +36 -0
  31. data/test/spec/unit/sbyc/codetree/producing/tracing_methods/default_options.spec +10 -0
  32. data/test/spec/unit/sbyc/codetree/producing/tracing_methods/prepare_options.spec +18 -0
  33. data/test/spec/unit/sbyc/codetree/producing/tracing_methods/trace.spec +59 -0
  34. data/test/spec/unit/sbyc/codetree/producing/tracing_methods/trace_rule_entered.spec +25 -0
  35. data/test/spec/unit/sbyc/codetree/producing/tracing_methods/trace_rule_exited.spec +25 -0
  36. metadata +27 -4
@@ -2,7 +2,7 @@ require File.expand_path('../../../../../spec_helper', __FILE__)
2
2
 
3
3
  describe "CodeTree::ProcParser::Expr" do
4
4
 
5
- let(:the_expr) { CodeTree::ProcParser::Expr.new }
5
+ let(:the_expr) { CodeTree::ProcParser::Expr.new(nil, nil, nil) }
6
6
 
7
7
  describe("should not have access to Kernel methods") do
8
8
  specify{
@@ -69,7 +69,7 @@ describe "CodeTree::ProcParser#parse" do
69
69
  end
70
70
 
71
71
  context "when call on expressions that refer to ruby Kernel methods" do
72
- let(:expected) { "(puts (to_s (? (_ :x))))"}
72
+ let(:expected) { "(puts (to_s (? (_ :x))))" }
73
73
  let(:code) { lambda { (puts (to_s x)) } }
74
74
  specify{ subject.inspect.should == expected }
75
75
  end
@@ -80,4 +80,37 @@ describe "CodeTree::ProcParser#parse" do
80
80
  specify{ subject.inspect.should == expected }
81
81
  end
82
82
 
83
+ context "when called with a multiline option set to false" do
84
+ let(:expected) { "(puts (to_s (? (_ :x))))" }
85
+ let(:code) { lambda { (puts (to_s x)) } }
86
+ subject { CodeTree::ProcParser::parse(code, :multiline => false) }
87
+ specify{
88
+ subject.inspect.should == expected
89
+ }
90
+ end
91
+
92
+ context "when called with a multiline option set to true" do
93
+ let(:expected) { "(puts (to_s (? (_ :x))))" }
94
+ let(:code) { lambda { (puts (to_s x)) } }
95
+ subject { CodeTree::ProcParser::parse(code, :multiline => true) }
96
+ specify{
97
+ subject.should be_kind_of(Array)
98
+ subject[0].inspect.should == expected
99
+ }
100
+ end
101
+
102
+ context "when called with a multiline option set to true and multiple lines" do
103
+ let(:code) { lambda {
104
+ (puts (to_s x))
105
+ (say "hello")
106
+ } }
107
+ subject { CodeTree::ProcParser::parse(code, :multiline => true) }
108
+ specify{
109
+ subject.should be_kind_of(Array)
110
+ subject.size.should == 2
111
+ subject[0].inspect.should == "(puts (to_s (? (_ :x))))"
112
+ subject[1].inspect.should == '(say (_ "hello"))'
113
+ }
114
+ end
115
+
83
116
  end
@@ -0,0 +1,62 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::Producer#apply_args_conventions" do
4
+
5
+ let(:producer) { ::CodeTree::producer }
6
+
7
+ context "whitout options at all (not provided, no default)" do
8
+ let(:extension) { module Ext; def hello() "hello"; end end; Ext }
9
+
10
+ subject { producer.add_extension(extension) }
11
+ it { should == producer }
12
+ it { should be_kind_of(extension) }
13
+ it { should respond_to(:hello) }
14
+ specify { producer.extension_options[extension].should be_nil }
15
+ end
16
+
17
+ context "with default options only" do
18
+ let(:extension) {
19
+ module ::Ext
20
+ def self.prepare_options(options)
21
+ { :who => "blambeau", :times => 3 }.merge(options)
22
+ end
23
+ def hello()
24
+ extension_options[Ext][:who]*extension_options[Ext][:times]
25
+ end
26
+ end;
27
+ ::Ext
28
+ }
29
+ subject { producer.add_extension(extension) }
30
+ it { should == producer }
31
+ it { should be_kind_of(extension) }
32
+ it { should respond_to(:hello) }
33
+ specify {
34
+ subject.extension_options[extension].should == { :who => "blambeau", :times => 3 }
35
+ subject.hello.should == "blambeaublambeaublambeau"
36
+ }
37
+ end
38
+
39
+
40
+ context "with both" do
41
+ let(:extension) {
42
+ module ::Ext
43
+ def self.prepare_options(options)
44
+ { :who => "blambeau", :times => 3 }.merge(options)
45
+ end
46
+ def hello()
47
+ extension_options[Ext][:who]*extension_options[Ext][:times]
48
+ end
49
+ end;
50
+ ::Ext
51
+ }
52
+ subject { producer.add_extension(extension, :times => 1) }
53
+ it { should == producer }
54
+ it { should be_kind_of(extension) }
55
+ it { should respond_to(:hello) }
56
+ specify {
57
+ subject.extension_options[extension].should == { :who => "blambeau", :times => 1 }
58
+ subject.hello.should == "blambeau"
59
+ }
60
+ end
61
+
62
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingOptions" do
4
+
5
+ let(:producer) {
6
+ ::CodeTree::producer{|p|
7
+ p.rule(:'_') do |engine, node|
8
+ engine.trace("On: #{node.literal.inspect}")
9
+ end
10
+ p.rule("*") do |engine, node|
11
+ engine.trace_rule_entered("Before: #{node}")
12
+ engine.apply(node.children)
13
+ engine.trace_rule_exited("After: #{node}")
14
+ nil
15
+ end
16
+ }
17
+ }
18
+
19
+ let(:expr) { CodeTree::parse{ (concat "hello ", who) } }
20
+
21
+ subject { producer.tracing_options[:io] }
22
+
23
+ context("With default options but io") do
24
+ before do
25
+ producer.add_extension(::CodeTree::Producing::TracingMethods, :io => [])
26
+ producer.apply(expr)
27
+ end
28
+ it { should == ['Before: (concat "hello ", who)' + "\n",
29
+ ' On: "hello "' + "\n",
30
+ ' Before: who' + "\n",
31
+ ' On: :who' + "\n",
32
+ ' After: who' + "\n",
33
+ 'After: (concat "hello ", who)' + "\n"] }
34
+ end
35
+
36
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingMethods#default_options" do
4
+
5
+ subject{ CodeTree::Producing::TracingMethods.default_options }
6
+
7
+ it { should be_kind_of(Hash) }
8
+ specify { subject[:io].should_not be_nil }
9
+
10
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingMethods#prepare_options" do
4
+
5
+ subject{ CodeTree::Producing::TracingMethods.prepare_options(options) }
6
+
7
+ context "When called without options" do
8
+ let(:options){ {} }
9
+ it { should == CodeTree::Producing::TracingMethods.default_options }
10
+ specify { subject[:io].should == STDOUT }
11
+ end
12
+
13
+ context "When called with overriding option" do
14
+ let(:options){ {:io => []} }
15
+ specify { subject[:io].should == [] }
16
+ end
17
+
18
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingMethods#trace" do
4
+
5
+ context("Without indentation support") do
6
+ let(:tracer) {
7
+ t = Object.new
8
+ t.extend(CodeTree::Producing::TracingMethods)
9
+ def t.tracing_options
10
+ @options ||= {:newline_support => false,
11
+ :indent_support => false,
12
+ :indent_level => 12,
13
+ :io => []}
14
+ end
15
+ t
16
+ }
17
+ specify {
18
+ tracer.trace("This is a first message\n")
19
+ tracer.tracing_io.should == ["This is a first message\n"]
20
+ }
21
+ end
22
+
23
+ context("With indent support") do
24
+ let(:tracer) {
25
+ t = Object.new
26
+ t.extend(CodeTree::Producing::TracingMethods)
27
+ def t.tracing_options
28
+ @options ||= {:newline_support => false,
29
+ :indent_support => true,
30
+ :indent_level => 2,
31
+ :indent_string => "aaa ",
32
+ :io => []}
33
+ end
34
+ t
35
+ }
36
+ specify {
37
+ tracer.trace("This is a first message")
38
+ tracer.tracing_io.should == ["aaa aaa This is a first message"]
39
+ }
40
+ end
41
+
42
+ context("With newline support") do
43
+ let(:tracer) {
44
+ t = Object.new
45
+ t.extend(CodeTree::Producing::TracingMethods)
46
+ def t.tracing_options
47
+ @options ||= {:newline_support => true,
48
+ :indent_support => false,
49
+ :io => []}
50
+ end
51
+ t
52
+ }
53
+ specify {
54
+ tracer.trace("This is a first message")
55
+ tracer.tracing_io.should == ["This is a first message\n"]
56
+ }
57
+ end
58
+
59
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingMethods#trace_rule_entered" do
4
+
5
+ let(:tracer) {
6
+ t = Object.new.extend(CodeTree::Producing::TracingMethods)
7
+ def t.tracing_options
8
+ @options ||= CodeTree::Producing::TracingMethods.prepare_options(:io => [])
9
+ end
10
+ t
11
+ }
12
+
13
+ it "Should increment the indent level" do
14
+ bef = tracer.tracing_indent_level
15
+ tracer.trace_rule_entered("A message")
16
+ aft = tracer.tracing_indent_level
17
+ aft.should == bef+1
18
+ end
19
+
20
+ it "Should log the message" do
21
+ tracer.trace_rule_entered("A message")
22
+ tracer.tracing_io.should == ["A message\n"]
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../../../../../spec_helper', __FILE__)
2
+
3
+ describe "CodeTree::Producing::TracingMethods#trace_rule_exited" do
4
+
5
+ let(:tracer) {
6
+ t = Object.new.extend(CodeTree::Producing::TracingMethods)
7
+ def t.tracing_options
8
+ @options ||= CodeTree::Producing::TracingMethods.prepare_options(:io => [])
9
+ end
10
+ t
11
+ }
12
+
13
+ it "Should increment the indent level" do
14
+ bef = tracer.tracing_indent_level
15
+ tracer.trace_rule_exited("A message")
16
+ aft = tracer.tracing_indent_level
17
+ aft.should == bef-1
18
+ end
19
+
20
+ it "Should log the message" do
21
+ tracer.trace_rule_exited("A message")
22
+ tracer.tracing_io.should == ["A message\n"]
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbyc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernard Lambeau
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-20 00:00:00 +02:00
18
+ date: 2010-06-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -38,8 +38,12 @@ files:
38
38
  - lib/sbyc/codetree/matching/match_data.rb
39
39
  - lib/sbyc/codetree/matching/matcher.rb
40
40
  - lib/sbyc/codetree/matching.rb
41
+ - lib/sbyc/codetree/name2x/delegate.rb
42
+ - lib/sbyc/codetree/name2x/module_delegate.rb
43
+ - lib/sbyc/codetree/name2x.rb
41
44
  - lib/sbyc/codetree/proc_parser.rb
42
45
  - lib/sbyc/codetree/producing/producer.rb
46
+ - lib/sbyc/codetree/producing/tracing_methods.rb
43
47
  - lib/sbyc/codetree/producing.rb
44
48
  - lib/sbyc/codetree/rewriting/class_methods.rb
45
49
  - lib/sbyc/codetree/rewriting/compiler.rb
@@ -58,10 +62,13 @@ files:
58
62
  - test/spec/documentation/readme/syntax.spec
59
63
  - test/spec/spec_helper.rb
60
64
  - test/spec/test_all.rb
65
+ - test/spec/unit/sbyc/codetree/ast_node/code_inject.spec
61
66
  - test/spec/unit/sbyc/codetree/ast_node/coerce.spec
67
+ - test/spec/unit/sbyc/codetree/ast_node/digest.spec
62
68
  - test/spec/unit/sbyc/codetree/ast_node/equality.spec
63
69
  - test/spec/unit/sbyc/codetree/ast_node/inspect.spec
64
70
  - test/spec/unit/sbyc/codetree/ast_node/literal.spec
71
+ - test/spec/unit/sbyc/codetree/ast_node/rename.spec
65
72
  - test/spec/unit/sbyc/codetree/ast_node/to_a.spec
66
73
  - test/spec/unit/sbyc/codetree/ast_node/to_s.spec
67
74
  - test/spec/unit/sbyc/codetree/ast_node/visit.spec
@@ -75,10 +82,26 @@ files:
75
82
  - test/spec/unit/sbyc/codetree/matching/matcher/do_match.spec
76
83
  - test/spec/unit/sbyc/codetree/matching/matcher/function_match.spec
77
84
  - test/spec/unit/sbyc/codetree/matching/matcher/match.spec
85
+ - test/spec/unit/sbyc/codetree/name2x/delegate/coerce.spec
86
+ - test/spec/unit/sbyc/codetree/name2x/delegate/fetch.spec
87
+ - test/spec/unit/sbyc/codetree/name2x/delegate/name2class.spec
88
+ - test/spec/unit/sbyc/codetree/name2x/delegate/name2module.spec
89
+ - test/spec/unit/sbyc/codetree/name2x/delegate/name2name.spec
90
+ - test/spec/unit/sbyc/codetree/name2x/module_delegate/name2class.spec
91
+ - test/spec/unit/sbyc/codetree/name2x/module_delegate/name2module.spec
92
+ - test/spec/unit/sbyc/codetree/name2x/module_delegate/name2name.spec
93
+ - test/spec/unit/sbyc/codetree/parse.spec
78
94
  - test/spec/unit/sbyc/codetree/proc_parser/expr.spec
79
95
  - test/spec/unit/sbyc/codetree/proc_parser/parse.spec
96
+ - test/spec/unit/sbyc/codetree/producing/producer/add_extension.spec
80
97
  - test/spec/unit/sbyc/codetree/producing/producer/apply_args_conventions.spec
81
98
  - test/spec/unit/sbyc/codetree/producing/producer.spec
99
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods/default_options.spec
100
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods/prepare_options.spec
101
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods/trace.spec
102
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods/trace_rule_entered.spec
103
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods/trace_rule_exited.spec
104
+ - test/spec/unit/sbyc/codetree/producing/tracing_methods.spec
82
105
  - test/spec/unit/sbyc/codetree/rewriting/instance_methods/apply_args_conventions.spec
83
106
  - test/spec/unit/sbyc/codetree/rewriting/instance_methods/node.spec
84
107
  - test/spec/unit/sbyc/codetree/rewriting/instance_methods/rewrite.spec