iba 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/tasks/notes.rake DELETED
@@ -1,122 +0,0 @@
1
- # The following code is based on Bones 2.5.1
2
- #
3
-
4
- module Bones
5
-
6
- # A helper class used to find and display any annotations in a collection of
7
- # project files.
8
- #
9
- class AnnotationExtractor
10
-
11
- class Annotation < Struct.new(:line, :tag, :text)
12
- # Returns a string representation of the annotation. If the
13
- # <tt>:tag</tt> parameter is given as +true+, then the annotation tag
14
- # will be included in the string.
15
- #
16
- def to_s( opts = {} )
17
- s = "[%3d] " % line
18
- s << "[#{tag}] " if opts[:tag]
19
- s << text
20
- end
21
- end
22
-
23
- # Enumerate all the annoations for the given _project_ and _tag_. This
24
- # will search for all athe annotations and display them on standard
25
- # output.
26
- #
27
- def self.enumerate tag, id = nil, opts = {}
28
- extractor = new(tag, id)
29
- extractor.display(extractor.find, opts)
30
- end
31
-
32
- attr_reader :tag, :id
33
-
34
- # Creates a new annotation extractor configured to use the _project_ open
35
- # strcut and to search for the given _tag_ (which can be more than one tag
36
- # via a regular expression 'or' operation -- i.e. THIS|THAT|OTHER)
37
- #
38
- def initialize tag, id
39
- @tag = tag
40
- @id = @id_rgxp = nil
41
-
42
- unless id.nil? or id.empty?
43
- @id = id
44
- @id_rgxp = Regexp.new(Regexp.escape(id), Regexp::IGNORECASE)
45
- end
46
- end
47
-
48
- # Iterate over all the files in the project and extract annotations from
49
- # the those files. Returns the results as a hash for display.
50
- #
51
- def find
52
- results = {}
53
- rgxp = %r/(#{tag}):?\s*(.*?)(?:\s*(?:-?%>|\*+\/))?$/o
54
-
55
- files = Dir.glob("lib/**/*.rb")
56
- files += Dir.glob("test/**/*.rb")
57
- files += Dir.glob("bin/*")
58
- files.each do |fn|
59
- results.update(extract_annotations_from(fn, rgxp))
60
- end
61
-
62
- results
63
- end
64
-
65
- # Extract any annotations from the given _file_ using the regular
66
- # expression _pattern_ provided.
67
- #
68
- def extract_annotations_from( file, pattern )
69
- lineno = 0
70
- result = File.readlines(file).inject([]) do |list, line|
71
- lineno += 1
72
- next list unless m = pattern.match(line)
73
- next list << Annotation.new(lineno, m[1], m[2]) unless id
74
-
75
- text = m[2]
76
- if text =~ @id_rgxp
77
- list << Annotation.new(lineno, m[1], text)
78
- end
79
- list
80
- end
81
- result.empty? ? {} : { file => result }
82
- end
83
-
84
- # Print the results of the annotation extraction to the screen. If the
85
- # <tt>:tags</tt> option is set to +true+, then the annotation tag will be
86
- # displayed.
87
- #
88
- def display( results, opts = {} )
89
- results.keys.sort.each do |file|
90
- puts "#{file}:"
91
- results[file].each do |note|
92
- puts " * #{note.to_s(opts)}"
93
- end
94
- puts
95
- end
96
- end
97
-
98
- end # class AnnotationExtractor
99
- end # module Bones
100
-
101
- note_tags = ["TODO", "FIXME", "OPTIMIZE"]
102
-
103
- desc "Enumerate all annotations"
104
- task :notes do |t|
105
- id = if t.application.top_level_tasks.length > 1
106
- t.application.top_level_tasks.slice!(1..-1).join(' ')
107
- end
108
- Bones::AnnotationExtractor.enumerate(
109
- note_tags.join('|'), id, :tag => true)
110
- end
111
-
112
- namespace :notes do
113
- note_tags.each do |tag|
114
- desc "Enumerate all #{tag} annotations"
115
- task tag.downcase.to_sym do |t|
116
- id = if t.application.top_level_tasks.length > 1
117
- t.application.top_level_tasks.slice!(1..-1).join(' ')
118
- end
119
- Bones::AnnotationExtractor.enumerate(tag, id)
120
- end
121
- end
122
- end
data/tasks/setup.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'rake/clean'
2
-
3
- # Load the other rake files in the tasks folder
4
- tasks_dir = File.expand_path(File.dirname(__FILE__))
5
- rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
6
- import(*rakefiles)
data/tasks/test.rake DELETED
@@ -1,14 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- namespace :test do
4
-
5
- Rake::TestTask.new(:run) do |t|
6
- t.libs = ['lib']
7
- t.test_files = FileList['test/**/*_test.rb']
8
- t.ruby_opts += ["-w"]
9
- end
10
-
11
- end
12
-
13
- desc 'Alias to test:run'
14
- task :test => 'test:run'
data/test/analyse_test.rb DELETED
@@ -1,58 +0,0 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
-
3
- # Test how the combinator analyses the parsed block contents.
4
- class AnalyseTest < Test::Unit::TestCase
5
- def test_empty_block
6
- assert_equal "nil is nil", combinator { }.analyse
7
- end
8
-
9
- def test_variable
10
- foo = 23
11
- assert_equal "foo is 23", combinator { foo }.analyse
12
- end
13
-
14
- def test_operator_equals
15
- foo = 42
16
- bar = 23
17
- assert_equal "(foo == bar) is false\nfoo is 42, bar is 23",
18
- combinator { foo == bar }.analyse
19
- end
20
-
21
- def test_operator_equals_literal
22
- foo = 42
23
- assert_equal "(foo == 23) is false\nfoo is 42",
24
- combinator { foo == 23 }.analyse
25
- end
26
-
27
- def test_operator_equals_array_literal
28
- foo = [1, "bar"]
29
- assert_equal "(foo == [2, \"baz\"]) is false\nfoo is [1, \"bar\"]",
30
- combinator { foo == [2, "baz"] }.analyse
31
- end
32
-
33
- def test_string_variable
34
- foo = "blub"
35
- assert_equal "foo is \"blub\"", combinator { foo }.analyse
36
- end
37
-
38
- def test_array_variable
39
- foo = [1, 2]
40
- assert_equal "foo is [1, 2]", combinator { foo }.analyse
41
- end
42
-
43
- def test_object_variable
44
- foo = Object.new
45
- insp = foo.inspect
46
- assert_equal "foo is #{insp}", combinator { foo }.analyse
47
- end
48
-
49
- def test_literal
50
- assert_equal "23 is 23", combinator { 23 }.analyse
51
- end
52
-
53
- def test_instance_variable
54
- @foo = 23
55
- assert_equal "@foo is 23", combinator { @foo }.analyse
56
- end
57
- end
58
-
data/test/assert_test.rb DELETED
@@ -1,58 +0,0 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
-
3
- # Test behavior of overridden assert method.
4
- class AssertTest < Test::Unit::TestCase
5
- def test_simple_assert
6
- assert { true }
7
- end
8
-
9
- def failing_block_assertion_test message, &block
10
- begin
11
- assert(&block)
12
- rescue Exception => e
13
- assert_equal message, e.message
14
- end
15
- end
16
-
17
- def test_simple_failing_assert
18
- failing_block_assertion_test("false is false.") { false }
19
- end
20
-
21
- def test_operator_equals_assert
22
- foo = 24
23
- failing_block_assertion_test("(foo == 23) is false\nfoo is 24.") { foo == 23 }
24
- end
25
-
26
- def test_instance_variable_assert
27
- @foo = 24
28
- failing_block_assertion_test("(@foo == 23) is false\n@foo is 24.") { @foo == 23 }
29
- end
30
-
31
- # Special cases
32
-
33
- def test_assert_with_custom_message
34
- foo = false
35
- begin
36
- assert("We want foo") { foo }
37
- rescue Exception => e
38
- assert_equal "We want foo.\nfoo is false.", e.message
39
- end
40
- end
41
-
42
- def test_original_assert
43
- begin
44
- assert false
45
- rescue Exception => e
46
- assert_equal "<false> is not true.", e.message
47
- end
48
- end
49
-
50
- def test_original_assert_with_custom_message
51
- begin
52
- assert false, "We want the truth"
53
- rescue Exception => e
54
- assert_equal "We want the truth.\n<false> is not true.", e.message
55
- end
56
- end
57
- end
58
-
data/test/call_test.rb DELETED
@@ -1,18 +0,0 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
-
3
- # Test how the combinator calls the passed block.
4
- class CallTest < Test::Unit::TestCase
5
- def test_empty_combinator
6
- assert_equal nil, combinator { }.call
7
- end
8
-
9
- def test_variable
10
- foo = 23
11
- assert_equal 23, combinator { foo }.call
12
- end
13
-
14
- def test_operator_call
15
- foo = 23
16
- assert_equal true, combinator { foo == 23 }.call
17
- end
18
- end
data/test/display_test.rb DELETED
@@ -1,57 +0,0 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
2
-
3
- # Test how the combinator displays the parsed block contents.
4
- class DisplayTest < Test::Unit::TestCase
5
- def test_empty_combinator
6
- assert_equal "nil", combinator { }.to_s
7
- end
8
-
9
- def test_literal_number
10
- assert_equal "23", combinator { 23 }.to_s
11
- end
12
-
13
- def test_literal_string
14
- assert_equal "\"aa\"", combinator { "aa" }.to_s
15
- end
16
-
17
- def test_method_calls
18
- assert_equal "foo", combinator { foo }.to_s
19
- assert_equal "foo.foo", combinator { foo.foo }.to_s
20
- assert_equal "foo.foo(1)", combinator { foo.foo 1 }.to_s
21
- assert_equal "foo(1)", combinator { foo 1 }.to_s
22
- assert_equal "foo(bar)", combinator { foo bar }.to_s
23
- assert_equal "foo(1).bar", combinator { foo(1).bar }.to_s
24
- assert_equal "foo.foo.foo", combinator { foo.foo.foo }.to_s
25
- assert_equal "foo(bar.baz)", combinator { foo bar.baz }.to_s
26
- end
27
-
28
- def test_operators
29
- assert_equal "(foo + 1)", combinator { foo + 1 }.to_s
30
- assert_equal "(foo - 1)", combinator { foo - 1 }.to_s
31
- end
32
-
33
- def test_operator_equals
34
- assert_equal "(foo == 1)", combinator { foo == 1 }.to_s
35
- end
36
-
37
- def test_array_index
38
- assert_equal "foo[1]", combinator { foo[1] }.to_s
39
- end
40
-
41
- def test_to_s_method
42
- assert_equal "foo.to_s", combinator { foo.to_s }.to_s
43
- end
44
-
45
- def test_operator_unary_minus
46
- assert_equal "-foo", combinator { -foo }.to_s
47
- end
48
-
49
- def test_operator_if_wont_work
50
- assert_equal "bar", combinator { foo ? bar : baz }.to_s
51
- end
52
-
53
- def test_defined_instance_variables
54
- @foo = 1
55
- assert_equal "@foo", combinator { @foo }.to_s
56
- end
57
- end
data/test/test_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'test/unit'
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'iba'
4
-
5
- class Test::Unit::TestCase
6
- include Iba::BlockAssertion
7
-
8
- def combinator &blk
9
- return Iba::Combinator.new(&blk)
10
- end
11
-
12
- end