piggly 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/README.markdown +84 -0
  2. data/Rakefile +19 -0
  3. data/bin/piggly +245 -0
  4. data/lib/piggly/compiler/cache.rb +151 -0
  5. data/lib/piggly/compiler/pretty.rb +67 -0
  6. data/lib/piggly/compiler/queue.rb +46 -0
  7. data/lib/piggly/compiler/tags.rb +244 -0
  8. data/lib/piggly/compiler/trace.rb +91 -0
  9. data/lib/piggly/compiler.rb +5 -0
  10. data/lib/piggly/config.rb +43 -0
  11. data/lib/piggly/filecache.rb +40 -0
  12. data/lib/piggly/installer.rb +95 -0
  13. data/lib/piggly/parser/grammar.tt +747 -0
  14. data/lib/piggly/parser/nodes.rb +319 -0
  15. data/lib/piggly/parser/parser.rb +11783 -0
  16. data/lib/piggly/parser/traversal.rb +48 -0
  17. data/lib/piggly/parser/treetop_ruby19_patch.rb +17 -0
  18. data/lib/piggly/parser.rb +67 -0
  19. data/lib/piggly/profile.rb +87 -0
  20. data/lib/piggly/reporter/html.rb +207 -0
  21. data/lib/piggly/reporter/piggly.css +187 -0
  22. data/lib/piggly/reporter/sortable.js +493 -0
  23. data/lib/piggly/reporter.rb +21 -0
  24. data/lib/piggly/task.rb +64 -0
  25. data/lib/piggly/util.rb +28 -0
  26. data/lib/piggly/version.rb +15 -0
  27. data/lib/piggly.rb +18 -0
  28. data/spec/compiler/cache_spec.rb +9 -0
  29. data/spec/compiler/pretty_spec.rb +9 -0
  30. data/spec/compiler/queue_spec.rb +3 -0
  31. data/spec/compiler/rewrite_spec.rb +3 -0
  32. data/spec/compiler/tags_spec.rb +285 -0
  33. data/spec/compiler/trace_spec.rb +173 -0
  34. data/spec/config_spec.rb +58 -0
  35. data/spec/filecache_spec.rb +70 -0
  36. data/spec/fixtures/snippets.sql +158 -0
  37. data/spec/grammar/expression_spec.rb +302 -0
  38. data/spec/grammar/statements/assignment_spec.rb +70 -0
  39. data/spec/grammar/statements/exception_spec.rb +52 -0
  40. data/spec/grammar/statements/if_spec.rb +178 -0
  41. data/spec/grammar/statements/loop_spec.rb +41 -0
  42. data/spec/grammar/statements/sql_spec.rb +71 -0
  43. data/spec/grammar/tokens/comment_spec.rb +58 -0
  44. data/spec/grammar/tokens/datatype_spec.rb +52 -0
  45. data/spec/grammar/tokens/identifier_spec.rb +58 -0
  46. data/spec/grammar/tokens/keyword_spec.rb +44 -0
  47. data/spec/grammar/tokens/label_spec.rb +40 -0
  48. data/spec/grammar/tokens/literal_spec.rb +30 -0
  49. data/spec/grammar/tokens/lval_spec.rb +50 -0
  50. data/spec/grammar/tokens/number_spec.rb +34 -0
  51. data/spec/grammar/tokens/sqlkeywords_spec.rb +45 -0
  52. data/spec/grammar/tokens/string_spec.rb +54 -0
  53. data/spec/grammar/tokens/whitespace_spec.rb +40 -0
  54. data/spec/parser_spec.rb +8 -0
  55. data/spec/profile_spec.rb +5 -0
  56. data/spec/reporter/html_spec.rb +0 -0
  57. data/spec/spec_helper.rb +61 -0
  58. data/spec/spec_suite.rb +5 -0
  59. metadata +121 -0
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ module Piggly
4
+
5
+ describe Parser, "statements" do
6
+ include GrammarHelper
7
+
8
+ describe "SQL keywords" do
9
+ it "parse successfully" do
10
+ GrammarHelper::SQLWORDS.test_each do |k|
11
+ parse(:sqlKeyword, k).source_text.should == k
12
+ end
13
+ end
14
+
15
+ it "cannot have trailing characters" do
16
+ GrammarHelper::SQLWORDS.each do |k|
17
+ lambda{ parse(:sqlKeyword, "#{k}abc") }.should raise_error
18
+ end
19
+ end
20
+
21
+ it "cannot have preceeding characters" do
22
+ GrammarHelper::SQLWORDS.each do |k|
23
+ lambda{ parse(:sqlKeyword, "abc#{k}") }.should raise_error
24
+ end
25
+ end
26
+
27
+ it "are terminated by symbols" do
28
+ GrammarHelper::SQLWORDS.test_each do |k|
29
+ node, rest = parse_some(:sqlKeyword, "#{k}+")
30
+ node.source_text.should == k
31
+ rest.should == '+'
32
+ end
33
+ end
34
+
35
+ it "are terminated by spaces" do
36
+ GrammarHelper::SQLWORDS.test_each do |k|
37
+ node, rest = parse_some(:sqlKeyword, "#{k} ")
38
+ node.source_text.should == k
39
+ rest.should == ' '
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ module Piggly
4
+ describe Parser, "tokens" do
5
+ include GrammarHelper
6
+
7
+ describe "strings" do
8
+ it "can be enclosed within single quotes" do
9
+ ["''", "'abc'", "'abc xyz'"].test_each do |s|
10
+ parse(:tString, s).should be_a(TString)
11
+ end
12
+ end
13
+
14
+ it "cannot be nested within single quotes" do
15
+ node, rest = parse_some(:tString, "'abc 'xyz' tuv'")
16
+ node.should be_a(TString)
17
+ rest.should == "xyz' tuv'"
18
+
19
+ node, rest = parse_some(:tString, "'can't'")
20
+ node.should be_a(TString)
21
+ rest.should == "t'"
22
+ end
23
+
24
+ it "can contain escaped single quotes" do
25
+ ["''''", "'can''t'", "'abc '' xyz'"].test_each do |s|
26
+ parse(:tString, s).should be_a(TString)
27
+ end
28
+ end
29
+
30
+ it "can be enclosed with $$ tags" do
31
+ ["$$$$", "$$ abc $$", "$T$ abc $T$", "$tt$ abc $tt$"].test_each do |s|
32
+ parse(:tString, s).should be_a(TString)
33
+ end
34
+ end
35
+
36
+ it "must have matching start and end $$ tags"
37
+
38
+ it "can be nested within $$ tags"
39
+
40
+ it "can embed $$ strings within single-quoted strings" do
41
+ ["'ab $$ xyz $$ cd'", "'a $b$ c $b$ d'"].test_each do |s|
42
+ parse(:tString, s).should be_a(TString)
43
+ end
44
+ end
45
+
46
+ it "can embed single-quote strings within $$ strings" do
47
+ ["$$ 'abc' $$", "$ABC$ 'ab''cd' $ABC$"].test_each do |s|
48
+ parse(:tString, s).should be_a(TString)
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ module Piggly
4
+ describe Parser, "tokens" do
5
+ include GrammarHelper
6
+
7
+ describe "white space" do
8
+ it "includes spaces" do
9
+ node, rest = parse_some(:tSpace, " ")
10
+ rest.should == ''
11
+ node.source_text.should == " "
12
+ end
13
+
14
+ it "includes tabs" do
15
+ node, rest = parse_some(:tSpace, "\t\t")
16
+ rest.should == ''
17
+ node.source_text.should == "\t\t"
18
+ end
19
+
20
+ it "includes line feeds" do
21
+ node, rest = parse_some(:tSpace, "\f\f")
22
+ rest.should == ''
23
+ node.source_text.should == "\f\f"
24
+ end
25
+
26
+ it "includes line breaks" do
27
+ node, rest = parse_some(:tSpace, "\n\n")
28
+ rest.should == ''
29
+ node.source_text.should == "\n\n"
30
+ end
31
+
32
+ it "includes carriage returns" do
33
+ node, rest = parse_some(:tSpace, "\r\r")
34
+ rest.should == ''
35
+ node.source_text.should == "\r\r"
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ module Piggly
4
+
5
+ describe Parser do
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ module Piggly
4
+
5
+ end
File without changes
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'piggly'))
5
+
6
+ #Dir[File.join(File.dirname(__FILE__), 'mocks', '*')].each do |m|
7
+ # require File.expand_path(m)
8
+ #end
9
+
10
+ module Piggly
11
+ module GrammarHelper
12
+
13
+ COMMENTS = ["abc defghi", "abc -- abc", "quote's", "a 'str'"]
14
+
15
+ SQLWORDS = %w[select insert update delete drop alter
16
+ commit begin rollback set start vacuum]
17
+
18
+ KEYWORDS = %w[as := = alias begin by close constant continue
19
+ cursor debug declare diagnostics else elsif elseif
20
+ end exception execute exit fetch for from get if
21
+ in info insert into is log loop move not notice
22
+ null open or perform raise rename result_oid return
23
+ reverse row_count scroll strict then to type warning
24
+ when while]
25
+
26
+ def parse(root, input)
27
+ string = input.downcase
28
+ parser = Parser.parser
29
+ parser.root = root
30
+ parser.consume_all_input = true
31
+ parser.parse(string) or raise Parser::Failure, parser.failure_reason
32
+ ensure
33
+ string.replace input
34
+ end
35
+
36
+ def parse_some(root, input)
37
+ string = input.downcase
38
+ parser = Parser.parser
39
+ parser.root = root
40
+ parser.consume_all_input = false
41
+ node = parser.parse(string)
42
+ raise Parser::Failure, parser.failure_reason unless node
43
+ return node, input[parser.index..-1]
44
+ ensure
45
+ string.replace input
46
+ end
47
+ end
48
+ end
49
+
50
+ module Enumerable
51
+ def test_each
52
+ each do |o|
53
+ begin
54
+ yield o
55
+ rescue
56
+ $!.message << "; while evaluating #{o}"
57
+ raise
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ dir = File.dirname(__FILE__)
2
+
3
+ Dir["#{dir}/**/*_spec.rb"].each do |spec|
4
+ require spec
5
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piggly
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Putnam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-19 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: treetop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: PostgreSQL PL/pgSQL stored procedure code coverage
26
+ email: putnam.kyle@gmail.com
27
+ executables:
28
+ - piggly
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README.markdown
35
+ - Rakefile
36
+ - spec/profile_spec.rb
37
+ - spec/grammar/expression_spec.rb
38
+ - spec/grammar/tokens/datatype_spec.rb
39
+ - spec/grammar/tokens/identifier_spec.rb
40
+ - spec/grammar/tokens/label_spec.rb
41
+ - spec/grammar/tokens/lval_spec.rb
42
+ - spec/grammar/tokens/keyword_spec.rb
43
+ - spec/grammar/tokens/sqlkeywords_spec.rb
44
+ - spec/grammar/tokens/whitespace_spec.rb
45
+ - spec/grammar/tokens/number_spec.rb
46
+ - spec/grammar/tokens/string_spec.rb
47
+ - spec/grammar/tokens/literal_spec.rb
48
+ - spec/grammar/tokens/comment_spec.rb
49
+ - spec/grammar/statements/assignment_spec.rb
50
+ - spec/grammar/statements/loop_spec.rb
51
+ - spec/grammar/statements/if_spec.rb
52
+ - spec/grammar/statements/sql_spec.rb
53
+ - spec/grammar/statements/exception_spec.rb
54
+ - spec/parser_spec.rb
55
+ - spec/fixtures/snippets.sql
56
+ - spec/filecache_spec.rb
57
+ - spec/reporter/html_spec.rb
58
+ - spec/config_spec.rb
59
+ - spec/compiler/tags_spec.rb
60
+ - spec/compiler/queue_spec.rb
61
+ - spec/compiler/cache_spec.rb
62
+ - spec/compiler/rewrite_spec.rb
63
+ - spec/compiler/trace_spec.rb
64
+ - spec/compiler/pretty_spec.rb
65
+ - spec/spec_suite.rb
66
+ - spec/spec_helper.rb
67
+ - lib/piggly.rb
68
+ - lib/piggly/util.rb
69
+ - lib/piggly/version.rb
70
+ - lib/piggly/parser/treetop_ruby19_patch.rb
71
+ - lib/piggly/parser/traversal.rb
72
+ - lib/piggly/parser/grammar.tt
73
+ - lib/piggly/parser/nodes.rb
74
+ - lib/piggly/parser/parser.rb
75
+ - lib/piggly/reporter.rb
76
+ - lib/piggly/compiler.rb
77
+ - lib/piggly/reporter/html.rb
78
+ - lib/piggly/reporter/piggly.css
79
+ - lib/piggly/reporter/sortable.js
80
+ - lib/piggly/compiler/pretty.rb
81
+ - lib/piggly/compiler/trace.rb
82
+ - lib/piggly/compiler/cache.rb
83
+ - lib/piggly/compiler/tags.rb
84
+ - lib/piggly/compiler/queue.rb
85
+ - lib/piggly/filecache.rb
86
+ - lib/piggly/task.rb
87
+ - lib/piggly/config.rb
88
+ - lib/piggly/parser.rb
89
+ - lib/piggly/installer.rb
90
+ - lib/piggly/profile.rb
91
+ - bin/piggly
92
+ has_rdoc: true
93
+ homepage: http://github.com/kputnam/piggly
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.5
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: PL/pgSQL code coverage tool
120
+ test_files: []
121
+