sql_matchers 1.0.0.pre.rc.2 → 1.0.0.pre.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sql_matchers/matchers/sql.rb +8 -10
- data/lib/sql_matchers/normalizers/sql.rb +15 -0
- data/lib/sql_matchers/normalizers.rb +7 -0
- data/lib/sql_matchers/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0cde4f12d9a94e037920bb6549a52e2ae29f14bcb8eea6efa1ea64dc927b777
|
4
|
+
data.tar.gz: cf5b0efb6152a3ad11783ee44cc38083468b9e67b001e3eb8b78ced87a985a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f310b5513d1bef5ac0259b5d951e397dab137f27407e7ce515fdb82a4cf76177b5fe4e5507150b6a6c6dd37d313a8e43ced4a45cbf04cd366c58673962d2559
|
7
|
+
data.tar.gz: 2bb8fd1381957561cf6b8cfe91df600053c2e5589b969e154b4061c3e8cb96694f66b46cc7a37e58e755ea268e90646149dd9a73d7f02ca11b852edf8c513e01
|
@@ -2,16 +2,17 @@
|
|
2
2
|
|
3
3
|
require 'anbt-sql-formatter/formatter'
|
4
4
|
|
5
|
+
require_relative '../normalizers/sql'
|
6
|
+
|
5
7
|
module SqlMatchers
|
6
8
|
module Matchers
|
7
9
|
class Sql
|
8
|
-
QUOTED_IDENT_RE = /[`"](\w+)[`"]/
|
9
|
-
|
10
10
|
attr_reader :actual, :expected
|
11
11
|
|
12
12
|
def initialize(expected)
|
13
|
-
@expected
|
14
|
-
@
|
13
|
+
@expected = expected
|
14
|
+
@normalizer = Normalizers::Sql.new
|
15
|
+
@formatter = AnbtSql::Formatter.new(
|
15
16
|
AnbtSql::Rule.new.tap do |r|
|
16
17
|
r.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
|
17
18
|
r.function_names += %w[count sum substr date]
|
@@ -22,11 +23,8 @@ module SqlMatchers
|
|
22
23
|
|
23
24
|
def diffable? = true
|
24
25
|
def matches?(actual)
|
25
|
-
@expected = formatter.format(
|
26
|
-
|
27
|
-
|
28
|
-
@actual = formatter.format(+actual.to_s.strip)
|
29
|
-
.gsub(QUOTED_IDENT_RE, '\1')
|
26
|
+
@expected = formatter.format(normalizer.normalize(expected.to_s.strip))
|
27
|
+
@actual = formatter.format(normalizer.normalize(actual.to_s.strip))
|
30
28
|
|
31
29
|
@actual == @expected
|
32
30
|
end
|
@@ -43,7 +41,7 @@ module SqlMatchers
|
|
43
41
|
|
44
42
|
private
|
45
43
|
|
46
|
-
attr_reader :formatter
|
44
|
+
attr_reader :formatter, :normalizer
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'anbt-sql-formatter/formatter'
|
4
|
+
|
5
|
+
module SqlMatchers
|
6
|
+
module Normalizers
|
7
|
+
class Sql
|
8
|
+
QUOTED_IDENT_RE = /[`"](\w+)[`"]/
|
9
|
+
SELECT_STAR_RE = /[`"]?(\w+)[`"]?\s{,1}\*/
|
10
|
+
|
11
|
+
def normalize(sql) = +sql.gsub(SELECT_STAR_RE, '\1.*')
|
12
|
+
.gsub(QUOTED_IDENT_RE, '\1')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/sql_matchers/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.rc.
|
4
|
+
version: 1.0.0.pre.rc.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- lib/sql_matchers/matchers/query.rb
|
86
86
|
- lib/sql_matchers/matchers/sql.rb
|
87
87
|
- lib/sql_matchers/methods.rb
|
88
|
+
- lib/sql_matchers/normalizers.rb
|
89
|
+
- lib/sql_matchers/normalizers/sql.rb
|
88
90
|
- lib/sql_matchers/version.rb
|
89
91
|
homepage: https://github.com/keygen-sh/sql_matchers
|
90
92
|
licenses:
|