piggly-nsd 2.3.3 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ module Piggly::Util
4
+
5
+ describe LineNumbers do
6
+ describe ".count" do
7
+ it "returns 0 for empty source" do
8
+ expect(LineNumbers.count("")).to eq(0)
9
+ expect(LineNumbers.count(nil)).to eq(0)
10
+ end
11
+
12
+ it "counts lines without a trailing newline" do
13
+ expect(LineNumbers.count("a\nb\nc")).to eq(3)
14
+ end
15
+
16
+ it "does not over-count when source ends with a newline" do
17
+ expect(LineNumbers.count("a\nb\nc\n")).to eq(3)
18
+ end
19
+
20
+ it "counts CRLF sources consistently" do
21
+ expect(LineNumbers.count("a\r\nb\r\nc\r\n")).to eq(3)
22
+ end
23
+
24
+ it "matches String#lines for a large trailing-newline body" do
25
+ source = (1..366).map { |i| "line#{i}" }.join("\n") + "\n"
26
+ expect(LineNumbers.count(source)).to eq(366)
27
+ expect(LineNumbers.count(source)).to eq(source.lines.count)
28
+ end
29
+ end
30
+
31
+ describe ".at_offset" do
32
+ let(:source) { "a\nb\nc\n" }
33
+
34
+ it "returns 1 for empty source" do
35
+ expect(LineNumbers.at_offset("", 0)).to eq(1)
36
+ end
37
+
38
+ it "maps byte offsets to 1-based line numbers" do
39
+ expect(LineNumbers.at_offset(source, 0)).to eq(1)
40
+ expect(LineNumbers.at_offset(source, 2)).to eq(2)
41
+ expect(LineNumbers.at_offset(source, 4)).to eq(3)
42
+ end
43
+
44
+ it "clamps offsets past EOF to the last line" do
45
+ expect(LineNumbers.at_offset(source, source.length)).to eq(3)
46
+ expect(LineNumbers.at_offset(source, source.length + 10)).to eq(3)
47
+ end
48
+
49
+ it "does not report a line beyond count when offset is on trailing newline" do
50
+ source = (1..366).map { |i| "line#{i}" }.join("\n") + "\n"
51
+ max_line = LineNumbers.count(source)
52
+
53
+ expect(LineNumbers.at_offset(source, source.length - 1)).to eq(max_line)
54
+ expect(LineNumbers.at_offset(source, source.length)).to eq(max_line)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ module Piggly
4
+ describe "GET CURRENT DIAGNOSTICS" do
5
+ include GrammarHelper
6
+
7
+ it "can parse a GET CURRENT DIAGNOSTICS statement" do
8
+ body = "GET CURRENT DIAGNOSTICS l_wdc_inserted := ROW_COUNT;"
9
+
10
+ node = parse(:statement, body)
11
+ node.should be_statement
12
+ end
13
+
14
+ it "can parse a procedure with GET CURRENT DIAGNOSTICS" do
15
+ body = <<-SQL
16
+ DECLARE
17
+ l_wdc_inserted bigint;
18
+ BEGIN
19
+ INSERT INTO foo DEFAULT VALUES;
20
+ GET CURRENT DIAGNOSTICS l_wdc_inserted := ROW_COUNT;
21
+ RETURN l_wdc_inserted;
22
+ END;
23
+ SQL
24
+
25
+ node = parse(:start, body.strip.downcase)
26
+ node.count { |e| e.assignment? }.should == 0
27
+ node.count { |e| Parser::Nodes::Return === e }.should == 1
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ module Piggly
4
+ describe "SQL CASE in PL/pgSQL conditions" do
5
+ include GrammarHelper
6
+
7
+ it "can parse IF with CASE in a function argument" do
8
+ body = <<-SQL
9
+ BEGIN
10
+ IF 0 = public.f_test(
11
+ p_doc_type_mnemo => line_rec.doc_type_mnemo,
12
+ p_person_id => CASE
13
+ WHEN l_f_sub_acc = 1 THEN p_client_id
14
+ WHEN l_f_sub_acc = 0 THEN l_person_id
15
+ END,
16
+ p_repres_id => NULL
17
+ ) THEN
18
+ NULL;
19
+ END IF;
20
+ END;
21
+ SQL
22
+
23
+ node = parse(:start, body.strip.downcase)
24
+ node.count { |e| e.if? }.should == 1
25
+ end
26
+
27
+ it "can parse ELSIF with CASE in a function argument" do
28
+ body = <<-SQL
29
+ BEGIN
30
+ IF false THEN
31
+ NULL;
32
+ ELSIF 0 = public.f_test(
33
+ p_person_id => CASE WHEN l_flag = 1 THEN p_a ELSE p_b END
34
+ ) THEN
35
+ NULL;
36
+ END IF;
37
+ END;
38
+ SQL
39
+
40
+ node = parse(:start, body.strip.downcase)
41
+ node.count { |e| e.if? }.should == 2
42
+ end
43
+
44
+ it "does not break simple IF conditions" do
45
+ node = parse(:statement, "IF cond THEN a := 10; END IF;")
46
+ node.should be_statement
47
+ node.count { |e| e.if? }.should == 1
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ module Piggly
4
+ describe "standalone transaction statements" do
5
+ include GrammarHelper
6
+
7
+ it "can parse commit without trailing expression" do
8
+ node = parse(:statement, "commit;")
9
+ node.should be_statement
10
+ node.count { |e| e.sql? }.should == 1
11
+ node.find { |e| e.sql? }.source_text.should == "commit;"
12
+ end
13
+
14
+ it "can parse rollback without trailing expression" do
15
+ node = parse(:statement, "rollback;")
16
+ node.should be_statement
17
+ node.count { |e| e.sql? }.should == 1
18
+ end
19
+
20
+ it "can parse a procedure with multiple commit statements" do
21
+ body = <<-SQL
22
+ BEGIN
23
+ call i_schema.create_choice1(p_session_id => l_session_id);
24
+ commit;
25
+ call i_schema.create_choice2(l_session_id);
26
+ commit;
27
+ END;
28
+ SQL
29
+
30
+ node = parse(:start, body.strip.downcase)
31
+ node.count { |e| e.sql? }.should == 4
32
+ end
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ module Piggly
26
26
 
