amp-core 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +17 -0
  6. data/Rakefile +67 -0
  7. data/VERSION +1 -0
  8. data/features/amp-core.feature +9 -0
  9. data/features/step_definitions/amp-core_steps.rb +0 -0
  10. data/features/support/env.rb +4 -0
  11. data/lib/amp-core.rb +53 -0
  12. data/lib/amp-core/command_ext/repository_loading.rb +31 -0
  13. data/lib/amp-core/repository/abstract/abstract_changeset.rb +113 -0
  14. data/lib/amp-core/repository/abstract/abstract_local_repo.rb +208 -0
  15. data/lib/amp-core/repository/abstract/abstract_staging_area.rb +202 -0
  16. data/lib/amp-core/repository/abstract/abstract_versioned_file.rb +116 -0
  17. data/lib/amp-core/repository/abstract/common_methods/changeset.rb +185 -0
  18. data/lib/amp-core/repository/abstract/common_methods/local_repo.rb +293 -0
  19. data/lib/amp-core/repository/abstract/common_methods/staging_area.rb +248 -0
  20. data/lib/amp-core/repository/abstract/common_methods/versioned_file.rb +87 -0
  21. data/lib/amp-core/repository/generic_repo_picker.rb +94 -0
  22. data/lib/amp-core/repository/repository.rb +41 -0
  23. data/lib/amp-core/support/encoding_utils.rb +46 -0
  24. data/lib/amp-core/support/platform_utils.rb +92 -0
  25. data/lib/amp-core/support/rooted_opener.rb +143 -0
  26. data/lib/amp-core/support/string_utils.rb +86 -0
  27. data/lib/amp-core/templates/git/blank.log.erb +18 -0
  28. data/lib/amp-core/templates/git/default.log.erb +18 -0
  29. data/lib/amp-core/templates/mercurial/blank.commit.erb +23 -0
  30. data/lib/amp-core/templates/mercurial/blank.log.erb +18 -0
  31. data/lib/amp-core/templates/mercurial/default.commit.erb +23 -0
  32. data/lib/amp-core/templates/mercurial/default.log.erb +26 -0
  33. data/lib/amp-core/templates/template.rb +202 -0
  34. data/spec/amp-core_spec.rb +11 -0
  35. data/spec/command_ext_specs/repository_loading_spec.rb +64 -0
  36. data/spec/command_ext_specs/spec_helper.rb +1 -0
  37. data/spec/repository_specs/repository_spec.rb +41 -0
  38. data/spec/repository_specs/spec_helper.rb +1 -0
  39. data/spec/spec.opts +1 -0
  40. data/spec/spec_helper.rb +14 -0
  41. data/spec/support_specs/encoding_utils_spec.rb +69 -0
  42. data/spec/support_specs/platform_utils_spec.rb +33 -0
  43. data/spec/support_specs/spec_helper.rb +1 -0
  44. data/spec/support_specs/string_utils_spec.rb +44 -0
  45. data/test/test_templates.rb +81 -0
  46. metadata +157 -0
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb'))
@@ -0,0 +1,41 @@
1
+ ##################################################################
2
+ # Licensing Information #
3
+ # #
4
+ # The following code is licensed, as standalone code, under #
5
+ # the Ruby License, unless otherwise directed within the code. #
6
+ # #
7
+ # For information on the license of this code when distributed #
8
+ # with and used in conjunction with the other modules in the #
9
+ # Amp project, please see the root-level LICENSE file. #
10
+ # #
11
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
+ # #
13
+ ##################################################################
14
+
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
16
+
17
+ describe Amp::Core::Repositories do
18
+ describe '#pick' do
19
+ before do
20
+ mock1, mock2, mock3 = mock(:r1), mock(:r2), mock(:r3)
21
+ subklass1 = Class.new(Amp::Core::Repositories::GenericRepoPicker) do
22
+ define_method(:repo_in_dir?) { |path| false }
23
+ define_method(:pick) { |config, path, create| mock1 }
24
+ end
25
+ subklass2 = Class.new(Amp::Core::Repositories::GenericRepoPicker) do
26
+ define_method(:repo_in_dir?) { |path| true }
27
+ define_method(:pick) { |config, path, create| mock2 }
28
+ end
29
+ subklass3 = Class.new(Amp::Core::Repositories::GenericRepoPicker) do
30
+ define_method(:repo_in_dir?) { |path| true }
31
+ define_method(:pick) { |config, path, create| mock3 }
32
+ end
33
+ @expected = mock2
34
+ end
35
+
36
+ it 'Picks the first loaded Repository type to match.' do
37
+ p Amp::Core::Repositories::GenericRepoPicker.all_pickers
38
+ Amp::Core::Repositories.pick(nil, nil, false).should == @expected
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb'))
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'amp-front'
6
+ require 'amp-core'
7
+ require 'spec'
8
+ require 'spec/autorun'
9
+
10
+ Amp::Plugins::Core.new.load!
11
+
12
+ Spec::Runner.configure do |config|
13
+
14
+ end
@@ -0,0 +1,69 @@
1
+ ##################################################################
2
+ # Licensing Information #
3
+ # #
4
+ # The following code is licensed, as standalone code, under #
5
+ # the Ruby License, unless otherwise directed within the code. #
6
+ # #
7
+ # For information on the license of this code when distributed #
8
+ # with and used in conjunction with the other modules in the #
9
+ # Amp project, please see the root-level LICENSE file. #
10
+ # #
11
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
+ # #
13
+ ##################################################################
14
+
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
16
+
17
+ describe Amp::Core::Support::EncodingUtils do
18
+ describe '#network_to_host_64' do
19
+ context 'when little-endian' do
20
+ before(:each) do
21
+ @old_endian = Amp::Core::Support::Platform::SYSTEM[:endian]
22
+ Amp::Core::Support::Platform::SYSTEM[:endian] = :little
23
+ end
24
+
25
+ after(:each) do
26
+ Amp::Core::Support::Platform::SYSTEM[:endian] = @old_endian
27
+ end
28
+
29
+ it 'returns the integer with all 8 of its swapped to the n-1 position' do
30
+ input = 0xaabbccddeeff0011
31
+ output = 0x1100ffeeddccbbaa
32
+ Amp::Core::Support::EncodingUtils.network_to_host_64(input).should == output
33
+ Amp::Core::Support::EncodingUtils.network_to_host_64(output).should == input
34
+ end
35
+
36
+ it 'returns the integer with all 8 of its swapped to the n-1 position again' do
37
+ input = 0x0123456789abcdef
38
+ output = 0xefcdab8967452301
39
+ Amp::Core::Support::EncodingUtils.network_to_host_64(input).should == output
40
+ Amp::Core::Support::EncodingUtils.network_to_host_64(output).should == input
41
+ end
42
+ end
43
+
44
+ context 'when big-endian' do
45
+ before(:each) do
46
+ @old_endian = Amp::Core::Support::Platform::SYSTEM[:endian]
47
+ Amp::Core::Support::Platform::SYSTEM[:endian] = :big
48
+ end
49
+
50
+ after(:each) do
51
+ Amp::Core::Support::Platform::SYSTEM[:endian] = @old_endian
52
+ end
53
+
54
+ it 'does nothing' do
55
+ input = 0xaabbccddeeff0011
56
+ output = 0xaabbccddeeff0011
57
+ Amp::Core::Support::EncodingUtils.network_to_host_64(input).should == output
58
+ Amp::Core::Support::EncodingUtils.network_to_host_64(output).should == input
59
+ end
60
+
61
+ it 'continues to do nothing' do
62
+ input = 0x0123456789abcdef
63
+ output = 0x0123456789abcdef
64
+ Amp::Core::Support::EncodingUtils.network_to_host_64(input).should == output
65
+ Amp::Core::Support::EncodingUtils.network_to_host_64(output).should == input
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,33 @@
1
+ ##################################################################
2
+ # Licensing Information #
3
+ # #
4
+ # The following code is licensed, as standalone code, under #
5
+ # the Ruby License, unless otherwise directed within the code. #
6
+ # #
7
+ # For information on the license of this code when distributed #
8
+ # with and used in conjunction with the other modules in the #
9
+ # Amp project, please see the root-level LICENSE file. #
10
+ # #
11
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
+ # #
13
+ ##################################################################
14
+
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
16
+
17
+ describe Amp::Core::Support::Platform do
18
+ it 'has an OS' do
19
+ Amp::Core::Support::Platform.const_defined?(:OS).should be_true
20
+ end
21
+ it 'has an implementation' do
22
+ Amp::Core::Support::Platform.const_defined?(:IMPL).should be_true
23
+ end
24
+ it 'has an architecture' do
25
+ Amp::Core::Support::Platform.const_defined?(:ARCH).should be_true
26
+ end
27
+ it 'has an SYSTEM hash' do
28
+ Amp::Core::Support::Platform.const_defined?(:SYSTEM).should be_true
29
+ end
30
+ it 'has an endianness' do
31
+ Amp::Core::Support::Platform::SYSTEM[:endian].should_not be_nil
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb'))
@@ -0,0 +1,44 @@
1
+ ##################################################################
2
+ # Licensing Information #
3
+ # #
4
+ # The following code is licensed, as standalone code, under #
5
+ # the Ruby License, unless otherwise directed within the code. #
6
+ # #
7
+ # For information on the license of this code when distributed #
8
+ # with and used in conjunction with the other modules in the #
9
+ # Amp project, please see the root-level LICENSE file. #
10
+ # #
11
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
+ # #
13
+ ##################################################################
14
+
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
16
+
17
+ describe Amp::Core::Support::StringUtils do
18
+ describe '#ord' do
19
+ it 'raises an ArgumentError on an empty string' do
20
+ lambda { Amp::Core::Support::StringUtils.ord('') }.should raise_error(ArgumentError)
21
+ end
22
+
23
+ it 'returns the first byte of the string' do
24
+ Amp::Core::Support::StringUtils.ord('A').should == 65
25
+ Amp::Core::Support::StringUtils.ord('™').should == 226
26
+ end
27
+ end
28
+
29
+ describe '#unhexlify' do
30
+ it 'converts a few hex bytes to binary' do
31
+ Amp::Core::Support::StringUtils.unhexlify('abcd').should == "\xab\xcd"
32
+ end
33
+ end
34
+
35
+ describe '#hexlify' do
36
+ it 'converts text data to its hex form' do
37
+ Amp::Core::Support::StringUtils.hexlify('ABCD').should == '41424344'
38
+ end
39
+
40
+ it 'converts binary data to its hex form' do
41
+ Amp::Core::Support::StringUtils.hexlify('ABCD').should == '41424344'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,81 @@
1
+ ##################################################################
2
+ # Licensing Information #
3
+ # #
4
+ # The following code is licensed, as standalone code, under #
5
+ # the Ruby License, unless otherwise directed within the code. #
6
+ # #
7
+ # For information on the license of this code when distributed #
8
+ # with and used in conjunction with the other modules in the #
9
+ # Amp project, please see the root-level LICENSE file. #
10
+ # #
11
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
+ # #
13
+ ##################################################################
14
+
15
+ require 'test/unit'
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+
18
+ require 'rubygems'
19
+ require 'amp-front'
20
+ require 'amp-core'
21
+ Amp::Plugins::Core.new.load!
22
+
23
+ class TestTemplates < Test::Unit::TestCase
24
+ include Amp::Support
25
+
26
+ def setup
27
+ @template = Template.new(:log, :test, :erb, "<%= name %> <%= age %>")
28
+ @hamltemplate = Template.new(:commit, :silly, :haml, "= name\n==Age: \#{age}")
29
+ end
30
+
31
+ def test_new_template
32
+ assert @template
33
+ assert Template[:log, :test]
34
+ end
35
+
36
+ def test_unregister
37
+ Template.unregister(:log, :test)
38
+ assert_nil(Template[:log, :test])
39
+ end
40
+
41
+ # ERb Support
42
+
43
+ def test_render
44
+ name = "Steve"
45
+ age = 21
46
+ assert_equal "Steve 21", @template.render({}, binding)
47
+ end
48
+
49
+ def test_locals
50
+ locals = {:name => "Steve", :age => 21}
51
+ assert_equal "Steve 21", @template.render(locals)
52
+ end
53
+
54
+ # Haml support
55
+
56
+ def test_haml_render
57
+ name = "Steve"
58
+ age = 21
59
+ assert_equal "Steve\nAge: 21", @hamltemplate.render({}, binding).strip
60
+ end
61
+
62
+ def test_haml_locals
63
+ locals = {:name => "Steve", :age => 21}
64
+ assert_equal "Steve\nAge: 21", @hamltemplate.render(locals).strip
65
+ end
66
+
67
+ # RawTemplates
68
+ def test_raw_template
69
+ locals = {:name => "Steve", :age => 21}
70
+ assert_equal "Steve 21", RawERbTemplate.new("name + ' ' + age.to_s").render(locals)
71
+ end
72
+
73
+ # Indirectly tests FileTemplate
74
+ def test_loading_defaults
75
+ Template.ensure_templates_loaded
76
+ assert Template.templates_loaded?
77
+ assert_not_nil(Template[:mercurial, "default-commit"])
78
+ assert_not_nil(Template[:mercurial, "default-log"])
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amp-core
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Edgar
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-03 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: yard
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: cucumber
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: |
59
+ Amp's required plugin, providing core functionality (such as repository detection
60
+ and amp-specific command validations) to all other plugins.
61
+
62
+ email: michael.j.edgar@dartmouth.edu
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files:
68
+ - LICENSE
69
+ - README.rdoc
70
+ files:
71
+ - .document
72
+ - .gitignore
73
+ - Gemfile
74
+ - LICENSE
75
+ - README.rdoc
76
+ - Rakefile
77
+ - VERSION
78
+ - features/amp-core.feature
79
+ - features/step_definitions/amp-core_steps.rb
80
+ - features/support/env.rb
81
+ - lib/amp-core.rb
82
+ - lib/amp-core/command_ext/repository_loading.rb
83
+ - lib/amp-core/repository/abstract/abstract_changeset.rb
84
+ - lib/amp-core/repository/abstract/abstract_local_repo.rb
85
+ - lib/amp-core/repository/abstract/abstract_staging_area.rb
86
+ - lib/amp-core/repository/abstract/abstract_versioned_file.rb
87
+ - lib/amp-core/repository/abstract/common_methods/changeset.rb
88
+ - lib/amp-core/repository/abstract/common_methods/local_repo.rb
89
+ - lib/amp-core/repository/abstract/common_methods/staging_area.rb
90
+ - lib/amp-core/repository/abstract/common_methods/versioned_file.rb
91
+ - lib/amp-core/repository/generic_repo_picker.rb
92
+ - lib/amp-core/repository/repository.rb
93
+ - lib/amp-core/support/encoding_utils.rb
94
+ - lib/amp-core/support/platform_utils.rb
95
+ - lib/amp-core/support/rooted_opener.rb
96
+ - lib/amp-core/support/string_utils.rb
97
+ - lib/amp-core/templates/git/blank.log.erb
98
+ - lib/amp-core/templates/git/default.log.erb
99
+ - lib/amp-core/templates/mercurial/blank.commit.erb
100
+ - lib/amp-core/templates/mercurial/blank.log.erb
101
+ - lib/amp-core/templates/mercurial/default.commit.erb
102
+ - lib/amp-core/templates/mercurial/default.log.erb
103
+ - lib/amp-core/templates/template.rb
104
+ - spec/amp-core_spec.rb
105
+ - spec/command_ext_specs/repository_loading_spec.rb
106
+ - spec/command_ext_specs/spec_helper.rb
107
+ - spec/repository_specs/repository_spec.rb
108
+ - spec/repository_specs/spec_helper.rb
109
+ - spec/spec.opts
110
+ - spec/spec_helper.rb
111
+ - spec/support_specs/encoding_utils_spec.rb
112
+ - spec/support_specs/platform_utils_spec.rb
113
+ - spec/support_specs/spec_helper.rb
114
+ - spec/support_specs/string_utils_spec.rb
115
+ - test/test_templates.rb
116
+ has_rdoc: true
117
+ homepage: http://github.com/michaeledgar/amp-core
118
+ licenses: []
119
+
120
+ post_install_message:
121
+ rdoc_options:
122
+ - --charset=UTF-8
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project:
142
+ rubygems_version: 1.3.6
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: The core plugin for Amp. Necessary for Amp to function.
146
+ test_files:
147
+ - spec/amp-core_spec.rb
148
+ - spec/command_ext_specs/repository_loading_spec.rb
149
+ - spec/command_ext_specs/spec_helper.rb
150
+ - spec/repository_specs/repository_spec.rb
151
+ - spec/repository_specs/spec_helper.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support_specs/encoding_utils_spec.rb
154
+ - spec/support_specs/platform_utils_spec.rb
155
+ - spec/support_specs/spec_helper.rb
156
+ - spec/support_specs/string_utils_spec.rb
157
+ - test/test_templates.rb