mumuki-text-runner 1.2.1 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff637b59a63ae832dbb1707f9ca1c5fd43a1df4a70531d307626449007e59e1c
4
- data.tar.gz: a936a8b9382eb3219615f006fd41b7c2c551b33a5f220bdf087faf6fb8b94770
3
+ metadata.gz: 5b6cf60acdbbbea2a93591a35f6798f31e97138768b7f715f9be0b5fdd945901
4
+ data.tar.gz: 38891926782f7edb4d5a40928162ae66e507727c7dda9b35cd72840e33853239
5
5
  SHA512:
6
- metadata.gz: 4ac21ef25b3fb829eb341bde542388285436dccb5f24f99a541579ccf78528ced3d45b2c037124df368fe51d1bdaa018885ea38b32d05871860dda3f3fa35259
7
- data.tar.gz: edb1488843f13aa4046ed7d695425067a1069d965119e80cea903da2ca6c0c64e88ba75263af341e656fd975cacf8fac346fb8f5f801b4faed1cc1f7aaedce63
6
+ metadata.gz: d8f03d8e82ebf3bd9e72aef871e5aa2e429d022c0d332a3f59cd6e6067346618dc1b43d850fa096d803fd97b22a8e037ce60ecec581c094ed35b0cf8bea9de5e
7
+ data.tar.gz: 5515417742c30efe5b90b2b3675ce565950d8056ee51b0c3e84bc5f08a0533628144a1f265b2dce6d6f95e04af7a6e5a2dba13fa929071f58d3f73da356fd024
data/lib/checker.rb CHANGED
@@ -1,17 +1,41 @@
1
1
  class TextChecker < Mumukit::Metatest::Checker
2
- def self.compare(relation_hash)
3
- raise 'Invalid hash arity' if relation_hash.size != 1
4
- type = relation_hash.keys.first
5
- comparator_class = relation_hash.values.first
6
- define_method "check_#{type}".to_sym do |test, config|
7
- comparator_class
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/lenient_blank'
9
+ require_relative './options/ignore_case'
10
+ require_relative './options/ignore_whitespace'
11
+ require_relative './options/multiline'
12
+
13
+ COMPARATORS = {
14
+ match: TextChecker::RegexpComparator,
15
+ equal: TextChecker::EqualityComparator,
16
+ contain: TextChecker::ContainComparator,
17
+ valid_ip: TextChecker::ValidIpComparator
18
+ }
19
+
20
+ def check_assertion(key, input, config, example)
21
+ if key == :keys
22
+ check_keys input, config, example
23
+ else
24
+ check_comparators key, input, config
25
+ end
26
+ end
27
+
28
+ def check_comparators(key, input, config)
29
+ COMPARATORS[key]
8
30
  .new(config.is_a?(Hash) ? config : {expected: config})
9
- .compare(test[:source])
31
+ .compare(input[:source])
10
32
  .try { |error| fail error }
11
- end
12
33
  end
13
34
 
14
- compare :match => RegexpComparator
15
- compare :equal => EqualityComparator
16
- compare :contain => ContainComparator
35
+ def check_keys(input, config, example)
36
+ source_hash = YAML.load(input[:source]).with_indifferent_access
37
+ config.each do |subkey, subconfig|
38
+ check_assertions({source: source_hash[subkey]}, subconfig, example)
39
+ end
40
+ end
17
41
  end
@@ -1,21 +1,24 @@
1
- class Comparator
2
- def initialize(opts)
3
- @expected = opts[:expected]
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
- @error_message || error_message(source) unless success?(source)
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::IgnoreCase if @config[:ignore_case]
19
+ modifiers << TextChecker::LenientBlank if @config[:lenient_blank]
20
+ modifiers << TextChecker::IgnoreWhitespace if @config[:ignore_whitespace]
21
+ modifiers << TextChecker::Multiline if @config[:multiline]
19
22
  modifiers
20
23
  end
21
24
 
@@ -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
- transform(source).include? transform(@expected)
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
- transform(source) == transform(@expected)
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
- !!@expected_regexp.match(source)
4
+ !!Regexp.new(expected).match(source)
7
5
  end
8
6
 
9
- def setup
10
- @expected_regexp = eval_regexp(@expected)
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
@@ -5,3 +5,5 @@ en:
5
5
  failure: '**%{actual}** does not contain the right value.'
6
6
  expression:
7
7
  failure: '**%{actual}** does not match the expected expression.'
8
+ valid_ip:
9
+ failure: '**%{actual}** is not a valid IP address.'
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
- failure: '**%{actual}** no coincide con la expresión correcta.'
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/metadata_hook.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  class TextMetadataHook < Mumukit::Hook
2
2
  def metadata
3
- { language: {
3
+ {
4
+ language: {
4
5
  name: 'text',
5
6
  icon: { type: 'devicon', name: 'code' },
6
7
  extension: 'txt',
7
- test_framework: {
8
- name: 'text',
9
- test_extension: 'yml'
10
- }
11
- } }
8
+ },
9
+ test_framework: {
10
+ name: 'text',
11
+ test_extension: 'yml'
12
+ }
13
+ }
12
14
  end
13
15
  end
@@ -1,7 +1,5 @@
1
- module IgnoreCase
2
- class << self
3
- def apply(text)
4
- text.downcase
5
- end
1
+ module TextChecker::IgnoreCase
2
+ def self.apply(text)
3
+ text.downcase
6
4
  end
7
5
  end
@@ -1,7 +1,5 @@
1
- module IgnoreWhitespace
2
- class << self
3
- def apply(text)
4
- text.delete(' ')
5
- end
1
+ module TextChecker::IgnoreWhitespace
2
+ def self.apply(text)
3
+ text.delete(' ')
6
4
  end
7
5
  end
@@ -0,0 +1,5 @@
1
+ module TextChecker::LenientBlank
2
+ def self.apply(text)
3
+ text.gsub("\t", ' ').squeeze(' ')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module TextChecker::Multiline
2
+ def self.apply(text)
3
+ text.gsub("\r\n", "\n")
4
+ end
5
+ end
data/lib/test_hook.rb CHANGED
@@ -30,7 +30,9 @@ class TextTestHook < Mumukit::Hook
30
30
  postconditions: { equal: {
31
31
  expected: parsed_test['equal'],
32
32
  ignore_case: parsed_test['ignore_case'].present?,
33
- ignore_whitespace: parsed_test['ignore_whitespace'].present? } }
33
+ ignore_whitespace: parsed_test['ignore_whitespace'].present?,
34
+ lenient_blank: parsed_test['lenient_blank'].present?,
35
+ multiline: parsed_test['multiline'].present? } }
34
36
  }]
35
37
  end
36
38
 
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
@@ -1,3 +1,3 @@
1
1
  module TextVersionHook
2
- VERSION = '1.2.1'
2
+ VERSION = '1.5.0'
3
3
  end
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.2.1
4
+ version: 1.5.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-02-27 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.7'
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.7'
26
+ version: '2.27'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -120,11 +120,14 @@ 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
126
127
  - lib/options/ignore_case.rb
127
128
  - lib/options/ignore_whitespace.rb
129
+ - lib/options/lenient_blank.rb
130
+ - lib/options/multiline.rb
128
131
  - lib/test_hook.rb
129
132
  - lib/text_runner.rb
130
133
  - lib/version_hook.rb
@@ -147,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
150
  - !ruby/object:Gem::Version
148
151
  version: '0'
149
152
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.6
153
+ rubygems_version: 3.0.3
152
154
  signing_key:
153
155
  specification_version: 4
154
156
  summary: Text Runner for Mumuki