notes 0.0.3 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,17 @@
1
+ == 0.1.0-pre1
2
+
3
+ Complete refactoring of Notes: LESS IS MORE!
4
+
5
+ * Defaults tags are now TODO, FIXME, and XXX.
6
+ * Drop the Rak gem.
7
+ * Yield on each note instead of returning the whole result set.
8
+ * Grep style result display.
9
+ * Notes now provides #scan or #scan_file methods, and a Scanner class.
10
+ * An object (which respond to #read or #to_s) can extend Notes to add a #notes method.
11
+ * Use the Paint gem for coloring.
12
+ * Add an option not to colorize output.
13
+ * Use minitest for test cases.
14
+
1
15
  == 0.0.3
2
16
 
3
17
  Force rak version to 1.0
data/LICENSE CHANGED
@@ -1,7 +1,6 @@
1
- -------------------------------------------------------------------------------
2
- "THE BEER-WARE LICENSE" (Revision 42):
3
- <vivien.didelot@gmail.com> wrote this gem. As long as you retain this notice
4
- you can do whatever you want with this stuff. If we meet some day, and you
5
- think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
6
- -------------------------------------------------------------------------------
7
-
1
+ ----------------------------------------------------------------------------
2
+ "THE BEER-WARE LICENSE" (Revision 42):
3
+ <vivien@didelot.org> wrote this code. As long as you retain this notice you
4
+ can do whatever you want with this stuff. If we meet some day, and you think
5
+ this stuff is worth it, you can buy me a beer in return Vivien Didelot
6
+ ----------------------------------------------------------------------------
@@ -0,0 +1,105 @@
1
+ # Notes
2
+
3
+ grep tags in source files
4
+
5
+ This gem provides a command line tool and a Ruby library to find tags in
6
+ source code. Defaults tags are *TODO*, *FIXME*, and *XXX*.
7
+ Custom tags can be found as well.
8
+
9
+ It's kind of a generic version of the `rake notes` command,
10
+ which is only available in Ruby on Rails applications.
11
+
12
+ ## Command line tool
13
+
14
+ Usage:
15
+
16
+ $ notes [options] [file...]
17
+
18
+ With no argument, `notes` will search recursively in the current
19
+ directory. For details, see `notes --help`.
20
+
21
+ Examples:
22
+
23
+ $ notes
24
+ $ notes foo.h src/
25
+ $ notes --tag @@@
26
+ $ notes --no-{todo,fixme,xxx} --tag FOO
27
+
28
+ ### Convention over configuration
29
+
30
+ Notes won't filter. `find`, `xargs` are here for you:
31
+
32
+ $ find . -name '*.rb' | xargs notes
33
+
34
+ No custom output. It uses a grep-style display, which makes it easy to
35
+ fit your needs. Try:
36
+
37
+ $ notes | cut -d: -f3,4-
38
+
39
+ Or get the list of tagged files in the current directory with:
40
+
41
+ $ notes | cut -d: -f1 | sort -u
42
+
43
+ ## Installation
44
+
45
+ Notes is available on [Rubygems.org](http://rubygems.org/gems/notes) and
46
+ can be installed with:
47
+
48
+ $ [sudo] gem install notes
49
+
50
+ ## The Notes library
51
+
52
+ Module functions:
53
+
54
+ require 'notes'
55
+
56
+ Notes.scan_file("foo.c") do |note|
57
+ puts "#{note.tag} found at line #{note.line}!"
58
+ end
59
+
60
+ Notes.scan("...\nXXX: an urgent note!") do |note|
61
+ putes note.text
62
+ end
63
+
64
+ Extending the Notes module:
65
+
66
+ require 'notes'
67
+
68
+ file = File.new("foo.c")
69
+ file.extend Notes
70
+ file.notes { |note| puts note.text }
71
+
72
+ Using the Notes scanner:
73
+
74
+ require 'notes'
75
+
76
+ scan = Notes::Scanner.new
77
+ scan.tags = Notes::TAGS + "FOO"
78
+ scan.on_note do |note|
79
+ puts "found!"
80
+ end
81
+ scan.scan_file("foo.c")
82
+ scan.scan_file("bar.c")
83
+
84
+ Create your own scanner:
85
+
86
+ require 'notes'
87
+
88
+ class Foo < Notes::Scanner
89
+ attr_reader :notes
90
+
91
+ def initialize tags = nil
92
+ super(tags)
93
+ @notes = []
94
+ end
95
+
96
+ # Called if no action block set. So override it.
97
+ def tag note
98
+ @notes << note
99
+ end
100
+ end
101
+
102
+ License
103
+ -------
104
+
105
+ That's free for sure! See the LICENSE file.
data/bin/notes CHANGED
@@ -1,65 +1,80 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # ------------------------------------------------------------------------------
3
+ # ----------------------------------------------------------------------------
4
4
  # "THE BEER-WARE LICENSE" (Revision 42):
5
- # <vivien.didelot@gmail.com> wrote this file. As long as you retain this notice
6
- # you can do whatever you want with this stuff. If we meet some day, and you
7
- # think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
8
- # ------------------------------------------------------------------------------
9
-
10
- # Command line tool to grep annotations from source files.
11
- # Author:: Vivien 'v0n' Didelot <vivien.didelot@gmail.com>
5
+ # <vivien@didelot.org> wrote this file. As long as you retain this notice you
6
+ # can do whatever you want with this stuff. If we meet some day, and you think
7
+ # this stuff is worth it, you can buy me a beer in return Vivien Didelot
8
+ # ----------------------------------------------------------------------------
12
9
 
13
10
  require 'notes'
14
-
15
- require 'rainbow'
16
11
  require 'optparse'
12
+ require 'paint'
13
+ require 'find'
17
14
 
18
- def display(list)
19
- list.each do |a|
20
- color = case a.tag
21
- when "TODO" then :yellow
22
- when "FIXME" then :red
23
- when "OPTIMIZE" then :green
24
- else :blue
25
- end
26
-
27
- printf("%s:%s: %s: %s\n",
28
- a.file.color(:magenta), a.line, a.tag.color(color), a.text)
29
- end
15
+ # grep-style display
16
+ def pretty_print(note, colors)
17
+ col = Paint[':', :cyan]
18
+ format = Paint['%s', :magenta] + col
19
+ format << Paint['%s', :green] + col
20
+ format << Paint['%s', colors[note.tag] || colors[:custom], :bold] + col
21
+ format << "%s\n"
22
+ printf(format,
23
+ note.source,
24
+ note.line,
25
+ note.tag,
26
+ note.text.rstrip)
30
27
  end
31
28
 
32
- tags = []
33
- source = []
34
- file = nil
29
+ tags = Notes::TAGS.dup
30
+ colors = {
31
+ "TODO" => 'green',
32
+ "FIXME" => 'yellow',
33
+ "XXX" => 'red',
34
+ :custom => 'cyan'
35
+ }
35
36
 
36
- ARGV.options do |o|
37
- o.banner = "Usage: #{File.basename $0} [options] [file...]\n"
38
- o.banner << "Search recursively for annotations in source code.\n"
39
- o.banner << "By default, #{File.basename $0} will search for all annotations in current directory.\n"
40
-
41
- o.on_head("Available options:")
42
- o.on("-a", "--all", "Search TODO, FIXME and OPTIMIZE annotations") { tags << AnnotationExtractor::TAGS }
43
- o.on("-t", "--todo", "Search TODO annotations") { tags << "TODO" }
44
- o.on("-f", "--fixme", "Search FIXME annotations") { tags << "FIXME" }
45
- o.on("-z", "--optimize", "Search OPTIMIZE annotations") { tags << "OPTIMIZE" }
46
- o.on("-c", "--custom=TAG", String, "Search TAG annotations") { |v| tags << v }
47
- o.on("-o", "--out=FILE", String, "Save output in FILE") { |v| file = v }
48
- o.on("-v", "--version", "Print notes version") { puts "notes: version #{AnnotationExtractor::VERSION}" ; exit }
37
+ usage = 'Usage: notes [OPTION]... [FILE]...'
49
38
 
50
- o.on_tail("Example: #{File.basename $0} -ac IMPROVE test.c lib\nwill search for TODO, FIXME, OPTIMIZE and IMPROVE annotations in test.c lib directory.")
39
+ ARGV.options do |o|
40
+ o.version = Notes::VERSION
41
+ o.banner = usage
42
+ o.on( '--no-todo', 'Do not search TODO tags') { tags -= ['TODO'] }
43
+ o.on( '--no-fixme', 'Do not search FIXME tags') { tags -= ['FIXME'] }
44
+ o.on( '--no-xxx', 'Do not search XXX tags') { tags -= ['XXX'] }
45
+ o.on('-t', '--tag=TAG', 'Search TAG tags') { |tag| tags |= [tag] }
46
+ o.on( '--no-color', 'Do not colorize ouput') { Paint.mode = 0 }
51
47
  end
52
48
 
53
49
  begin
54
50
  ARGV.options.parse!
55
- AnnotationExtractor.tags = tags.flatten unless tags.empty?
56
- source = ARGV
51
+ rescue => e
52
+ STDERR.puts "notes: #{e.message}"
53
+ STDERR.puts usage
54
+ STDERR.puts "Try `notes --help' for more information."
55
+ exit 1
56
+ end
57
+
58
+ scanner = Notes::Scanner.new
59
+ scanner.look_for tags
60
+ scanner.on_note do |note|
61
+ pretty_print(note, colors)
62
+ end
57
63
 
58
- notes = AnnotationExtractor.new(source)
64
+ paths = ARGV.dup
65
+ paths.empty? and paths << Dir.pwd
59
66
 
60
- file.nil? ? display(notes.list) : notes.write(file)
61
- rescue => e
62
- STDERR.puts "error: #{e}"
67
+ Find.find(*paths) do |path|
68
+ unless paths.include? path
69
+ Find.prune if File.basename(path).start_with? '.'
70
+ end
71
+ next if File.directory? path
72
+
73
+ begin
74
+ scanner.scan_file(path)
75
+ rescue => e
76
+ STDERR.puts "notes: #{path}: #{e.message}"
77
+ end
63
78
  end
64
79
 
65
80
  exit
@@ -5,108 +5,36 @@
5
5
  # think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
6
6
  # ------------------------------------------------------------------------------
7
7
 
8
- # Useless, but informs that rak should be installed.
9
- require 'rubygems'
10
- require 'rak'
8
+ require 'notes/version'
9
+ require 'notes/scanner'
11
10
 
12
- class AnnotationExtractor
13
- VERSION = "0.0.3"
11
+ module Notes
14
12
 
15
- # An annotation class.
16
- class Annotation
17
- attr_accessor :file, :line, :tag, :text
13
+ # Default tags to grep in source code.
14
+ TAGS = %w[TODO FIXME XXX]
18
15
 
19
- # Instanciate a new Annotation from a hash.
20
- def initialize(args)
21
- @file = args[:file]
22
- @line = args[:line]
23
- @tag = args[:tag]
24
- @text = args[:text]
25
- end
26
- end
27
-
28
- # Default tags list
29
- TAGS = ["TODO", "FIXME", "OPTIMIZE"]
16
+ Note = Struct.new(:tag, :text, :line, :source)
30
17
 
31
- # Trick not to use @@tags class variable, but works the same way.
32
- # Custom tags can be added with AnnotationExtractor.tags << "FOO".
33
- @tags = TAGS.clone
34
- class << self
35
- attr_reader :tags
36
- def tags=(tags)
37
- @tags = tags.is_a?(Array) ? tags : [tags]
38
- end
18
+ # TODO doc
19
+ def self.scan(source, tags = nil, &block)
20
+ block.nil? and return enum_for(__method__, source, tags, &block)
21
+ scanner = Scanner.new(tags, &block)
22
+ scanner.scan(source)
39
23
  end
40
24
 
41
- # The list of all notes.
42
- attr_reader :list
43
-
44
- # Instanciate a new extractor for the given target files.
45
- def initialize(source = Dir.pwd)
46
- @source = [].push(source).flatten
47
- @list = Array.new
48
-
49
- extract
25
+ # TODO doc
26
+ def self.scan_file(file, tags = nil, &block)
27
+ block.nil? and return enum_for(__method__, file, tags, &block)
28
+ scanner = Scanner.new(tags, &block)
29
+ scanner.scan_file(file)
50
30
  end
51
31
 
52
- # Get annotation with tag 'tag' from the list.
53
- def get(tag)
54
- @list.find_all { |a| a.tag == tag }
55
- end
56
-
57
- # Write all annotations to the file 'file'.
58
- def write(file)
59
- longest_tag = @list.max { |a, b| a.tag.size <=> b.tag.size }.tag.size
60
-
61
- File.open(file, 'w') do |f|
62
- @list.each do |a|
63
- f.write(sprintf(" * [%-#{longest_tag}s] %s (%s): %s\n",
64
- a.tag, a.file, a.line, a.text))
65
- end
66
- end
32
+ # TODO doc
33
+ def notes(tags = nil, &block)
34
+ block.nil? and return enum_for(__method__, tags, &block)
35
+ scanner = Scanner.new(tags, &block)
36
+ source = (self.respond_to? :read) ? self.read : self.to_s
37
+ scanner.scan(source)
67
38
  end
68
39
 
69
- private
70
-
71
- # Extract annotations.
72
- def extract
73
- tags = self.class.tags.join("|")
74
- suffix = "\s?:?" # Allowed annotation suffix.
75
- source = @source.join(" ")
76
-
77
- # Because of different rak versions,
78
- # rak system call outputs are not similar.
79
- if `rak --version` =~ /rak (\d\.\d)/
80
- rak_version = $1
81
- else
82
- raise "Can't get rak version"
83
- end
84
-
85
- # 0.9 is the current rak version from rubygems.
86
- # 1.1 is the current rak version from the github repo.
87
- if rak_version == "1.1"
88
- #TODO /^(.+):(\d+):...?
89
- regex = /^(.*):(\d*):.*(#{tags})#{suffix}(.*)$/
90
- else
91
- regex = /^([^\s]+)\s+(\d+)\|.*(#{tags})#{suffix}(.*)$/
92
- end
93
- # TODO extract first matching annotation if there're many on a line.
94
- # e.g. "TODO: Rename $TODOLIST variable."
95
-
96
- out = `rak '(#{tags})#{suffix}\s+' #{source}`.strip
97
-
98
- @list = out.split("\n").map do |l|
99
- if l =~ regex
100
- Annotation.new({
101
- :file => $1,
102
- :line => $2.to_i,
103
- :tag => $3,
104
- :text => $4.strip
105
- })
106
- else
107
- # Just for a debug purpose
108
- raise "notes: does not match regexp => \"#{l}\""
109
- end
110
- end
111
- end
112
- end
40
+ end # Notes
@@ -0,0 +1,52 @@
1
+ module Notes
2
+ class Scanner
3
+
4
+ attr_accessor :tags, :action
5
+
6
+ # TODO doc
7
+ def initialize tags = nil, &block
8
+ @tags = tags || TAGS.dup
9
+ @action = block || proc { |note| tag(note) }
10
+ end
11
+
12
+ # TODO doc
13
+ alias look_for tags=
14
+
15
+ # TODO doc
16
+ def on_note &block
17
+ @action = block
18
+ end
19
+
20
+ # TODO doc
21
+ def scan source
22
+ source.split("\n").each_with_index do |line, i|
23
+ if line =~ regexp
24
+ @action.call Note.new($1, line, i + 1)
25
+ end
26
+ end
27
+ end
28
+
29
+ # TODO doc
30
+ def scan_file path
31
+ file = File.open(path, 'r')
32
+ file.each_with_index do |line, i|
33
+ if line =~ regexp
34
+ @action.call Note.new($1, line, i + 1, path)
35
+ end
36
+ end
37
+ file.close
38
+ end
39
+
40
+ # TODO doc
41
+ def tag note
42
+ puts "#{note.type} on line #{note.line}: #{note.text.strip}"
43
+ end
44
+
45
+ private
46
+
47
+ def regexp
48
+ /\b(#{@tags.join('|')})\b/
49
+ end
50
+
51
+ end # Scanner
52
+ end # Notes
@@ -0,0 +1,4 @@
1
+ module Notes
2
+ VERSION = "0.1.0.pre"
3
+ end
4
+
metadata CHANGED
@@ -1,38 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vivien Didelot
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-09 00:00:00.000000000Z
12
+ date: 2012-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rak
16
- requirement: &83676280 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - =
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *83676280
25
- - !ruby/object:Gem::Dependency
26
- name: rainbow
27
- requirement: &83675860 !ruby/object:Gem::Requirement
15
+ name: paint
16
+ requirement: &20331680 !ruby/object:Gem::Requirement
28
17
  none: false
29
18
  requirements:
30
19
  - - ! '>='
31
20
  - !ruby/object:Gem::Version
32
- version: '1.1'
21
+ version: 0.8.4
33
22
  type: :runtime
34
23
  prerelease: false
35
- version_requirements: *83675860
24
+ version_requirements: *20331680
36
25
  description:
37
26
  email: vivien.didelot@gmail.com
38
27
  executables:
@@ -41,9 +30,9 @@ extensions: []
41
30
  extra_rdoc_files: []
42
31
  files:
43
32
  - lib/notes.rb
44
- - test/notes_test.rb
45
- - test/data/sample.c
46
- - README.rdoc
33
+ - lib/notes/scanner.rb
34
+ - lib/notes/version.rb
35
+ - README.md
47
36
  - CHANGELOG.rdoc
48
37
  - LICENSE
49
38
  - bin/notes
@@ -62,13 +51,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
51
  required_rubygems_version: !ruby/object:Gem::Requirement
63
52
  none: false
64
53
  requirements:
65
- - - ! '>='
54
+ - - ! '>'
66
55
  - !ruby/object:Gem::Version
67
- version: '0'
56
+ version: 1.3.1
68
57
  requirements: []
69
58
  rubyforge_project:
70
- rubygems_version: 1.8.6
59
+ rubygems_version: 1.8.15
71
60
  signing_key:
72
61
  specification_version: 3
73
- summary: A Ruby gem to grep annotations in source files.
62
+ summary: A Ruby gem to grep tags in source files.
74
63
  test_files: []
@@ -1,90 +0,0 @@
1
- = Notes
2
-
3
- == grep annotations in source files
4
-
5
- This lib provides a Ruby library and command line tool to find annotations in source files such as:
6
- * TODO
7
- * FIXME
8
- * OPTIMIZE
9
- Custom tags can also be found.
10
-
11
- The purpose of this code is to get a generic version of the `rake notes' command (only used for Ruby on Rails applications).
12
- It will look for tags recursively in every given files (or in current directory by default).
13
-
14
- == Installation
15
-
16
- Notes is available on Rubygems.org[http://rubygems.org/gems/notes] and can be installed with:
17
-
18
- $ gem install notes
19
-
20
- This command needs Rubygems (rubygems package on Ubuntu).
21
-
22
- Note: it depends on rak version = 1.0 and rainbow version >= 1.1.
23
-
24
- == Usage
25
-
26
- === Command line tool
27
-
28
- notes [options] [file...]
29
-
30
- For details, see the help.
31
-
32
- $ ruby notes --help
33
- Usage: notes [options] [file...]
34
- Search recursively for annotations in source code.
35
- By default, notes will search for all annotations in current directory.
36
- Available options:
37
- -a, --all Search TODO, FIXME and OPTIMIZE annotations
38
- -t, --todo Search TODO annotations
39
- -f, --fixme Search FIXME annotations
40
- -z, --optimize Search OPTIMIZE annotations
41
- -c, --custom=TAG Search TAG annotations
42
- -o, --out=FILE Save output in FILE
43
- -v, --version Print notes version
44
- Example: notes -ac IMPROVE test.c lib
45
- will search for TODO, FIXME, OPTIMIZE and IMPROVE annotations in test.c file and lib directory.
46
-
47
- Another example:
48
-
49
- $ notes test/data/sample.c
50
- ../test/data/sample.c:16: TODO: first thing to do
51
- ../test/data/sample.c:26: FIXME: first fixme thing
52
- ../test/data/sample.c:32: TODO: second todo thing!
53
- ../test/data/sample.c:42: OPTIMIZE: make it better
54
- ../test/data/sample.c:47: TODO: hello world
55
-
56
- If the terminal allows it, colors will be displayed for files and tags.
57
-
58
- Another again:
59
-
60
- $ notes -o TODO.txt test/data/sample.c
61
-
62
- will write all notes to a TODO.txt file. It will look like that:
63
-
64
- * [TODO ] ../test/data/sample.c (16): first thing to do
65
- * [FIXME ] ../test/data/sample.c (26): first fixme thing
66
- * [TODO ] ../test/data/sample.c (32): second todo thing!
67
- * [OPTIMIZE] ../test/data/sample.c (42): make it better
68
- * [TODO ] ../test/data/sample.c (47): hello world
69
-
70
- === Lib
71
-
72
- This code can be used as a Ruby lib. Let's see how it works in irb:
73
-
74
- $ irb
75
- >> require 'notes'
76
- >> AnnotationExtractor.tags << "FOO" # Add custom tag
77
- >> notes = AnnotationExtractor.new "test/data/sample.c" # Parse file
78
- >> notes.list # Return the array of annotations
79
- >> notes.get "FIXME" # Return the array of FIXME annotations only
80
- >> notes.write "TODO.rdoc" # Write all annotations in a file
81
-
82
- == License
83
-
84
- ------------------------------------------------------------------------------
85
- "THE BEER-WARE LICENSE" (Revision 42):
86
- <vivien.didelot@gmail.com> wrote this gem. As long as you retain this notice
87
- you can do whatever you want with this stuff. If we meet some day, and you
88
- think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
89
- ------------------------------------------------------------------------------
90
-
@@ -1,58 +0,0 @@
1
- /*
2
- * -----------------------------------------------------------------------------
3
- * "THE BEER-WARE LICENSE" (Revision 42):
4
- * <vivien.didelot@gmail.com> wrote this file. As long as you retain this notice
5
- * you can do whatever you want with this stuff. If we meet some day, and you
6
- * think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
7
- * -----------------------------------------------------------------------------
8
- */
9
-
10
- /* UDP Server */
11
-
12
- #include <netinet/in.h>
13
- #include <stdio.h>
14
- #include <stdlib.h>
15
-
16
- //TODO first thing to do
17
- #define STEP sizeof(char)
18
-
19
- int main()
20
- {
21
- int sock;
22
- size_t size = STEP;
23
- size_t a_size = sizeof(struct sockaddr_in);
24
- void *buffer = malloc(STEP);
25
-
26
- //FIXME: first fixme thing
27
- int port = 4242;
28
-
29
- /* address server sock */
30
- struct sockaddr_in addr = {AF_INET, htons(port), {htonl(INADDR_ANY)}};
31
-
32
- //TODO : second todo thing!
33
- /* client sock */
34
- struct sockaddr_in client;
35
-
36
- /* socket declaration */
37
- sock = socket(AF_INET, SOCK_DGRAM, 0);
38
-
39
- /* bind socket to local */
40
- bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
41
-
42
- //OPTIMIZE make it better
43
- while(1)
44
- {
45
- //FOO a custom tag
46
- //FOOBAR this should not be found if 'FOO' is asked. Same thing for:
47
- //TODOLIST blah blah
48
- //TODO_LIST etc.
49
- while (recvfrom(sock, buffer, size, MSG_PEEK, NULL, NULL) == size)
50
- buffer = realloc(buffer, size += STEP); //TODO hello world
51
-
52
- recvfrom(sock, buffer, size, 0, (struct sockaddr*) &client, &a_size);
53
-
54
- printf("Server receive: \"%s\"\n", (char*) buffer);
55
- }
56
-
57
- return 0;
58
- }
@@ -1,63 +0,0 @@
1
- # ------------------------------------------------------------------------------
2
- # "THE BEER-WARE LICENSE" (Revision 42):
3
- # <vivien.didelot@gmail.com> wrote this file. As long as you retain this notice
4
- # you can do whatever you want with this stuff. If we meet some day, and you
5
- # think this stuff is worth it, you can buy me a beer in return. Vivien Didelot
6
- # ------------------------------------------------------------------------------
7
-
8
- require "test/unit"
9
- require "notes"
10
- require "tempfile"
11
-
12
- class NotesTest < Test::Unit::TestCase
13
- def setup
14
- @sample = "#{File.join "..", "test", "data", "sample.c"}"
15
- end
16
-
17
- def test_new
18
- notes = AnnotationExtractor.new(@sample)
19
- assert_equal 5, notes.list.size
20
- notes.list.each { |a| assert_kind_of AnnotationExtractor::Annotation, a }
21
-
22
- AnnotationExtractor.tags << "FOO"
23
- notes = AnnotationExtractor.new(@sample)
24
- assert_equal 6, notes.list.size
25
-
26
- # Test exact text
27
- assert_equal "first thing to do", notes.list[0].text
28
- assert_equal "first fixme thing", notes.list[1].text
29
- assert_equal "second todo thing!", notes.list[2].text
30
- assert_equal "make it better", notes.list[3].text
31
- assert_equal "a custom tag", notes.list[4].text
32
- assert_equal "hello world", notes.list[5].text
33
-
34
- AnnotationExtractor.tags = "OPTIMIZE"
35
- notes = AnnotationExtractor.new(@sample)
36
- assert_equal 1, notes.list.size
37
- assert_equal "make it better", notes.list.first.text
38
-
39
- AnnotationExtractor.tags = "FOO"
40
- notes = AnnotationExtractor.new(@sample)
41
- assert_equal 1, notes.list.size
42
- assert_equal "a custom tag", notes.list.first.text
43
- end
44
-
45
- def test_get
46
- notes = AnnotationExtractor.new(@sample)
47
- assert_equal 3, notes.get("TODO").size
48
- assert_equal 1, notes.get("FIXME").size
49
- assert_equal 1, notes.get("OPTIMIZE").size
50
- end
51
-
52
- def test_write
53
- tempfile = Tempfile.new("notes").path
54
-
55
- AnnotationExtractor.tags = AnnotationExtractor::TAGS
56
- notes = AnnotationExtractor.new(@sample)
57
- notes.write tempfile
58
-
59
- assert_equal 5, File.readlines(tempfile).size
60
-
61
- File.delete tempfile
62
- end
63
- end