mulang 5.0.0 → 5.1.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: 9175932c143b6a0841997e1400944429565ba33beb09aabbbd9183117a041791
4
- data.tar.gz: b9f93712987684230b357cbf4fcccd9a231fce0873c67f38db57cfe6c7f5fed0
3
+ metadata.gz: 57cbb3086b4bddd286d787889961a658c45b2a32c5a131f5f86404ee714607f3
4
+ data.tar.gz: '047820d569e4a86ece08c14a117777444991c0c5d4e53012a033ef68806d4883'
5
5
  SHA512:
6
- metadata.gz: d8cb2ca9a340f56f504e8c70be5d44b24d3c7ebb344eb93695abed8d6c136dd9a2196a84169e238d9d2afc8e5a4c22fa946b65804cf83a4a3580625a51bceab7
7
- data.tar.gz: 94bd5b78f772d46e15e341d4264fdf7bca020081dfe9e3ddff05dd04df3664cedeac77413577bd0c641bc7ae441f980b932b9d9601d0a8c9083d00c77521517b
6
+ metadata.gz: e4a096e0a186d663cb521b8cea49877433c1622329f78cc5c884338085fddceb69918861c550aa1afc86e8e3d8b26e2fa5436c74a4a6da951609cb7f8697be65
7
+ data.tar.gz: 1e01645471e77d50392af5f2716cbdb7881da28998d4fa13a0f64b6df37a9b16327edb72804000ed23f551d90756d67a31a735810ae2795986ef801231dc212a
data/bin/mulang CHANGED
Binary file
@@ -123,6 +123,7 @@ en:
123
123
  HasRedundantLocalVariableReturn: '%{binding} has unnecesary local variables; please try returning the expression directly'
124
124
  HasRedundantParameter: '%{binding} has unnecessary parameters, that can be removed using point-free'
125
125
  HasRedundantReduction: '%{binding} uses <i>%{keyword_is}</i>, but it does not artihmetic'
126
+ HasRedundantRepeat: '%{binding} has an unnecesary <i>%{keyword_repeat}</i>'
126
127
  HasTooManyMethods: '%{binding} has too many methods'
127
128
  HasTooShortBindings: '%{binding} is a too short identifier'
128
129
  HasTooShortIdentifiers: '%{binding} is a too short identifier'
@@ -127,6 +127,7 @@ es:
127
127
  HasRedundantLocalVariableReturn: '%{binding} usa variables locales innecesarias; podés retornar directamente la expresión'
128
128
  HasRedundantParameter: '%{binding} tiene parámetros innecesarios (se pueden eliminar mediante point-free)'
129
129
  HasRedundantReduction: '%{binding} usa <i>%{keyword_is}</i>, pero no realiza cálculos'
130
+ HasRedundantRepeat: '%{binding} tiene un <i>%{keyword_repeat}</i> innecesario'
130
131
  HasTooManyMethods: '%{binding} tiene demasiados métodos'
131
132
  HasTooShortBindings: '%{binding} es un identificador muy corto'
132
133
  HasTooShortIdentifiers: '%{binding} es un identificador muy corto'
@@ -122,11 +122,12 @@ pt:
122
122
  HasMisspelledIdentifiers: '%{binding} está incorreto. Verifique a ortografia e tente não usar abreviaturas'
123
123
  HasRedundantBooleanComparison: '%{binding} faz comparações booleanas desnecessárias'
124
124
  HasRedundantGuards: '%{binding} possui protetores desnecessários'
125
- HasRedundantIf: '%{binding} tem desnecessário ifs'
125
+ HasRedundantIf: '%{binding} <i>%{keyword_if}</i> desnecessário'
126
126
  HasRedundantLambda: '%{binding} possui lambdas desnecessários'
127
127
  HasRedundantLocalVariableReturn: '%{binding} usa variáveis ​​locais desnecessárias; você pode retornar a expressão diretamente'
128
128
  HasRedundantParameter: '%{binding} possui parâmetros desnecessários (pode ser removido por ponto-livre)'
