mumuki-text-runner 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/checker.rb +33 -11
- data/lib/comparators/comparator.rb +10 -9
- data/lib/comparators/contain_comparator.rb +4 -4
- data/lib/comparators/equality_comparator.rb +4 -4
- data/lib/comparators/regexp_comparator.rb +4 -11
- data/lib/comparators/valid_ip_comparator.rb +14 -0
- data/lib/locales/en.yml +2 -0
- data/lib/locales/es.yml +3 -1
- data/lib/options/ignore_case.rb +3 -5
- data/lib/options/ignore_whitespace.rb +3 -5
- data/lib/text_runner.rb +0 -8
- data/lib/version_hook.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2b935fa7c9c7cccead52aa65543db209da093b16779b51944ccf4f5053412d5
|
4
|
+
data.tar.gz: 14ef6d6d43802dcd76008c27d5275452b09b5c668454163fecec74fe7c90304e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: badaa8753e28b572c4adf18559c83f0f1a0ba4797397aa38bd525374be68022771a716c9c09565430ffee2695ee9f3543d2b98ebb46d28d2b3f7384cdb2b146e
|
7
|
+
data.tar.gz: 39c00537548e07b45e900519ff0b5e784a8baa34fd9c0055a2d5b0aac2a6d513ffc8f93470621fd042486034ea37c24e130729a1663c1362a91e5dbcb1286d51
|
data/lib/checker.rb
CHANGED
@@ -1,17 +1,39 @@
|
|
1
1
|
class TextChecker < Mumukit::Metatest::Checker
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
require_relative './comparators/comparator'
|
3
|
+
require_relative './comparators/equality_comparator'
|
4
|
+
require_relative './comparators/contain_comparator'
|
5
|
+
require_relative './comparators/regexp_comparator'
|
6
|
+
require_relative './comparators/valid_ip_comparator'
|
7
|
+
|
8
|
+
require_relative './options/ignore_whitespace'
|
9
|
+
require_relative './options/ignore_case'
|
10
|
+
|
11
|
+
COMPARATORS = {
|
12
|
+
match: TextChecker::RegexpComparator,
|
13
|
+
equal: TextChecker::EqualityComparator,
|
14
|
+
contain: TextChecker::ContainComparator,
|
15
|
+
valid_ip: TextChecker::ValidIpComparator
|
16
|
+
}
|
17
|
+
|
18
|
+
def check_assertion(key, input, config, example)
|
19
|
+
if key == :keys
|
20
|
+
check_keys input, config, example
|
21
|
+
else
|
22
|
+
check_comparators key, input, config
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_comparators(key, input, config)
|
27
|
+
COMPARATORS[key]
|
8
28
|
.new(config.is_a?(Hash) ? config : {expected: config})
|
9
|
-
.compare(
|
29
|
+
.compare(input[:source])
|
10
30
|
.try { |error| fail error }
|
11
|
-
end
|
12
31
|
end
|
13
32
|
|
14
|
-
|
15
|
-
|
16
|
-
|
33
|
+
def check_keys(input, config, example)
|
34
|
+
source_hash = YAML.load(input[:source]).with_indifferent_access
|
35
|
+
config.each do |subkey, subconfig|
|
36
|
+
check_assertions({source: source_hash[subkey]}, subconfig, example)
|
37
|
+
end
|
38
|
+
end
|
17
39
|
end
|
@@ -1,21 +1,22 @@
|
|
1
|
-
class Comparator
|
2
|
-
def initialize(
|
3
|
-
@
|
4
|
-
@error_message = opts[:error]
|
5
|
-
@config = opts
|
6
|
-
setup if respond_to?(:setup, true)
|
1
|
+
class TextChecker::Comparator
|
2
|
+
def initialize(config = {})
|
3
|
+
@config = config
|
7
4
|
end
|
8
5
|
|
9
6
|
def compare(source)
|
10
|
-
@
|
7
|
+
@config[:error] || error_message(source) unless success?(transform(source))
|
8
|
+
end
|
9
|
+
|
10
|
+
def expected
|
11
|
+
transform @config[:expected]
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def modifiers
|
16
17
|
modifiers = []
|
17
|
-
modifiers << IgnoreWhitespace if @config[:ignore_whitespace]
|
18
|
-
modifiers << IgnoreCase if @config[:ignore_case]
|
18
|
+
modifiers << TextChecker::IgnoreWhitespace if @config[:ignore_whitespace]
|
19
|
+
modifiers << TextChecker::IgnoreCase if @config[:ignore_case]
|
19
20
|
modifiers
|
20
21
|
end
|
21
22
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class ContainComparator < Comparator
|
2
|
-
|
3
|
-
private
|
1
|
+
class TextChecker::ContainComparator < TextChecker::Comparator
|
4
2
|
|
5
3
|
def success?(source)
|
6
|
-
|
4
|
+
source.include? expected.to_s
|
7
5
|
end
|
8
6
|
|
7
|
+
private
|
8
|
+
|
9
9
|
def error_message(source)
|
10
10
|
I18n.t 'contain.failure', actual: source
|
11
11
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class EqualityComparator < Comparator
|
2
|
-
|
3
|
-
private
|
1
|
+
class TextChecker::EqualityComparator < TextChecker::Comparator
|
4
2
|
|
5
3
|
def success?(source)
|
6
|
-
|
4
|
+
source == expected.to_s
|
7
5
|
end
|
8
6
|
|
7
|
+
private
|
8
|
+
|
9
9
|
def error_message(source)
|
10
10
|
I18n.t 'equality.failure', actual: source
|
11
11
|
end
|
@@ -1,20 +1,13 @@
|
|
1
|
-
class RegexpComparator < Comparator
|
2
|
-
|
3
|
-
private
|
1
|
+
class TextChecker::RegexpComparator < TextChecker::Comparator
|
4
2
|
|
5
3
|
def success?(source)
|
6
|
-
|
4
|
+
!!Regexp.new(expected).match(source)
|
7
5
|
end
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
private
|
8
|
+
|
12
9
|
|
13
10
|
def error_message(source)
|
14
11
|
I18n.t 'expression.failure', actual: source
|
15
12
|
end
|
16
|
-
|
17
|
-
def eval_regexp(expression)
|
18
|
-
Regexp.new(expression)
|
19
|
-
end
|
20
13
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class TextChecker::ValidIpComparator < TextChecker::Comparator
|
2
|
+
|
3
|
+
def success?(source)
|
4
|
+
!!REGEXP.match(source)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
REGEXP = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i
|
10
|
+
|
11
|
+
def error_message(source)
|
12
|
+
I18n.t 'valid_ip.failure', actual: source
|
13
|
+
end
|
14
|
+
end
|
data/lib/locales/en.yml
CHANGED
data/lib/locales/es.yml
CHANGED
@@ -4,4 +4,6 @@ es:
|
|
4
4
|
contain:
|
5
5
|
failure: '**%{actual}** no contiene el valor correcto.'
|
6
6
|
expression:
|
7
|
-
|
7
|
+
failure: '**%{actual}** no coincide con la expresión correcta.'
|
8
|
+
valid_ip:
|
9
|
+
failure: '**%{actual}** no es una dirección IP válida.'
|
data/lib/options/ignore_case.rb
CHANGED
data/lib/text_runner.rb
CHANGED
@@ -12,12 +12,4 @@ require_relative './version_hook'
|
|
12
12
|
require_relative './metadata_hook'
|
13
13
|
require_relative './test_hook'
|
14
14
|
|
15
|
-
require_relative './comparators/comparator'
|
16
|
-
require_relative './comparators/equality_comparator'
|
17
|
-
require_relative './comparators/contain_comparator'
|
18
|
-
require_relative './comparators/regexp_comparator'
|
19
|
-
|
20
|
-
require_relative './options/ignore_whitespace'
|
21
|
-
require_relative './options/ignore_case'
|
22
|
-
|
23
15
|
require_relative './checker'
|
data/lib/version_hook.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-text-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.27'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.27'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/comparators/contain_comparator.rb
|
121
121
|
- lib/comparators/equality_comparator.rb
|
122
122
|
- lib/comparators/regexp_comparator.rb
|
123
|
+
- lib/comparators/valid_ip_comparator.rb
|
123
124
|
- lib/locales/en.yml
|
124
125
|
- lib/locales/es.yml
|
125
126
|
- lib/metadata_hook.rb
|
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
version: '0'
|
149
150
|
requirements: []
|
150
151
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.7.
|
152
|
+
rubygems_version: 2.7.7
|
152
153
|
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: Text Runner for Mumuki
|