xmp2assert 1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +172 -0
- data/.yardopts +5 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +19 -0
- data/README.md +40 -0
- data/Rakefile +61 -0
- data/Stylegiude.md +284 -0
- data/exe/xmpcheck.rb +75 -0
- data/lib/xmp2assert/assertions.rb +157 -0
- data/lib/xmp2assert/classifier.rb +71 -0
- data/lib/xmp2assert/converter.rb +113 -0
- data/lib/xmp2assert/prettier_inspect.rb +50 -0
- data/lib/xmp2assert/quasifile.rb +144 -0
- data/lib/xmp2assert/template.erb +37 -0
- data/lib/xmp2assert/version.rb +27 -0
- data/lib/xmp2assert/xmp2rexp.rb +56 -0
- data/lib/xmp2assert.rb +41 -0
- data/xmp2assert.gemspec +71 -0
- metadata +249 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil; ruby-indent-level 2 -*-
|
3
|
+
# -*- frozen_string_literal: true -*-
|
4
|
+
# -*- warn_indent: true -*-
|
5
|
+
|
6
|
+
# Copyright (c) 2017 Urabe, Shyouhei
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
# SOFTWARE.
|
25
|
+
|
26
|
+
# An XMP comment normally looks like this:
|
27
|
+
#
|
28
|
+
# ```ruby
|
29
|
+
# Object.new # => #<Object:0x007f896c9b49c8>
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
# Here, the hexadecimal number 0x007f896c9b49c8 is the raw pointer address of
|
33
|
+
# this evaluated object. When we check sanity of this XMP, that part would
|
34
|
+
# never match because pointer addresses are kind of arbitrary.
|
35
|
+
#
|
36
|
+
# To reroute the problem, here we convert a XMP comment into a regular
|
37
|
+
# expression. The idea behind this is the diff process hook implemented in
|
38
|
+
# https://github.com/ruby/chkbuild
|
39
|
+
module XMP2Assert::XMP2Rexp
|
40
|
+
module_function
|
41
|
+
|
42
|
+
# Generates a regular expression that roughly matches the input.
|
43
|
+
# @param xmp [String] example.
|
44
|
+
# @return [Regexp] converted regular expression.
|
45
|
+
def xmp2rexp xmp
|
46
|
+
# :NOTE: we are editing regular expressions using regular expressions. In
|
47
|
+
# order to hack this method you must be a seasoned regular expression
|
48
|
+
# craftsperson who can count backslashes at ease.
|
49
|
+
src = Regexp.escape xmp
|
50
|
+
src.gsub!(/([^\\])(\\n|\\ )+/, '\\1\s+')
|
51
|
+
src.gsub!(/(#<[\w:]+?:)0x[0-9a-f]+/, '\\10x[0-9a-f]+')
|
52
|
+
src.gsub!(/\\\.rb:\d+/, '\\.rb:\d+')
|
53
|
+
|
54
|
+
return Regexp.new "\\A#{src}\\z"
|
55
|
+
end
|
56
|
+
end
|
data/lib/xmp2assert.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#! /your/favourite/path/to/ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil; ruby-indent-level 2 -*-
|
3
|
+
# -*- frozen_string_literal: true -*-
|
4
|
+
# -*- warn_indent: true -*-
|
5
|
+
|
6
|
+
# Copyright (c) 2017 Urabe, Shyouhei
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
# SOFTWARE.
|
25
|
+
|
26
|
+
# This is a namespace. Look at each classes under this module:
|
27
|
+
#
|
28
|
+
# - XMP2Assert::Assertions the assertion framework.
|
29
|
+
# - XMP2Assert::Classifier check if the given file actually has the comment.
|
30
|
+
# - XMP2Assert::Converter source code in-place editor using Ripper.
|
31
|
+
# - XMP2Assert::Quasifile IO/String abstraction layer
|
32
|
+
# - XMP2Assert::PrttierInpect helper module to ease inspection.
|
33
|
+
module XMP2Assert
|
34
|
+
# These files assume the namespace, hence required here inside.
|
35
|
+
require_relative 'xmp2assert/version'
|
36
|
+
require_relative 'xmp2assert/prettier_inspect'
|
37
|
+
require_relative 'xmp2assert/quasifile'
|
38
|
+
require_relative 'xmp2assert/converter'
|
39
|
+
require_relative 'xmp2assert/classifier'
|
40
|
+
require_relative 'xmp2assert/assertions'
|
41
|
+
end
|
data/xmp2assert.gemspec
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#! /your/favourite/path/to/gem
|
2
|
+
# -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil; ruby-indent-level 2 -*-
|
3
|
+
# -*- frozen_string_literal: true -*-
|
4
|
+
# -*- warn_indent: true -*-
|
5
|
+
|
6
|
+
# Copyright (c) 2017 Urabe, Shyouhei
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files (the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# The above copyright notice and this permission notice shall be
|
16
|
+
# included in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
# SOFTWARE.
|
25
|
+
|
26
|
+
# :HACK: avoid namespace pollution
|
27
|
+
path = File.expand_path 'lib/xmp2assert/version.rb', __dir__
|
28
|
+
content = File.read path
|
29
|
+
version = Module.new.module_eval <<-'end'
|
30
|
+
XMP2Assert = Module.new
|
31
|
+
eval content, binding, path
|
32
|
+
end
|
33
|
+
|
34
|
+
Gem::Specification.new do |spec|
|
35
|
+
spec.name = 'xmp2assert'
|
36
|
+
spec.version = version
|
37
|
+
spec.author = 'Urabe, Shyouhei'
|
38
|
+
spec.email = 'shyouhei@ruby-lang.org'
|
39
|
+
spec.summary = 'auto-generate assertions from `# =>` comments'
|
40
|
+
spec.description = <<-'end'.gsub(/\s+/, ' ').strip
|
41
|
+
In ruby we use `# =>` as a comment marker that mean the immediately
|
42
|
+
adjacent expression's expected value. There are gems like xmpfilter /
|
43
|
+
seening_is_believing, which are to generate such comments. They are very
|
44
|
+
useful. But so far we lack feature that does vice-versa; to check if the
|
45
|
+
comment is actually the output of the expression.
|
46
|
+
|
47
|
+
This is the library that does it.
|
48
|
+
end
|
49
|
+
spec.homepage = 'https://github.com/shyouhei/xmp2assert'
|
50
|
+
spec.license = 'MIT'
|
51
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f|
|
52
|
+
f.match(%r'^(test|spec|features)/')
|
53
|
+
}
|
54
|
+
spec.bindir = 'exe'
|
55
|
+
spec.executables = spec.files.grep(%r'^exe/') { |f| File.basename(f) }
|
56
|
+
|
57
|
+
spec.add_development_dependency 'bundler'
|
58
|
+
spec.add_development_dependency 'github-markup'
|
59
|
+
spec.add_development_dependency 'pry'
|
60
|
+
spec.add_development_dependency 'rake'
|
61
|
+
spec.add_development_dependency 'rcodetools'
|
62
|
+
spec.add_development_dependency 'rdoc'
|
63
|
+
spec.add_development_dependency 'redcarpet'
|
64
|
+
spec.add_development_dependency 'rubocop'
|
65
|
+
spec.add_development_dependency 'seeing_is_believing'
|
66
|
+
spec.add_development_dependency 'simplecov'
|
67
|
+
spec.add_development_dependency 'yard'
|
68
|
+
spec.add_runtime_dependency 'ruby-uuid'
|
69
|
+
spec.add_runtime_dependency 'test-unit', '>= 3'
|
70
|
+
spec.required_ruby_version = '>= 2.2'
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmp2assert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Urabe, Shyouhei
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github-markup
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcodetools
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rdoc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: redcarpet
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: seeing_is_believing
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: ruby-uuid
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: test-unit
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '3'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '3'
|
195
|
+
description: In ruby we use `# =>` as a comment marker that mean the immediately adjacent
|
196
|
+
expression's expected value. There are gems like xmpfilter / seening_is_believing,
|
197
|
+
which are to generate such comments. They are very useful. But so far we lack feature
|
198
|
+
that does vice-versa; to check if the comment is actually the output of the expression.
|
199
|
+
This is the library that does it.
|
200
|
+
email: shyouhei@ruby-lang.org
|
201
|
+
executables:
|
202
|
+
- xmpcheck.rb
|
203
|
+
extensions: []
|
204
|
+
extra_rdoc_files: []
|
205
|
+
files:
|
206
|
+
- ".gitignore"
|
207
|
+
- ".rubocop.yml"
|
208
|
+
- ".yardopts"
|
209
|
+
- Gemfile
|
210
|
+
- LICENSE.txt
|
211
|
+
- README.md
|
212
|
+
- Rakefile
|
213
|
+
- Stylegiude.md
|
214
|
+
- exe/xmpcheck.rb
|
215
|
+
- lib/xmp2assert.rb
|
216
|
+
- lib/xmp2assert/assertions.rb
|
217
|
+
- lib/xmp2assert/classifier.rb
|
218
|
+
- lib/xmp2assert/converter.rb
|
219
|
+
- lib/xmp2assert/prettier_inspect.rb
|
220
|
+
- lib/xmp2assert/quasifile.rb
|
221
|
+
- lib/xmp2assert/template.erb
|
222
|
+
- lib/xmp2assert/version.rb
|
223
|
+
- lib/xmp2assert/xmp2rexp.rb
|
224
|
+
- xmp2assert.gemspec
|
225
|
+
homepage: https://github.com/shyouhei/xmp2assert
|
226
|
+
licenses:
|
227
|
+
- MIT
|
228
|
+
metadata: {}
|
229
|
+
post_install_message:
|
230
|
+
rdoc_options: []
|
231
|
+
require_paths:
|
232
|
+
- lib
|
233
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '2.2'
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - ">="
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: '0'
|
243
|
+
requirements: []
|
244
|
+
rubyforge_project:
|
245
|
+
rubygems_version: 2.6.11
|
246
|
+
signing_key:
|
247
|
+
specification_version: 4
|
248
|
+
summary: auto-generate assertions from `# =>` comments
|
249
|
+
test_files: []
|