129
129
  HasRedundantReduction: '%{binding} usa <i>%{keyword_is}</i>, mas não executa cálculos'
130
+ HasRedundantRepeat: '%{binding} tem <i>%{keyword_repeat}</i> desnecessário'
130
131
  HasTooManyMethods: '%{binding} tem muitos métodos'
131
132
  HasTooShortBindings: '%{binding} é um identificador muito curto'
132
133
  HasTooShortIdentifiers: '%{binding} é um identificador muito curto'
@@ -22,8 +22,7 @@ module Mulang
22
22
  end
23
23
 
24
24
  def expect(binding='*', inspection)
25
- expectation = {binding: binding, inspection: inspection}
26
- Mulang::Expectation.parse expectation
25
+ expectation = Mulang::Expectation.parse(binding: binding, inspection: inspection).as_v2.to_h
27
26
  expectation_results_for(analyse(expectations: [expectation])).first['result']
28
27
  end
29
28
 
@@ -1,7 +1,6 @@
1
- class Mulang::Expectation
2
-
1
+ module Mulang::Expectation
3
2
  SMELLS = %w(DiscardsExceptions DoesConsolePrint DoesNilTest DoesNullTest DoesTypeTest
4
- HasAssignmentReturn HasCodeDuplication HasEmptyIfBranches HasLongParameterList
3
+ HasAssignmentReturn HasCodeDuplication HasEmptyIfBranches HasRedundantRepeat HasLongParameterList
5
4
  HasMisspelledBindings HasMisspelledIdentifiers
6
5
  HasRedundantBooleanComparison HasRedundantGuards HasRedundantIf
7
6
  HasRedundantLambda HasRedundantLocalVariableReturn HasRedundantParameter
@@ -9,28 +8,10 @@ class Mulang::Expectation
9
8
  HasWrongCaseBinding HasWrongCaseIdentifiers IsLongCode OverridesEqualOrHashButNotBoth
10
9
  ReturnsNil ReturnsNull UsesCut UsesFail UsesUnificationOperator)
11
10
 
12
- attr_accessor :binding, :inspection
13
-
14
- def initialize(binding, inspection)
15
- @binding = binding
16
- @inspection = inspection
17
- end
18
-
19
- def check!
20
- raise "Wrong binding in #{to_h}" unless binding?
21
- raise "Wrong inspection #{to_h}" unless inspection?
22
- end
23
-
24
- def translate(keywords = nil)
25
- Mulang::Expectation::I18n.translate self, keywords
26
- end
27
-
28
- def to_h
29
- {binding: binding, inspection: inspection.to_s}
30
- end
31
-
32
11
  def self.guess_type(expectation)
33
- if expectation[:inspection] =~ /(Not\:)?Has.*/ && !has_smell?(expectation[:inspection])
12
+ if expectation[:binding] == '<<custom>>'
13
+ Custom
14
+ elsif expectation[:inspection] =~ /(Not\:)?Has.*/ && !has_smell?(expectation[:inspection])
34
15
  V0
35
16
  else
36
17
  V2
@@ -42,72 +23,14 @@ class Mulang::Expectation
42
23
  end
43
24
 
44
25
  def self.parse(expectation)
45
- guess_type(expectation).new(
46
- expectation[:binding],
47
- Mulang::Inspection.parse(expectation[:inspection]))
26
+ guess_type(expectation).parse(expectation)
48
27
  end
49
28
 
50
29
  def self.valid?(expectation)
