typ-formatter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/typ/formatter.rb +49 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247b0274ef455b8940e1c651f7559a995a53194da880873ebe7d403a27e754a0
|
4
|
+
data.tar.gz: e2aa7239e375f5f2f9a061347c55aba54c22d9adc27dfcde78ebe3aa660e6c4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e549112ce1f63d3cc2bb8d0df3836fb7042cf91162f43b443fad2a3c84c160ba11b9ccf41b51eaabb3921fab884c752695925215238ca3b5fc30b74ee61494a2
|
7
|
+
data.tar.gz: bb1da432b0e3a2df36ce63717d8339bb36e09f00d8d8099010c698edce0c7cee75c1daa009e02015f2ed4d3fc406270e6695f133a34e4d4aa5d76c6a36d3e464
|
data/lib/typ/formatter.rb
CHANGED
@@ -3,12 +3,45 @@ module Typ
|
|
3
3
|
module FormatGate
|
4
4
|
class Formatter
|
5
5
|
def initialize gate
|
6
|
-
@
|
6
|
+
@gate = gate
|
7
|
+
@string = format
|
7
8
|
end
|
8
9
|
|
10
|
+
attr_reader :gate
|
11
|
+
|
9
12
|
def to_s
|
10
13
|
@string
|
11
14
|
end
|
15
|
+
|
16
|
+
def head
|
17
|
+
@head ||= if gate.dsl_key
|
18
|
+
"#{gate.dsl_method} #{gate.dsl_key.inspect} #{gate.dsl_literal.inspect}"
|
19
|
+
else
|
20
|
+
"#{gate.dsl_method} #{gate.dsl_literal}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def actual
|
25
|
+
end
|
26
|
+
|
27
|
+
def format
|
28
|
+
if gate.ok?
|
29
|
+
Rainbow(head).green
|
30
|
+
else
|
31
|
+
error = gate.error
|
32
|
+
string = case error
|
33
|
+
when Typ::Error::BadAssertion
|
34
|
+
actual_type = "got #{actual.class}".indent 2
|
35
|
+
actual_value = actual.ai.indent 4
|
36
|
+
|
37
|
+
actual_type + "\n" + actual_value
|
38
|
+
else
|
39
|
+
(error.class.to_s.indent 2) + ":\n" + (error.to_s.indent 4)
|
40
|
+
end
|
41
|
+
|
42
|
+
Rainbow(head).red + "\n" + string
|
43
|
+
end
|
44
|
+
end
|
12
45
|
end
|
13
46
|
|
14
47
|
module ToPascalCase
|
@@ -29,12 +62,12 @@ module Typ
|
|
29
62
|
else
|
30
63
|
FormatGate
|
31
64
|
.const_get(gate.dsl_method.to_pascal_case)
|
32
|
-
.new(gate)
|
65
|
+
.new(gate)
|
33
66
|
end
|
34
67
|
end
|
35
68
|
|
36
69
|
class Is < Formatter
|
37
|
-
def format
|
70
|
+
def format
|
38
71
|
literal = gate.dsl_literal
|
39
72
|
|
40
73
|
case literal
|
@@ -46,7 +79,7 @@ module Typ
|
|
46
79
|
end
|
47
80
|
|
48
81
|
class IsA < Formatter
|
49
|
-
def format
|
82
|
+
def format
|
50
83
|
string = "is_a #{gate.dsl_literal}"
|
51
84
|
|
52
85
|
if gate.ok?
|
@@ -56,6 +89,18 @@ module Typ
|
|
56
89
|
end
|
57
90
|
end
|
58
91
|
end
|
92
|
+
|
93
|
+
class Its < Formatter
|
94
|
+
def actual
|
95
|
+
gate.it.send gate.dsl_key
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Key < Formatter
|
100
|
+
def actual
|
101
|
+
gate.it[gate.dsl_key]
|
102
|
+
end
|
103
|
+
end
|
59
104
|
end
|
60
105
|
|
61
106
|
require 'string/indent'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typ-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoly Chernov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typ
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.1
|
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: 0.1.
|
26
|
+
version: 0.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rainbow
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|