27
27
  COMMENTS = ["abc defghi", "abc -- abc", "quote's", "a 'str'"]
28
28
 
29
- SQLWORDS = %w[select insert update delete drop alter commit set start]
29
+ SQLWORDS = %w[select insert update delete merge drop alter commit set start]
30
30
 
31
31
  KEYWORDS = %w[as := = alias begin by constant continue
32
32
  cursor debug declare diagnostics else elsif elseif
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piggly-nsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kvle Putnam
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.18.4
40
+ - !ruby/object:Gem::Dependency
41
+ name: csv
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '3.3'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.3'
40
54
  description: PostgreSQL PL/pgSQL stored procedure code coverage (NSD fork)
41
55
  email: putnam.kvle@gmail.com
42
56
  executables:
@@ -56,6 +70,7 @@ files:
56
70
  - lib/piggly/compiler.rb
57
71
  - lib/piggly/compiler/cache_dir.rb
58
72
  - lib/piggly/compiler/coverage_report.rb
73
+ - lib/piggly/compiler/line_coverage.rb
59
74
  - lib/piggly/compiler/trace_compiler.rb
60
75
  - lib/piggly/config.rb
61
76
  - lib/piggly/dumper.rb
@@ -79,6 +94,8 @@ files:
79
94
  - lib/piggly/reporter/resources/highlight.js
80
95
  - lib/piggly/reporter/resources/piggly.css
81
96
  - lib/piggly/reporter/resources/sortable.js
97
+ - lib/piggly/reporter/schema_csv.rb
98
+ - lib/piggly/reporter/sonar.rb
82
99
  - lib/piggly/tags.rb
83
100
  - lib/piggly/task.rb
84
101
  - lib/piggly/util.rb
@@ -86,6 +103,7 @@ files:
86
103
  - lib/piggly/util/cacheable.rb
87
104
  - lib/piggly/util/enumerable.rb
88
105
  - lib/piggly/util/file.rb
106
+ - lib/piggly/util/line_numbers.rb
89
107
  - lib/piggly/util/process_queue.rb
90
108
  - lib/piggly/util/thunk.rb
91
109
  - lib/piggly/version.rb
@@ -121,12 +139,14 @@ files:
121
139
  - spec/examples/reporter/html/dsl_spec.rb
122
140
  - spec/examples/reporter/html/index_spec.rb
123
141
  - spec/examples/reporter/html_spec.rb
142
+ - spec/examples/reporter/schema_csv_spec.rb
124
143
  - spec/examples/reporter_spec.rb
125
144
  - spec/examples/tags_spec.rb
126
145
  - spec/examples/task_spec.rb
127
146
  - spec/examples/util/cacheable_spec.rb
128
147
  - spec/examples/util/enumerable_spec.rb
129
148
  - spec/examples/util/file_spec.rb
149
+ - spec/examples/util/line_numbers_spec.rb
130
150
  - spec/examples/util/process_queue_spec.rb
131
151
  - spec/examples/util/thunk_spec.rb
132
152
  - spec/examples/version_spec.rb
@@ -136,9 +156,12 @@ files:
136
156
  - spec/issues/028_spec.rb
137
157
  - spec/issues/032_spec.rb
138
158
  - spec/issues/036_spec.rb
159
+ - spec/issues/037_spec.rb
160
+ - spec/issues/case_in_condition_spec.rb
161
+ - spec/issues/commit_spec.rb
139
162
  - spec/spec_helper.rb
140
163
  - spec/spec_suite.rb
141
- homepage: https://github.com/sergeiboikov/piggly
164
+ homepage: https://github.com/NSDDeveloper/piggly
142
165
  licenses:
143
166
  - BSD-2-Clause
144
167
  metadata: {}