51
- !!Mulang::Inspection.parse(expectation['inspection']) rescue false
52
- end
53
-
54
- class V0 < Mulang::Expectation
55
- INSPECTIONS = %w(HasBinding HasTypeDeclaration HasTypeSignature HasVariable HasArity HasDirectRecursion
56
- HasComposition HasComprehension HasForeach HasIf HasGuards HasConditional HasLambda HasRepeat HasWhile
57
- HasUsage HasAnonymousVariable HasNot HasForall HasFindall)
58
-
59
-
60
- def binding?
61
- binding.present?
62
- end
63
-
64
- def inspection?
65
- inspection.present? && INSPECTIONS.include?(inspection.type)
66
- end
67
-
68
- def as_v2
69
- if has? 'Binding' then as_v2_declare ''
70
- elsif has? 'TypeDeclaration' then as_v2_declare 'TypeAlias'
71
- elsif has? 'TypeSignature' then as_v2_declare 'TypeSignature'
72
- elsif has? 'Variable' then as_v2_declare 'Variable'
73
- elsif has? 'Arity' then as_v2_declare "ComputationWithArity#{inspection.target.value}"
74
- elsif has? 'DirectRecursion' then as_v2_declare "Recursively"
75
- elsif has? 'Usage'
76
- V2.new binding, new_inspection('Uses', Mulang::Inspection::Target.named(inspection.target.value))
77
- else as_v2_use
78
- end
79
- end
80
-
81
- def has?(simple_type)
82
- inspection.type == "Has#{simple_type}"
83
- end
84
-
85
- def as_v2_use
86
- V2.new binding, new_inspection(inspection.type.gsub('Has', 'Uses'), nil)
87
- end
88
-
89
- def as_v2_declare(simple_type)
90
- V2.new '*', new_inspection("Declares#{simple_type}", Mulang::Inspection::Target.named(binding))
91
- end
92
-
93
- def new_inspection(type, target)
94
- Mulang::Inspection.new(type, target, negated: inspection.negated?)
95
- end
96
- end
97
-
98
- class V2 < Mulang::Expectation
99
- def binding?
100
- true
101
- end
102
-
103
- def inspection?
104
- true
105
- end
106
-
107
- def as_v2
108
- self
109
- end
30
+ guess_type(expectation).valid?(expectation)
110
31
  end
111
32
  end
112
33
 
113
34
  require_relative './expectation/i18n'
35
+ require_relative './expectation/custom'
36
+ require_relative './expectation/standard'
@@ -0,0 +1,31 @@
1
+ class Mulang::Expectation::Custom
2
+ attr_accessor :name
3
+
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def translate(*)
9
+ name
10
+ end
11
+
12
+ def to_h
13
+ {binding: '<<custom>>', inspection: name}
14
+ end
15
+
16
+ def custom?
17
+ true
18
+ end
19
+
20
+ def standard?
21
+ false
22
+ end
23
+
24
+ def self.parse(expectation)
25
+ new expectation[:inspection]
26
+ end
27
+
28
+ def self.valid?(_)
29
+ true
30
+ end
31
+ end
@@ -0,0 +1,95 @@
1
+ class Mulang::Expectation::Standard
2
+ attr_accessor :binding, :inspection
3
+
4
+ def initialize(binding, inspection)
5
+ @binding = binding
6
+ @inspection = inspection
7
+ end
8
+
9
+ def check!
10
+ raise "Wrong binding in #{to_h}" unless binding?
11
+ raise "Wrong inspection #{to_h}" unless inspection?
12
+ end
13
+
14
+ def translate(keywords = nil)
15
+ Mulang::Expectation::I18n.translate self, keywords
16
+ end
17
+
18
+ def to_h
19
+ {binding: binding, inspection: inspection.to_s}
20
+ end
21
+
22
+ def custom?
23
+ false
24
+ end
25
+
26
+ def standard?
27
+ true
28
+ end
29
+
30
+ def self.parse(expectation)
31
+ new expectation[:binding], Mulang::Inspection.parse(expectation[:inspection])
32
+ end
33
+
34
+ def self.valid?(expectation)
35
+ !!Mulang::Inspection.parse(expectation['inspection']) rescue false
36
+ end
37
+ end
38
+
39
+ class Mulang::Expectation::V0 < Mulang::Expectation::Standard
40
+ INSPECTIONS = %w(HasBinding HasTypeDeclaration HasTypeSignature HasVariable HasArity HasDirectRecursion
41
+ HasComposition HasComprehension HasForeach HasIf HasGuards HasConditional HasLambda HasRepeat HasWhile
42
+ HasUsage HasAnonymousVariable HasNot HasForall HasFindall)
43
+
44
+
45
+ def binding?
46
+ binding.present?
47
+ end
48
+
49
+ def inspection?
50
+ inspection.present? && INSPECTIONS.include?(inspection.type)
51
+ end
52
+
53
+ def as_v2
54
+ if has? 'Binding' then as_v2_declare ''
55
+ elsif has? 'TypeDeclaration' then as_v2_declare 'TypeAlias'
56
+ elsif has? 'TypeSignature' then as_v2_declare 'TypeSignature'
57
+ elsif has? 'Variable' then as_v2_declare 'Variable'
58
+ elsif has? 'Arity' then as_v2_declare "ComputationWithArity#{inspection.target.value}"
59
+ elsif has? 'DirectRecursion' then as_v2_declare "Recursively"
60
+ elsif has? 'Usage'
61
+ Mulang::Expectation::V2.new binding, new_inspection('Uses', Mulang::Inspection::Target.named(inspection.target.value))
62
+ else as_v2_use
63
+ end
64
+ end
65
+
66
+ def has?(simple_type)
67
+ inspection.type == "Has#{simple_type}"
68
+ end
69
+
70
+ def as_v2_use
71
+ Mulang::Expectation::V2.new binding, new_inspection(inspection.type.gsub('Has', 'Uses'), nil)
72
+ end
73
+
74
+ def as_v2_declare(simple_type)
75
+ Mulang::Expectation::V2.new '*', new_inspection("Declares#{simple_type}", Mulang::Inspection::Target.named(binding))
76
+ end
77
+
78
+ def new_inspection(type, target)
79
+ Mulang::Inspection.new(type, target, negated: inspection.negated?)
80
+ end
81
+ end
82
+
83
+ class Mulang::Expectation::V2 < Mulang::Expectation::Standard
84
+ def binding?
85
+ true
86
+ end
87
+
88
+ def inspection?
89
+ true
90
+ end
91
+
92
+ def as_v2
93
+ self
94
+ end
95
+ end
@@ -28,7 +28,7 @@ module Mulang
28
28
  end
