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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea820ab15f14da9e85e40d721cc0744edfabf5cf6b42dfbc89eebf714acbf74c
4
- data.tar.gz: 60d94b0722065797839159faf66e985f0f3b85c1f317858a9b04a9b52e82f0e3
3
+ metadata.gz: e0cde4f12d9a94e037920bb6549a52e2ae29f14bcb8eea6efa1ea64dc927b777
4
+ data.tar.gz: cf5b0efb6152a3ad11783ee44cc38083468b9e67b001e3eb8b78ced87a985a06
5
5
  SHA512:
6
- metadata.gz: '092790d059e6d1c066acd87b8c3a23b8bf59eb2677a8abf8bc554e754e358ff37440722a4625fbed7f1bd08518603756050e193a849dfb775653386109cb8576'
7
- data.tar.gz: e1788fe82defea276dac318dd158afd96ba9a5551f79d2628428c5a26778868c95a80b5754db43a3e0fe2bfb536e91ed739f9f8d7db18c5effb279df134d0b61
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 = expected
14
- @formatter = AnbtSql::Formatter.new(
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(+expected.to_s.strip)
26
- .gsub(QUOTED_IDENT_RE, '\1')
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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'normalizers/sql'
4
+
5
+ module SqlMatchers
6
+ module Normalizers; end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SqlMatchers
4
- VERSION = '1.0.0-rc.2'
4
+ VERSION = '1.0.0-rc.3'
5
5
  end
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.2
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: