alf 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +89 -0
- data/Gemfile.lock +6 -1
- data/README.md +35 -21
- data/TODO.md +0 -5
- data/alf.gemspec +2 -0
- data/alf.noespec +6 -4
- data/bin/alf +9 -13
- data/examples/{autonum.alf → operators/autonum.alf} +0 -0
- data/examples/{cities.rash → operators/cities.rash} +0 -0
- data/examples/{clip.alf → operators/clip.alf} +0 -0
- data/examples/{compact.alf → operators/compact.alf} +0 -0
- data/examples/{database.alf → operators/database.alf} +1 -1
- data/examples/{defaults.alf → operators/defaults.alf} +0 -0
- data/examples/{extend.alf → operators/extend.alf} +0 -0
- data/examples/{group.alf → operators/group.alf} +0 -0
- data/examples/{intersect.alf → operators/intersect.alf} +0 -0
- data/examples/{join.alf → operators/join.alf} +0 -0
- data/examples/operators/matching.alf +2 -0
- data/examples/{minus.alf → operators/minus.alf} +0 -0
- data/examples/operators/not_matching.alf +2 -0
- data/examples/{nulls.rash → operators/nulls.rash} +0 -0
- data/examples/{parts.rash → operators/parts.rash} +0 -0
- data/examples/{project.alf → operators/project.alf} +0 -0
- data/examples/{pseudo-with.alf → operators/pseudo-with.alf} +0 -0
- data/examples/{quota.alf → operators/quota.alf} +0 -0
- data/examples/operators/rank.alf +4 -0
- data/examples/{rename.alf → operators/rename.alf} +0 -0
- data/examples/{restrict.alf → operators/restrict.alf} +0 -0
- data/examples/{schema.yaml → operators/schema.yaml} +0 -0
- data/examples/{sort.alf → operators/sort.alf} +0 -0
- data/examples/{summarize.alf → operators/summarize.alf} +0 -0
- data/examples/{suppliers.rash → operators/suppliers.rash} +0 -0
- data/examples/{supplies.rash → operators/supplies.rash} +0 -0
- data/examples/{ungroup.alf → operators/ungroup.alf} +0 -0
- data/examples/{union.alf → operators/union.alf} +0 -0
- data/examples/{unwrap.alf → operators/unwrap.alf} +0 -0
- data/examples/{wrap.alf → operators/wrap.alf} +0 -0
- data/lib/alf.rb +837 -62
- data/lib/alf/loader.rb +2 -1
- data/lib/alf/text.rb +160 -0
- data/lib/alf/version.rb +1 -1
- data/lib/alf/yaml.rb +24 -0
- data/spec/integration/__database__/group.alf +3 -0
- data/spec/integration/__database__/parts.rash +6 -0
- data/spec/integration/__database__/suppliers.rash +5 -0
- data/spec/integration/__database__/supplies.rash +12 -0
- data/spec/integration/command/alf/alf_e.cmd +1 -0
- data/spec/integration/command/alf/alf_e.stdout +4 -0
- data/spec/integration/command/alf/alf_env.cmd +1 -0
- data/spec/integration/command/alf/alf_env.stdout +5 -0
- data/spec/integration/command/alf/alf_implicit.alf +1 -0
- data/spec/integration/command/alf/alf_implicit_exec.cmd +1 -0
- data/spec/integration/command/alf/alf_implicit_exec.stdout +4 -0
- data/spec/integration/command/alf/alf_r.cmd +1 -0
- data/spec/integration/command/alf/alf_r.stdout +5 -0
- data/spec/integration/command/alf/alf_version.cmd +1 -0
- data/spec/integration/command/alf/alf_version.stdout +2 -0
- data/spec/integration/command/alf/alf_yaml.cmd +1 -0
- data/spec/integration/command/alf/alf_yaml.stdout +22 -0
- data/spec/integration/command/alf/rel.rash +1 -0
- data/spec/integration/command/autonum/autonum_0.cmd +1 -0
- data/spec/integration/command/autonum/autonum_0.stdout +9 -0
- data/spec/integration/command/autonum/autonum_1.cmd +1 -0
- data/spec/integration/command/autonum/autonum_1.stdout +9 -0
- data/spec/integration/command/clip/clip_0.cmd +1 -0
- data/spec/integration/command/clip/clip_0.stdout +9 -0
- data/spec/integration/command/clip/clip_1.cmd +1 -0
- data/spec/integration/command/clip/clip_1.stdout +9 -0
- data/spec/integration/command/compact/compact_0.cmd +1 -0
- data/spec/integration/command/compact/compact_0.stdout +9 -0
- data/spec/integration/command/defaults/defaults_0.cmd +1 -0
- data/spec/integration/command/defaults/defaults_0.stdout +9 -0
- data/spec/integration/command/defaults/defaults_1.cmd +1 -0
- data/spec/integration/command/defaults/defaults_1.stdout +9 -0
- data/spec/integration/command/extend/extend_0.cmd +1 -0
- data/spec/integration/command/extend/extend_0.stdout +16 -0
- data/spec/integration/command/group/group_0.cmd +1 -0
- data/spec/integration/command/group/group_0.stdout +32 -0
- data/spec/integration/command/group/group_1.cmd +1 -0
- data/spec/integration/command/group/group_1.stdout +32 -0
- data/spec/integration/command/intersect/intersect_0.cmd +1 -0
- data/spec/integration/command/intersect/intersect_0.stdout +9 -0
- data/spec/integration/command/join/join_0.cmd +1 -0
- data/spec/integration/command/join/join_0.stdout +16 -0
- data/spec/integration/command/matching/matching_0.cmd +1 -0
- data/spec/integration/command/matching/matching_0.stdout +8 -0
- data/spec/integration/command/minus/minus_0.cmd +1 -0
- data/spec/integration/command/minus/minus_0.stdout +4 -0
- data/spec/integration/command/not-matching/not-matching_0.cmd +1 -0
- data/spec/integration/command/not-matching/not-matching_0.stdout +5 -0
- data/spec/integration/command/project/project_0.cmd +1 -0
- data/spec/integration/command/project/project_0.stdout +9 -0
- data/spec/integration/command/project/project_1.cmd +1 -0
- data/spec/integration/command/project/project_1.stdout +9 -0
- data/spec/integration/command/quota/quota_0.cmd +1 -0
- data/spec/integration/command/quota/quota_0.stdout +16 -0
- data/spec/integration/command/rank/rank_1.cmd +1 -0
- data/spec/integration/command/rank/rank_1.stdout +10 -0
- data/spec/integration/command/rank/rank_2.cmd +1 -0
- data/spec/integration/command/rank/rank_2.stdout +10 -0
- data/spec/integration/command/rank/rank_3.cmd +1 -0
- data/spec/integration/command/rank/rank_3.stdout +10 -0
- data/spec/integration/command/rank/rank_4.cmd +1 -0
- data/spec/integration/command/rank/rank_4.stdout +6 -0
- data/spec/integration/command/rank/rank_5.cmd +1 -0
- data/spec/integration/command/rank/rank_5.stdout +6 -0
- data/spec/integration/command/rename/rename_0.cmd +1 -0
- data/spec/integration/command/rename/rename_0.stdout +9 -0
- data/spec/integration/command/restrict/restrict_0.cmd +1 -0
- data/spec/integration/command/restrict/restrict_0.stdout +6 -0
- data/spec/integration/command/restrict/restrict_1.cmd +1 -0
- data/spec/integration/command/restrict/restrict_1.stdout +6 -0
- data/spec/integration/command/show/show_base.cmd +1 -0
- data/spec/integration/command/show/show_base.stdout +9 -0
- data/spec/integration/command/show/show_conflictual.cmd +1 -0
- data/spec/integration/command/show/show_conflictual.stdout +5 -0
- data/spec/integration/command/show/show_rash.cmd +1 -0
- data/spec/integration/command/show/show_rash.stdout +5 -0
- data/spec/integration/command/show/show_rash_2.cmd +1 -0
- data/spec/integration/command/show/show_rash_2.stdout +5 -0
- data/spec/integration/command/show/show_yaml.cmd +1 -0
- data/spec/integration/command/show/show_yaml.stdout +22 -0
- data/spec/integration/command/sort/sort_0.cmd +1 -0
- data/spec/integration/command/sort/sort_0.stdout +9 -0
- data/spec/integration/command/sort/sort_1.cmd +1 -0
- data/spec/integration/command/sort/sort_1.stdout +9 -0
- data/spec/integration/command/summarize/summarize_0.cmd +1 -0
- data/spec/integration/command/summarize/summarize_0.stdout +8 -0
- data/spec/integration/command/ungroup/ungroup_0.cmd +1 -0
- data/spec/integration/command/ungroup/ungroup_0.stdout +16 -0
- data/spec/integration/command/union/union_0.cmd +1 -0
- data/spec/integration/command/union/union_0.stdout +9 -0
- data/spec/integration/command/unwrap/unwrap_0.cmd +1 -0
- data/spec/integration/command/unwrap/unwrap_0.stdout +9 -0
- data/spec/integration/command/wrap/wrap_0.cmd +1 -0
- data/spec/integration/command/wrap/wrap_0.stdout +9 -0
- data/spec/integration/semantics/test_join.alf +9 -0
- data/spec/integration/{src → semantics}/test_minus.alf +0 -0
- data/spec/integration/{src → semantics}/test_project.alf +0 -0
- data/spec/integration/semantics/test_rank.alf +34 -0
- data/spec/integration/test_command.rb +36 -0
- data/spec/integration/test_examples.rb +11 -22
- data/spec/integration/test_semantics.rb +40 -0
- data/spec/regression/alf_file/__FILE__.alf +2 -0
- data/spec/regression/alf_file/suppliers.rash +5 -0
- data/spec/regression/alf_file/test___FILE__.rb +17 -0
- data/spec/regression/heading/test_heading_with_date.rb +12 -0
- data/spec/regression/lispy/test_compile.rb +14 -0
- data/spec/regression/relation/test_relation_with_date.rb +12 -0
- data/spec/regression/restrict/test_restrict_with_keywords.rb +17 -0
- data/spec/shared/a_value.rb +12 -0
- data/spec/shared/an_operator_class.rb +35 -0
- data/spec/spec_helper.rb +12 -34
- data/spec/unit/assumptions/test_file.rb +17 -0
- data/spec/unit/{test_assumptions.rb → assumptions/test_instance_eval.rb} +1 -1
- data/spec/unit/assumptions/test_scoping.rb +29 -0
- data/spec/unit/environment/test_folder.rb +6 -1
- data/spec/unit/operator/relational/matching/test_hash_based.rb +60 -0
- data/spec/unit/operator/relational/not_matching/test_hash_based.rb +37 -0
- data/spec/unit/operator/relational/test_rank.rb +50 -0
- data/spec/unit/operator/test_relational.rb +3 -0
- data/spec/unit/reader/test_alf_file.rb +7 -4
- data/spec/unit/reader/test_initialize.rb +60 -0
- data/spec/unit/relation/test_relops.rb +4 -0
- data/spec/unit/relation/test_to_a.rb +41 -0
- data/spec/unit/renderer/test_initialize.rb +60 -0
- data/spec/unit/test_environment.rb +38 -0
- data/spec/unit/test_heading.rb +38 -0
- data/spec/unit/test_reader.rb +5 -0
- data/spec/unit/test_relation.rb +31 -1
- data/spec/unit/test_renderer.rb +1 -1
- data/spec/unit/{renderer/text → text}/test_cell.rb +1 -1
- data/spec/unit/{renderer/text → text}/test_row.rb +1 -1
- data/spec/unit/{renderer/text → text}/test_table.rb +1 -1
- data/spec/unit/tools/test_ordering_key.rb +13 -0
- data/spec/unit/tools/test_parse_commandline_args.rb +47 -0
- data/spec/unit/tools/test_tuple_handle.rb +34 -2
- data/spec/unit/tools/test_varargs.rb +16 -0
- data/tasks/{spec_test.rake → integration_test.rake} +4 -32
- data/tasks/regression_test.rake +52 -0
- data/tasks/unit_test.rake +33 -58
- metadata +326 -66
- data/examples/runall.sh +0 -26
- data/lib/alf/relation.rb +0 -118
- data/lib/alf/renderer/text.rb +0 -153
- data/lib/alf/renderer/yaml.rb +0 -22
- data/spec/integration/test_alf_specs.rb +0 -37
@@ -0,0 +1 @@
|
|
1
|
+
alf --text unwrap suppliers -- loc_and_status
|
@@ -0,0 +1,9 @@
|
|
1
|
+
+------+-------+---------+--------+
|
2
|
+
| :sid | :name | :status | :city |
|
3
|
+
+------+-------+---------+--------+
|
4
|
+
| S1 | Smith | 20 | London |
|
5
|
+
| S2 | Jones | 10 | Paris |
|
6
|
+
| S3 | Blake | 30 | Paris |
|
7
|
+
| S4 | Clark | 20 | London |
|
8
|
+
| S5 | Adams | 30 | Athens |
|
9
|
+
+------+-------+---------+--------+
|
@@ -0,0 +1 @@
|
|
1
|
+
alf --text wrap suppliers -- city status loc_and_status
|
@@ -0,0 +1,9 @@
|
|
1
|
+
+------+-------+--------------------------------+
|
2
|
+
| :sid | :name | :loc_and_status |
|
3
|
+
+------+-------+--------------------------------+
|
4
|
+
| S1 | Smith | {:city=>"London", :status=>20} |
|
5
|
+
| S2 | Jones | {:city=>"Paris", :status=>10} |
|
6
|
+
| S3 | Blake | {:city=>"Paris", :status=>30} |
|
7
|
+
| S4 | Clark | {:city=>"London", :status=>20} |
|
8
|
+
| S5 | Adams | {:city=>"Athens", :status=>30} |
|
9
|
+
+------+-------+--------------------------------+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
(specify "(join xxx, DUM) is DUM",
|
2
|
+
(rel_equal DUM, (join :suppliers, DUM)))
|
3
|
+
(specify "(join DUM, xxx) is DUM",
|
4
|
+
(rel_equal DUM, (join DUM, :suppliers)))
|
5
|
+
|
6
|
+
(specify "(join DEE, xxx) is xxx",
|
7
|
+
(rel_equal :suppliers, (join DEE, :suppliers)))
|
8
|
+
(specify "(join xxx, DEE) is xxx",
|
9
|
+
(rel_equal :suppliers, (join :suppliers, DEE)))
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
input = rel(
|
2
|
+
{:id => 1, :weight => 10.0},
|
3
|
+
{:id => 2, :weight => 12.0},
|
4
|
+
{:id => 3, :weight => 12.0}
|
5
|
+
)
|
6
|
+
|
7
|
+
(specify "rank should respect < by default",
|
8
|
+
(rel_equal \
|
9
|
+
(rel (tuple :id => 1, :weight => 10.0, :rank => 0),
|
10
|
+
(tuple :id => 2, :weight => 12.0, :rank => 1),
|
11
|
+
(tuple :id => 3, :weight => 12.0, :rank => 1)),
|
12
|
+
(rank input, [:weight])))
|
13
|
+
|
14
|
+
(specify "rank should support a strict order",
|
15
|
+
(rel_equal \
|
16
|
+
(rel (tuple :id => 1, :weight => 10.0, :rank => 0),
|
17
|
+
(tuple :id => 2, :weight => 12.0, :rank => 1),
|
18
|
+
(tuple :id => 3, :weight => 12.0, :rank => 2)),
|
19
|
+
(rank input, [:weight, :id])))
|
20
|
+
|
21
|
+
(specify "rank should support a reverse order",
|
22
|
+
(rel_equal \
|
23
|
+
(rel (tuple :id => 1, :weight => 10.0, :rank => 2),
|
24
|
+
(tuple :id => 2, :weight => 12.0, :rank => 0),
|
25
|
+
(tuple :id => 3, :weight => 12.0, :rank => 0)),
|
26
|
+
(rank input, [[:weight, :desc]])))
|
27
|
+
|
28
|
+
(specify "rank should allow specifying a name",
|
29
|
+
(rel_equal \
|
30
|
+
(rel (tuple :id => 1, :weight => 10.0, :pos => 0),
|
31
|
+
(tuple :id => 2, :weight => 12.0, :pos => 1),
|
32
|
+
(tuple :id => 3, :weight => 12.0, :pos => 1)),
|
33
|
+
(rank input, [:weight], :pos)))
|
34
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "Alf's alf command / " do
|
3
|
+
|
4
|
+
Dir[_('command/**/*.cmd', __FILE__)].each do |input|
|
5
|
+
cmd = wlang(File.readlines(input).first, binding)
|
6
|
+
specify{ cmd.should =~ /^alf / }
|
7
|
+
|
8
|
+
describe "#{File.basename(input)}: #{cmd}" do
|
9
|
+
let(:argv) { Alf::Tools::parse_commandline_args(cmd)[1..-1] }
|
10
|
+
let(:stdout) { File.join(File.dirname(input), "#{File.basename(input, ".cmd")}.stdout") }
|
11
|
+
let(:expected) { wlang(File.read(stdout), binding) }
|
12
|
+
|
13
|
+
before{
|
14
|
+
$oldstdout = $stdout
|
15
|
+
$stdout = StringIO.new
|
16
|
+
}
|
17
|
+
after {
|
18
|
+
$stdout = $oldstdout
|
19
|
+
$oldstdout = nil
|
20
|
+
}
|
21
|
+
|
22
|
+
specify{
|
23
|
+
begin
|
24
|
+
dir = File.expand_path('../__database__', __FILE__)
|
25
|
+
main = Alf::Command::Main.new
|
26
|
+
main.environment = Alf::Environment.folder(dir)
|
27
|
+
main.run(argv, __FILE__)
|
28
|
+
rescue SystemExit
|
29
|
+
$stdout << SystemExit << "\n"
|
30
|
+
end
|
31
|
+
$stdout.string.should(eq(expected)) unless RUBY_VERSION < "1.9"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,26 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Alf's examples" do
|
4
|
-
|
5
|
-
shared_examples_for "An example" do
|
6
|
-
|
7
|
-
let(:env){ Environment.examples }
|
2
|
+
Dir["#{File.expand_path('../../../examples', __FILE__)}/**/*.alf"].each do |file|
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
Dir["#{File.expand_path('../../../examples', __FILE__)}/**/*.alf"].each do |file|
|
19
|
-
describe file do
|
20
|
-
subject{ file }
|
21
|
-
it_should_behave_like "An example"
|
22
|
-
end
|
4
|
+
describe "Alf example: #{file}" do
|
5
|
+
let(:example_path){ file }
|
6
|
+
let(:example_dir) { File.dirname(file) }
|
7
|
+
let(:example_env) { Alf::Environment.folder(example_dir) }
|
8
|
+
|
9
|
+
it "should run without error" do
|
10
|
+
Alf.lispy(example_env).compile(File.read(example_path)).to_rel
|
23
11
|
end
|
24
|
-
|
12
|
+
|
25
13
|
end
|
26
|
-
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "Alf's semantics tests" do
|
3
|
+
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
def rel_equal(x, y)
|
7
|
+
x = Alf::Environment.examples.dataset(x) if x.is_a?(Symbol)
|
8
|
+
y = Alf::Environment.examples.dataset(y) if y.is_a?(Symbol)
|
9
|
+
x.to_rel == y.to_rel
|
10
|
+
end
|
11
|
+
|
12
|
+
def specify(message, x)
|
13
|
+
raise message unless x
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
shared_examples_for "A semantics spec file" do
|
19
|
+
|
20
|
+
let(:lispy){
|
21
|
+
dir = File.expand_path('../__database__', __FILE__)
|
22
|
+
lispy = Alf.lispy(Alf::Environment.folder(dir))
|
23
|
+
lispy.ruby_extend(Helpers)
|
24
|
+
}
|
25
|
+
|
26
|
+
it "should work when executed with a Alf" do
|
27
|
+
lispy.compile(File.read(subject))
|
28
|
+
end
|
29
|
+
|
30
|
+
end # An example
|
31
|
+
|
32
|
+
|
33
|
+
Dir["#{File.expand_path('../semantics', __FILE__)}/**/*.alf"].each do |file|
|
34
|
+
describe file do
|
35
|
+
subject{ file }
|
36
|
+
it_should_behave_like "A semantics spec file"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
{:sid => 'S1', :name => 'Smith', :status => 20, :city => 'London'}
|
2
|
+
{:sid => 'S2', :name => 'Jones', :status => 10, :city => 'Paris'}
|
3
|
+
{:sid => 'S3', :name => 'Blake', :status => 30, :city => 'Paris'}
|
4
|
+
{:sid => 'S4', :name => 'Clark', :status => 20, :city => 'London'}
|
5
|
+
{:sid => 'S5', :name => 'Adams', :status => 30, :city => 'Athens'}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Reader::AlfFile do
|
4
|
+
subject{
|
5
|
+
Reader::AlfFile.new(File.expand_path("../__FILE__.alf", __FILE__), Environment.examples)
|
6
|
+
}
|
7
|
+
|
8
|
+
specify {
|
9
|
+
subject.to_rel.should == Relation[
|
10
|
+
{:city => "London"},
|
11
|
+
{:city => "Paris"},
|
12
|
+
{:city => "Athens"}
|
13
|
+
]
|
14
|
+
}
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "Lispy.compile" do
|
3
|
+
|
4
|
+
it "should use a clean binding" do
|
5
|
+
p = Alf::Lispy.compile("lambda{ path }", "a path")
|
6
|
+
lambda{ p.call }.should raise_error(NameError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should resolve __FILE__ correctly" do
|
10
|
+
p = Alf::Lispy.compile("__FILE__", "a path")
|
11
|
+
p.should == "a path"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe "(restrict xxx, :keyword => ...)" do
|
4
|
+
|
5
|
+
it "should support using a keyword on Relation" do
|
6
|
+
rel = Relation[{:when => "now"}]
|
7
|
+
rel.restrict(:when => "now").should eq(rel)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should support using a keyword on Lispy" do
|
11
|
+
Alf.lispy(Environment.examples).evaluate do
|
12
|
+
(restrict (extend :suppliers, {:when => lambda{"notnow"}}), {:when => "now"})
|
13
|
+
end.should eq(Relation::DUM)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
shared_examples_for "A value" do
|
2
|
+
|
3
|
+
it "should have a inspect/class.parse that lead to equal values" do
|
4
|
+
Kernel.eval(subject.inspect).should eq(subject)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should act a valid Hash keys" do
|
8
|
+
dup = Kernel.eval(subject.inspect)
|
9
|
+
{subject => true, dup => false}.size.should == 1
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
shared_examples_for "An operator class" do
|
2
|
+
|
3
|
+
it "should not have public set_args, _each and _prepare methods" do
|
4
|
+
operator_class.public_method_defined?(:set_args).should be_false
|
5
|
+
operator_class.public_method_defined?(:_each).should be_false
|
6
|
+
operator_class.public_method_defined?(:_prepare).should be_false
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a public run method" do
|
10
|
+
operator_class.public_method_defined?(:run).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a public pipe method" do
|
14
|
+
operator_class.public_method_defined?(:pipe).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a public each method" do
|
18
|
+
operator_class.public_method_defined?(:each).should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a unary? class method" do
|
22
|
+
operator_class.should respond_to(:unary?)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a binary? class method" do
|
26
|
+
operator_class.should respond_to(:binary?)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should implement unary? and binary? accurately" do
|
30
|
+
operator_class.unary?.should_not eq(operator_class.binary?)
|
31
|
+
operator_class.unary?.should eq(operator_class.ancestors.include?(Alf::Operator::Unary))
|
32
|
+
operator_class.binary?.should eq(operator_class.ancestors.include?(Alf::Operator::Binary))
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,44 +1,22 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
|
2
2
|
require 'alf'
|
3
|
+
require "rspec"
|
3
4
|
|
4
5
|
Alf::Lispy.extend(Alf::Lispy)
|
5
6
|
|
6
7
|
def rel(*args)
|
7
8
|
Alf::Relation.coerce(args)
|
8
9
|
end
|
10
|
+
def tuple(h)
|
11
|
+
h
|
12
|
+
end
|
13
|
+
def _(path, file)
|
14
|
+
File.expand_path("../#{path}", file)
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
it "should not have public set_args, _each and _prepare methods" do
|
13
|
-
operator_class.public_method_defined?(:set_args).should be_false
|
14
|
-
operator_class.public_method_defined?(:_each).should be_false
|
15
|
-
operator_class.public_method_defined?(:_prepare).should be_false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have a public run method" do
|
19
|
-
operator_class.public_method_defined?(:run).should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should have a public pipe method" do
|
23
|
-
operator_class.public_method_defined?(:pipe).should be_true
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should have a public each method" do
|
27
|
-
operator_class.public_method_defined?(:each).should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should have a unary? class method" do
|
31
|
-
operator_class.should respond_to(:unary?)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have a binary? class method" do
|
35
|
-
operator_class.should respond_to(:binary?)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should implement unary? and binary? accurately" do
|
39
|
-
operator_class.unary?.should_not eq(operator_class.binary?)
|
40
|
-
operator_class.unary?.should eq(operator_class.ancestors.include?(Alf::Operator::Unary))
|
41
|
-
operator_class.binary?.should eq(operator_class.ancestors.include?(Alf::Operator::Binary))
|
42
|
-
end
|
43
|
-
|
17
|
+
def wlang(str, binding)
|
18
|
+
str.gsub(/\$\(([\S]+)\)/){ Kernel.eval($1, binding) }
|
44
19
|
end
|
20
|
+
|
21
|
+
require 'shared/an_operator_class'
|
22
|
+
require 'shared/a_value'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "__FILE__" do
|
3
|
+
|
4
|
+
describe "when used with eval within same file" do
|
5
|
+
let(:src){ "__FILE__" }
|
6
|
+
subject{ Kernel.eval(src, binding, __FILE__) }
|
7
|
+
it { should == __FILE__ }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "when used with eval from other file" do
|
11
|
+
let(:src){ "__FILE__" }
|
12
|
+
subject{ Kernel.eval(src, binding, "hello.rb") }
|
13
|
+
it { should == "hello.rb" }
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe :clojures_and_scoping do
|
3
|
+
|
4
|
+
class Foo
|
5
|
+
|
6
|
+
def a_method
|
7
|
+
:inside
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(lamb)
|
11
|
+
if RUBY_VERSION <= "1.9"
|
12
|
+
self.instance_eval(&lamb)
|
13
|
+
else
|
14
|
+
self.instance_exec(&lamb)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "when no name clash" do
|
21
|
+
Foo.new.evaluate(lambda{ a_method }).should == :inside
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "with name clash" do
|
25
|
+
a_method = :outside
|
26
|
+
Foo.new.evaluate(Proc.new{ a_method }).should == :outside
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|