29
29
 
30
30
  def to_s
31
- "#{negated_to_s}#{type}#{target_to_s}"
31
+ "#{negated_to_s}#{type}#{target_to_s}#{matcher_to_s}"
32
32
  end
33
33
 
34
34
  def negated_to_s
@@ -39,6 +39,10 @@ module Mulang
39
39
  target ? ":#{target.to_s}" : nil
40
40
  end
41
41
 
42
+ def matcher_to_s
43
+ matcher ? ":#{matcher.to_s}" : nil
44
+ end
45
+
42
46
  def self.parse_binding_name(binding_s)
43
47
  if binding_s.start_with? 'Intransitive:'
44
48
  binding_s[13..-1]
@@ -10,6 +10,10 @@ class Mulang::Inspection::Matcher
10
10
  @value = value
11
11
  end
12
12
 
13
+ def to_s
14
+ "#{type.to_s.camelcase}#{value ? ":#{value}" : nil}"
15
+ end
16
+
13
17
  def self.parse(type, value)
14
18
  return nil unless type
15
19
  raise "Invalid matcher #{type}" unless type.in? TYPES
@@ -1,4 +1,4 @@
1
1
  module Mulang
2
- VERSION = "5.0.0"
3
- MULANG_VERSION = "5.0.0"
2
+ VERSION = "5.1.0"
3
+ MULANG_VERSION = "5.1.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mulang
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit-core
@@ -96,7 +96,9 @@ files:
96
96
  - lib/mulang.rb
97
97
  - lib/mulang/code.rb
98
98
  - lib/mulang/expectation.rb
99
+ - lib/mulang/expectation/custom.rb
99
100
  - lib/mulang/expectation/i18n.rb
101
+ - lib/mulang/expectation/standard.rb
100
102
  - lib/mulang/inspection.rb
101
103
  - lib/mulang/inspection/matcher.rb
102
104
  - lib/mulang/inspection/target.rb