alf-shell 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +35 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +13 -0
- data/README.md +11 -0
- data/Rakefile +11 -0
- data/bin/alf +17 -0
- data/lib/alf-shell.rb +1 -0
- data/lib/alf/shell.rb +48 -0
- data/lib/alf/shell/command.rb +21 -0
- data/lib/alf/shell/command/exec.rb +16 -0
- data/lib/alf/shell/command/help.rb +30 -0
- data/lib/alf/shell/command/main.rb +175 -0
- data/lib/alf/shell/command/show.rb +49 -0
- data/lib/alf/shell/doc_manager.rb +83 -0
- data/lib/alf/shell/ext/signature.rb +45 -0
- data/lib/alf/shell/from_argv.rb +78 -0
- data/lib/alf/shell/loader.rb +2 -0
- data/lib/alf/shell/operator.rb +63 -0
- data/lib/alf/shell/support.rb +28 -0
- data/lib/alf/shell/version.rb +16 -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__/suppliers_csv.csv +6 -0
- data/spec/integration/__database__/supplies.rash +12 -0
- data/spec/integration/alf/alf.db +0 -0
- data/spec/integration/alf/alf_db.cmd +1 -0
- data/spec/integration/alf/alf_db.stdout +5 -0
- data/spec/integration/alf/alf_e.cmd +1 -0
- data/spec/integration/alf/alf_e.stdout +4 -0
- data/spec/integration/alf/alf_help.cmd +1 -0
- data/spec/integration/alf/alf_help.stdout +72 -0
- data/spec/integration/alf/alf_json.cmd +1 -0
- data/spec/integration/alf/alf_json.stdout +1 -0
- data/spec/integration/alf/alf_r.cmd +1 -0
- data/spec/integration/alf/alf_r.stdout +5 -0
- data/spec/integration/alf/alf_version.cmd +1 -0
- data/spec/integration/alf/alf_version.stdout +2 -0
- data/spec/integration/alf/alf_yaml.cmd +1 -0
- data/spec/integration/alf/alf_yaml.stdout +22 -0
- data/spec/integration/alf/rel.rash +1 -0
- data/spec/integration/autonum/autonum_0.cmd +1 -0
- data/spec/integration/autonum/autonum_0.stdout +9 -0
- data/spec/integration/autonum/autonum_1.cmd +1 -0
- data/spec/integration/autonum/autonum_1.stdout +9 -0
- data/spec/integration/clip/clip_0.cmd +1 -0
- data/spec/integration/clip/clip_0.stdout +9 -0
- data/spec/integration/clip/clip_1.cmd +1 -0
- data/spec/integration/clip/clip_1.stdout +9 -0
- data/spec/integration/coerce/coerce_1.cmd +1 -0
- data/spec/integration/coerce/coerce_1.stdout +5 -0
- data/spec/integration/compact/compact_0.cmd +1 -0
- data/spec/integration/compact/compact_0.stdout +9 -0
- data/spec/integration/defaults/defaults_0.cmd +1 -0
- data/spec/integration/defaults/defaults_0.stdout +9 -0
- data/spec/integration/defaults/defaults_1.cmd +1 -0
- data/spec/integration/defaults/defaults_1.stdout +9 -0
- data/spec/integration/defaults/defaults_2.cmd +1 -0
- data/spec/integration/defaults/defaults_2.stdout +9 -0
- data/spec/integration/extend/extend_0.cmd +1 -0
- data/spec/integration/extend/extend_0.stdout +16 -0
- data/spec/integration/generator/generator_1.cmd +1 -0
- data/spec/integration/generator/generator_1.stdout +10 -0
- data/spec/integration/generator/generator_2.cmd +1 -0
- data/spec/integration/generator/generator_2.stdout +5 -0
- data/spec/integration/generator/generator_3.cmd +1 -0
- data/spec/integration/generator/generator_3.stdout +5 -0
- data/spec/integration/group/group_0.cmd +1 -0
- data/spec/integration/group/group_0.stdout +32 -0
- data/spec/integration/group/group_1.cmd +1 -0
- data/spec/integration/group/group_1.stdout +32 -0
- data/spec/integration/help/help_1.cmd +1 -0
- data/spec/integration/help/help_1.stdout +25 -0
- data/spec/integration/intersect/intersect_0.cmd +1 -0
- data/spec/integration/intersect/intersect_0.stdout +9 -0
- data/spec/integration/join/join_0.cmd +1 -0
- data/spec/integration/join/join_0.stdout +16 -0
- data/spec/integration/matching/matching_0.cmd +1 -0
- data/spec/integration/matching/matching_0.stdout +8 -0
- data/spec/integration/minus/minus_0.cmd +1 -0
- data/spec/integration/minus/minus_0.stdout +4 -0
- data/spec/integration/not-matching/not-matching_0.cmd +1 -0
- data/spec/integration/not-matching/not-matching_0.stdout +5 -0
- data/spec/integration/project/project_0.cmd +1 -0
- data/spec/integration/project/project_0.stdout +9 -0
- data/spec/integration/project/project_1.cmd +1 -0
- data/spec/integration/project/project_1.stdout +9 -0
- data/spec/integration/quota/quota_0.cmd +1 -0
- data/spec/integration/quota/quota_0.stdout +16 -0
- data/spec/integration/rank/rank_1.cmd +1 -0
- data/spec/integration/rank/rank_1.stdout +10 -0
- data/spec/integration/rank/rank_2.cmd +1 -0
- data/spec/integration/rank/rank_2.stdout +10 -0
- data/spec/integration/rank/rank_3.cmd +1 -0
- data/spec/integration/rank/rank_3.stdout +10 -0
- data/spec/integration/rank/rank_4.cmd +1 -0
- data/spec/integration/rank/rank_4.stdout +6 -0
- data/spec/integration/rank/rank_5.cmd +1 -0
- data/spec/integration/rank/rank_5.stdout +6 -0
- data/spec/integration/rename/rename_0.cmd +1 -0
- data/spec/integration/rename/rename_0.stdout +9 -0
- data/spec/integration/restrict/restrict_0.cmd +1 -0
- data/spec/integration/restrict/restrict_0.stdout +6 -0
- data/spec/integration/restrict/restrict_1.cmd +1 -0
- data/spec/integration/restrict/restrict_1.stdout +6 -0
- data/spec/integration/show/show_base.cmd +1 -0
- data/spec/integration/show/show_base.stdout +5 -0
- data/spec/integration/show/show_base_sort_1.cmd +1 -0
- data/spec/integration/show/show_base_sort_1.stdout +9 -0
- data/spec/integration/show/show_base_sort_2.cmd +1 -0
- data/spec/integration/show/show_base_sort_2.stdout +9 -0
- data/spec/integration/show/show_conflictual.cmd +1 -0
- data/spec/integration/show/show_conflictual.stdout +5 -0
- data/spec/integration/show/show_ff.cmd +1 -0
- data/spec/integration/show/show_ff.stdout +10 -0
- data/spec/integration/show/show_rash.cmd +1 -0
- data/spec/integration/show/show_rash.stdout +5 -0
- data/spec/integration/show/show_rash_pretty.cmd +1 -0
- data/spec/integration/show/show_rash_pretty.stdout +30 -0
- data/spec/integration/show/show_yaml.cmd +1 -0
- data/spec/integration/show/show_yaml.stdout +22 -0
- data/spec/integration/sort/sort_0.cmd +1 -0
- data/spec/integration/sort/sort_0.stdout +9 -0
- data/spec/integration/sort/sort_1.cmd +1 -0
- data/spec/integration/sort/sort_1.stdout +9 -0
- data/spec/integration/sort/sort_2.cmd +1 -0
- data/spec/integration/sort/sort_2.stdout +9 -0
- data/spec/integration/sort/sort_3.cmd +1 -0
- data/spec/integration/sort/sort_3.stdout +9 -0
- data/spec/integration/summarize/summarize_0.cmd +1 -0
- data/spec/integration/summarize/summarize_0.stdout +8 -0
- data/spec/integration/test_shell.rb +56 -0
- data/spec/integration/union/union_0.cmd +1 -0
- data/spec/integration/union/union_0.stdout +9 -0
- data/spec/integration/unwrap/unwrap_0.cmd +1 -0
- data/spec/integration/unwrap/unwrap_0.stdout +9 -0
- data/spec/integration/wrap/wrap_0.cmd +1 -0
- data/spec/integration/wrap/wrap_0.stdout +9 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_shell.rb +10 -0
- data/spec/unit/doc_manager/dynamic.md +1 -0
- data/spec/unit/doc_manager/example.md +1 -0
- data/spec/unit/doc_manager/example_1.txt +11 -0
- data/spec/unit/doc_manager/static.md +1 -0
- data/spec/unit/doc_manager/test_call.rb +43 -0
- data/spec/unit/ext/signature/test_argv2args.rb +82 -0
- data/spec/unit/ext/signature/test_to_shell.rb +103 -0
- data/spec/unit/from_argv/test_to_attr_list.rb +30 -0
- data/spec/unit/from_argv/test_to_attr_name.rb +27 -0
- data/spec/unit/from_argv/test_to_boolean.rb +32 -0
- data/spec/unit/from_argv/test_to_heading.rb +37 -0
- data/spec/unit/from_argv/test_to_ordering.rb +28 -0
- data/spec/unit/from_argv/test_to_predicate.rb +26 -0
- data/spec/unit/from_argv/test_to_renaming.rb +23 -0
- data/spec/unit/from_argv/test_to_size.rb +32 -0
- data/spec/unit/from_argv/test_to_summarization.rb +19 -0
- data/spec/unit/from_argv/test_to_tuple_computation.rb +18 -0
- data/spec/unit/from_argv/test_to_tuple_expression.rb +38 -0
- data/spec/unit/main/test_class_methods.rb +44 -0
- data/spec/unit/operator/test_autonum.rb +28 -0
- data/spec/unit/operator/test_clip.rb +29 -0
- data/spec/unit/operator/test_coerce.rb +22 -0
- data/spec/unit/operator/test_compact.rb +16 -0
- data/spec/unit/operator/test_defaults.rb +29 -0
- data/spec/unit/operator/test_extend.rb +21 -0
- data/spec/unit/operator/test_generator.rb +37 -0
- data/spec/unit/operator/test_group.rb +32 -0
- data/spec/unit/operator/test_infer_heading.rb +16 -0
- data/spec/unit/operator/test_intersect.rb +18 -0
- data/spec/unit/operator/test_join.rb +18 -0
- data/spec/unit/operator/test_matching.rb +18 -0
- data/spec/unit/operator/test_minus.rb +18 -0
- data/spec/unit/operator/test_not_matching.rb +18 -0
- data/spec/unit/operator/test_project.rb +38 -0
- data/spec/unit/operator/test_quota.rb +23 -0
- data/spec/unit/operator/test_rank.rb +30 -0
- data/spec/unit/operator/test_rename.rb +21 -0
- data/spec/unit/operator/test_restrict.rb +36 -0
- data/spec/unit/operator/test_sort.rb +49 -0
- data/spec/unit/operator/test_summarize.rb +30 -0
- data/spec/unit/operator/test_ungroup.rb +28 -0
- data/spec/unit/operator/test_union.rb +18 -0
- data/spec/unit/operator/test_unwrap.rb +28 -0
- data/spec/unit/operator/test_wrap.rb +30 -0
- data/tasks/gem.rake +8 -0
- data/tasks/test.rake +6 -0
- metadata +317 -0
@@ -0,0 +1 @@
|
|
1
|
+
Hello
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Shell
|
4
|
+
describe DocManager, ".call" do
|
5
|
+
|
6
|
+
let(:dm){ @dm ||= DocManager.new }
|
7
|
+
let(:cmd){ Alf::Shell::Show }
|
8
|
+
subject{
|
9
|
+
dm.call(cmd, {})
|
10
|
+
}
|
11
|
+
|
12
|
+
describe "on a static file" do
|
13
|
+
before{
|
14
|
+
def dm.find_file(cmd);
|
15
|
+
File.expand_path('../static.md', __FILE__)
|
16
|
+
end
|
17
|
+
}
|
18
|
+
it { should eq("Hello\n") }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "on a dynamic file" do
|
22
|
+
before{
|
23
|
+
def dm.find_file(cmd);
|
24
|
+
File.expand_path('../dynamic.md', __FILE__)
|
25
|
+
end
|
26
|
+
}
|
27
|
+
it { should eq("show\n") }
|
28
|
+
end
|
29
|
+
|
30
|
+
unless RUBY_VERSION < "1.9"
|
31
|
+
describe "on an example file" do
|
32
|
+
before{
|
33
|
+
def dm.find_file(cmd);
|
34
|
+
File.expand_path('../example.md', __FILE__)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
it { should eq(File.read(File.expand_path('../example_1.txt', __FILE__))) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Algebra
|
4
|
+
describe Signature, "#argv2args" do
|
5
|
+
|
6
|
+
class FakeOp
|
7
|
+
attr_accessor :operands
|
8
|
+
end
|
9
|
+
before{
|
10
|
+
signature.install
|
11
|
+
}
|
12
|
+
subject{
|
13
|
+
signature.argv2args(argv)
|
14
|
+
}
|
15
|
+
|
16
|
+
context "on a signature with arguments only" do
|
17
|
+
let(:signature){
|
18
|
+
Signature.new(FakeOp) do |s|
|
19
|
+
s.argument :proj, AttrList
|
20
|
+
end
|
21
|
+
}
|
22
|
+
let(:argv){ %w{operand -- hello world} }
|
23
|
+
|
24
|
+
it 'should return the expected triple' do
|
25
|
+
[["operand"], [AttrList[:hello, :world]], {}]
|
26
|
+
end
|
27
|
+
end # arguments only
|
28
|
+
|
29
|
+
context "with default values for arguments" do
|
30
|
+
let(:signature){
|
31
|
+
Signature.new(FakeOp) do |s|
|
32
|
+
s.argument :attrname, AttrName, :autonum
|
33
|
+
end
|
34
|
+
}
|
35
|
+
let(:arguments){ subject[1] }
|
36
|
+
|
37
|
+
context 'and passed' do
|
38
|
+
let(:argv){ %w{operand -- hello} }
|
39
|
+
|
40
|
+
it 'should not use the default value' do
|
41
|
+
arguments.should eq([:hello])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'and not passed' do
|
46
|
+
let(:argv){ %w{operand} }
|
47
|
+
|
48
|
+
it 'should use the default value' do
|
49
|
+
arguments.should eq([:autonum])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end # default values for arguments
|
53
|
+
|
54
|
+
context "on a signature with options" do
|
55
|
+
let(:signature){
|
56
|
+
Signature.new(FakeOp) do |s|
|
57
|
+
s.argument :key, AttrList, []
|
58
|
+
s.option :allbut, Boolean, false
|
59
|
+
end
|
60
|
+
}
|
61
|
+
let(:options){ subject[2] }
|
62
|
+
|
63
|
+
context "when no option is provided" do
|
64
|
+
let(:argv){ %w{operand -- hello world} }
|
65
|
+
|
66
|
+
it 'should use the default values for options' do
|
67
|
+
options.should eq({:allbut => false})
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when option is provided" do
|
72
|
+
let(:argv){ %w{operand --allbut -- hello world} }
|
73
|
+
|
74
|
+
it 'should not use the default values for options' do
|
75
|
+
options.should eq({:allbut => true})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end # signature with options
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Algebra
|
4
|
+
describe Signature, '#to_shell' do
|
5
|
+
|
6
|
+
subject{ signature.to_shell }
|
7
|
+
|
8
|
+
describe "on a nullary signature" do
|
9
|
+
let(:clazz){ Generator }
|
10
|
+
|
11
|
+
describe "on an empty signature" do
|
12
|
+
let(:signature){ Signature.new(clazz){|s|} }
|
13
|
+
it{ should eq("alf generator") }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "on an option-only signature" do
|
17
|
+
let(:signature){
|
18
|
+
Signature.new(clazz) do |s|
|
19
|
+
s.option :allbut, Boolean
|
20
|
+
end
|
21
|
+
}
|
22
|
+
it{ should eq("alf generator [--allbut]") }
|
23
|
+
end
|
24
|
+
|
25
|
+
end # nullary signature
|
26
|
+
|
27
|
+
describe "on a monadic operator" do
|
28
|
+
let(:clazz){ Coerce }
|
29
|
+
|
30
|
+
describe "on an empty signature" do
|
31
|
+
let(:signature){ Signature.new(clazz){|s|} }
|
32
|
+
it{ should eq("alf coerce [OPERAND]") }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "on an option-only signature" do
|
36
|
+
let(:signature){
|
37
|
+
Signature.new(clazz) do |s|
|
38
|
+
s.option :allbut, Boolean
|
39
|
+
end
|
40
|
+
}
|
41
|
+
it{ should eq("alf coerce [--allbut] [OPERAND]") }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "on an option-only signature with multiple options" do
|
45
|
+
let(:signature){
|
46
|
+
Signature.new(clazz) do |s|
|
47
|
+
s.option :allbut, Boolean
|
48
|
+
s.option :newname, AttrName
|
49
|
+
end
|
50
|
+
}
|
51
|
+
it{ should eq("alf coerce [--allbut] [--newname=NEWNAME] [OPERAND]") }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "on a signature with one argument only" do
|
55
|
+
let(:signature){
|
56
|
+
Signature.new(clazz) do |s|
|
57
|
+
s.argument :proj, AttrList
|
58
|
+
end
|
59
|
+
}
|
60
|
+
it{ should eq("alf coerce [OPERAND] -- PROJ") }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "on a signature with multiple arguments" do
|
64
|
+
let(:signature){
|
65
|
+
Signature.new(clazz) do |s|
|
66
|
+
s.argument :proj, AttrList
|
67
|
+
s.argument :ordering, Ordering
|
68
|
+
end
|
69
|
+
}
|
70
|
+
it{ should eq("alf coerce [OPERAND] -- PROJ -- ORDERING") }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "on a full signature" do
|
74
|
+
let(:signature){
|
75
|
+
Signature.new(clazz) do |s|
|
76
|
+
s.argument :proj, AttrList
|
77
|
+
s.argument :ordering, Ordering
|
78
|
+
s.option :allbut, Boolean
|
79
|
+
s.option :newname, AttrName
|
80
|
+
end
|
81
|
+
}
|
82
|
+
it{ should eq("alf coerce [--allbut] [--newname=NEWNAME] [OPERAND] -- PROJ -- ORDERING") }
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "on a dyadic operator" do
|
88
|
+
let(:clazz){ Join }
|
89
|
+
|
90
|
+
describe "on an option-only signature" do
|
91
|
+
let(:signature){
|
92
|
+
Signature.new(clazz) do |s|
|
93
|
+
s.option :allbut, Boolean
|
94
|
+
end
|
95
|
+
}
|
96
|
+
it{ should eq("alf join [--allbut] [LEFT] RIGHT") }
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, AttrList)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, AttrList) }
|
6
|
+
|
7
|
+
context "on an empty array" do
|
8
|
+
let(:argv){ [] }
|
9
|
+
it{ should eq(AttrList.new([])) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "on a singleton" do
|
13
|
+
let(:argv){ ["hello"] }
|
14
|
+
it{ should eq(AttrList.new([:hello])) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "on multiple strings" do
|
18
|
+
let(:argv){ ["hello", "world"] }
|
19
|
+
it{ should eq(AttrList.new([:hello, :world])) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when passed an unrecognized argument" do
|
23
|
+
let(:argv){ :not_recognized }
|
24
|
+
specify{
|
25
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, AttrName)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, AttrName) }
|
6
|
+
|
7
|
+
context "with a String" do
|
8
|
+
let(:argv){ %w{hello} }
|
9
|
+
it{ should eq(:hello) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with nothing" do
|
13
|
+
let(:argv){ %w{} }
|
14
|
+
specify{
|
15
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with more than one string" do
|
20
|
+
let(:argv){ %w{hello world} }
|
21
|
+
specify{
|
22
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, Boolean)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, Boolean) }
|
6
|
+
|
7
|
+
context "with a String" do
|
8
|
+
let(:argv){ %w{true} }
|
9
|
+
it{ should eq(true) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with nothing" do
|
13
|
+
let(:argv){ %w{} }
|
14
|
+
it{ should eq(false) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with an invalid string" do
|
18
|
+
let(:argv){ %w{hello} }
|
19
|
+
specify{
|
20
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with more than one string" do
|
25
|
+
let(:argv){ %w{hello world} }
|
26
|
+
specify{
|
27
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, Heading)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, Heading) }
|
6
|
+
|
7
|
+
context "on an empty array" do
|
8
|
+
let(:argv){ [] }
|
9
|
+
it{ should eq(Heading.new({})) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "on a single pair" do
|
13
|
+
let(:argv){ ["name", "String"] }
|
14
|
+
it{ should eq(Heading.new :name => String) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "on a double pair" do
|
18
|
+
let(:argv){ ["name", "String", "age", "Fixnum"] }
|
19
|
+
it{ should eq(Heading.new :name => String, :age => Fixnum) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on odd number of strings" do
|
23
|
+
let(:argv){ ["hello", "world", "foo"] }
|
24
|
+
specify{
|
25
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when passed an unrecognized argument" do
|
30
|
+
let(:argv){ :not_recognized }
|
31
|
+
specify{
|
32
|
+
lambda{ subject }.should raise_error(Myrrha::Error)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, Ordering)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, Ordering) }
|
6
|
+
|
7
|
+
context "on an empty array" do
|
8
|
+
let(:argv){ [] }
|
9
|
+
it{ should eq(Ordering.new([])) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "on a singleton" do
|
13
|
+
let(:argv){ ["hello"] }
|
14
|
+
it{ should eq(Ordering.new([[:hello, :asc]])) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "on multiple strings without explit directions" do
|
18
|
+
let(:argv){ ["hello", "world"] }
|
19
|
+
it{ should eq(Ordering.new([[:hello, :asc], [:world, :asc]])) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on multiple strings with explit directions" do
|
23
|
+
let(:argv){ ["hello", "asc", "world", "desc"] }
|
24
|
+
it{ should eq(Ordering.new([[:hello, :asc], [:world, :desc]])) }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, Predicate)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, Predicate) }
|
6
|
+
|
7
|
+
describe "from a singleton Array" do
|
8
|
+
let(:argv){ ["status == 10"] }
|
9
|
+
|
10
|
+
specify{
|
11
|
+
subject.expr.should be_a(Predicate::Native)
|
12
|
+
subject.to_ruby_literal.should eq("lambda{ status == 10 }")
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "from an Array with coercion" do
|
17
|
+
let(:argv){ ["status", "10"] }
|
18
|
+
|
19
|
+
specify{
|
20
|
+
subject.expr.should be_a(Predicate::Eq)
|
21
|
+
subject.expr.should eq([:eq, [:var_ref, :status], [:literal, 10]])
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
describe Shell, ".from_argv(argv, Renaming)" do
|
4
|
+
|
5
|
+
subject{ Shell.from_argv(argv, Renaming) }
|
6
|
+
|
7
|
+
context "from an empty Array" do
|
8
|
+
let(:argv){ [] }
|
9
|
+
it{ should eq(Renaming.new({})) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "from an Array of two elements" do
|
13
|
+
let(:argv){ ["old", "new"] }
|
14
|
+
it{ should eq(Renaming.new(:old => :new)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "from an Array of four elements" do
|
18
|
+
let(:argv){ ["old", "new", "hello", "world"] }
|
19
|
+
it{ should eq(Renaming.new(:old => :new, :hello => :world)) }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|