doctest2-core 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: beac60bca843e7adbfb3e7e584ebdc0a4b02c4ea7ea25a008260a3ef2ca827fb
4
+ data.tar.gz: 948397d1ac2588d2fb9b9ad9e8dfccadec21ed41f05c92850e057e3311777289
5
+ SHA512:
6
+ metadata.gz: aac4fb9d9e308781f2935ca4d5ffadddd7267f29a42f1331ac66226f22910668f44d1f9c4980a77297d7838adcfaee81533d9d94e520fa0fd57c85c304485c88
7
+ data.tar.gz: 0a32135d3f23c48f74f322724b3e6dc80bbb370cf87dd698b7843bdc00a439b709b08c4b0fdf45bed576ce726a696f44d86a3b37bb5088094064ea899495cf9d
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in doctest2-core.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ doctest2-core (0.9.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ ffi (1.15.5)
13
+ formatador (1.1.0)
14
+ guard (2.18.0)
15
+ formatador (>= 0.2.4)
16
+ listen (>= 2.7, < 4.0)
17
+ lumberjack (>= 1.0.12, < 2.0)
18
+ nenv (~> 0.1)
19
+ notiffany (~> 0.0)
20
+ pry (>= 0.13.0)
21
+ shellany (~> 0.0)
22
+ thor (>= 0.18.1)
23
+ guard-compat (1.2.1)
24
+ guard-rspec (4.7.3)
25
+ guard (~> 2.1)
26
+ guard-compat (~> 1.1)
27
+ rspec (>= 2.99.0, < 4.0)
28
+ json (2.6.3)
29
+ listen (3.8.0)
30
+ rb-fsevent (~> 0.10, >= 0.10.3)
31
+ rb-inotify (~> 0.9, >= 0.9.10)
32
+ lumberjack (1.2.8)
33
+ method_source (1.0.0)
34
+ nenv (0.3.0)
35
+ notiffany (0.1.3)
36
+ nenv (~> 0.1)
37
+ shellany (~> 0.0)
38
+ parallel (1.23.0)
39
+ parser (3.2.2.1)
40
+ ast (~> 2.4.1)
41
+ pry (0.14.2)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ rainbow (3.1.1)
45
+ rake (13.0.6)
46
+ rb-fsevent (0.11.2)
47
+ rb-inotify (0.10.1)
48
+ ffi (~> 1.0)
49
+ regexp_parser (2.8.0)
50
+ rexml (3.2.5)
51
+ rspec (3.12.0)
52
+ rspec-core (~> 3.12.0)
53
+ rspec-expectations (~> 3.12.0)
54
+ rspec-mocks (~> 3.12.0)
55
+ rspec-core (3.12.2)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-expectations (3.12.3)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-mocks (3.12.5)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-support (3.12.0)
64
+ rubocop (1.50.2)
65
+ json (~> 2.3)
66
+ parallel (~> 1.10)
67
+ parser (>= 3.2.0.0)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ regexp_parser (>= 1.8, < 3.0)
70
+ rexml (>= 3.2.5, < 4.0)
71
+ rubocop-ast (>= 1.28.0, < 2.0)
72
+ ruby-progressbar (~> 1.7)
73
+ unicode-display_width (>= 2.4.0, < 3.0)
74
+ rubocop-ast (1.28.1)
75
+ parser (>= 3.2.1.0)
76
+ ruby-progressbar (1.13.0)
77
+ shellany (0.0.1)
78
+ thor (1.2.2)
79
+ unicode-display_width (2.4.2)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ doctest2-core!
86
+ guard-rspec
87
+ pry
88
+ rake (~> 13.0)
89
+ rspec
90
+ rubocop (~> 1.21)
91
+
92
+ BUNDLED WITH
93
+ 2.1.4
data/Justfile ADDED
@@ -0,0 +1,16 @@
1
+ setup_and_test: setup test
2
+
3
+ setup:
4
+ bin/setup
5
+
6
+ test:
7
+ bundle exec rspec
8
+
9
+ console:
10
+ bin/console
11
+
12
+ install:
13
+ bundle exec rake install
14
+
15
+ release:
16
+ bundle exec rake release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 qqwy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Doctest2::Core
2
+
3
+ Read the main README at [../README.md](../README.md)
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,81 @@
1
+ module Doctest2
2
+ module Core
3
+ class Base
4
+
5
+ def self.analyze(str)
6
+ self.new(str).analyze
7
+ end
8
+
9
+ CODE_AND_RESULT_REGEXP = /^\s*#\s*>>\s*(?<code>.*)?#\s*=>\s*(?<result>.*)$/
10
+ CODE_REGEXP = /^\s*#\s*>>\s*(?<code>.*)/
11
+ RESULT_REGEXP = /#\s*=>\s*(?<result>.*)$/
12
+
13
+ def initialize(source)
14
+ if File.exist?(source)
15
+ @filename = source
16
+ @str = File.read(source)
17
+ else
18
+ @filename = nil
19
+ @str = source
20
+ end
21
+ @state = :no_match
22
+ @current = nil
23
+ @doctests = []
24
+ end
25
+
26
+ def analyze
27
+ @str.lines.each.with_index do |line, index|
28
+ case line
29
+ when CODE_AND_RESULT_REGEXP
30
+ code = Regexp.last_match['code']
31
+ result = Regexp.last_match['result']
32
+ handle_code(code)
33
+ handle_result(result, index)
34
+ when CODE_REGEXP
35
+ handle_code(Regexp.last_match['code'])
36
+ when RESULT_REGEXP
37
+ handle_result(Regexp.last_match['result'], index)
38
+ else
39
+ handle_no_doctest
40
+ end
41
+ end
42
+
43
+ @doctests
44
+ end
45
+
46
+ private
47
+
48
+ def add_doctest(code_lines, result, line_index)
49
+ @doctests << Doctest.new(code_lines.join(';'), result, @filename, line_index + 1)
50
+ end
51
+
52
+ def handle_code(code)
53
+ case @state
54
+ when :no_match
55
+ @current_code = [code]
56
+ @state = :match
57
+ when :match
58
+ @current_code << code
59
+ end
60
+ end
61
+
62
+ def handle_result(result, line_index)
63
+ case @state
64
+ when :match
65
+ add_doctest(@current_code, result, line_index)
66
+ reset
67
+ end
68
+ end
69
+
70
+ def handle_no_doctest
71
+ reset
72
+ end
73
+
74
+ def reset
75
+ @state = :no_match
76
+ @current
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,15 @@
1
+ module Doctest2
2
+ module Core
3
+ class Doctest < Struct.new(:code_string, :result_string, :original_file, :line)
4
+
5
+ def result_evaluation
6
+ eval(result_string)
7
+ end
8
+
9
+ def code_evaluation
10
+ eval(code_string)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ module Doctest2
2
+ module Core
3
+ module Source
4
+
5
+ def self.to_filenames(source)
6
+ case source
7
+ when Class, Module
8
+ constant_filenames(source)
9
+ else
10
+ [ source ]
11
+ end
12
+ end
13
+
14
+ def self.constant_filenames(constant)
15
+ (filenames_of_instance_methods(constant) + filenames_of_methods(constant)).uniq.sort
16
+ end
17
+
18
+ def self.filenames_of_instance_methods(constant)
19
+ constant.
20
+ instance_methods(false).
21
+ map{|m| constant.instance_method(m).source_location}.
22
+ map(&:first)
23
+ end
24
+
25
+ def self.filenames_of_methods(constant)
26
+ constant.
27
+ methods(false).
28
+ map{|m| constant.method(m).source_location}.
29
+ map(&:first)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doctest2
4
+ module Core
5
+ VERSION = "0.9.0"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "core/version"
4
+ require_relative "core/base"
5
+ require_relative "core/doctest"
6
+ require_relative "core/source"
7
+
8
+ module Doctest2
9
+ module Core
10
+ def self.extract_from(source)
11
+ Source.to_filenames(source).
12
+ flat_map{|code_location| Base.analyze(code_location)}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Doctest2
2
+ module Core
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doctest2-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Qqwy/Marten
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
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: guard-rspec
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
+ description: Extract doctests from Ruby files.
56
+ email:
57
+ - qqwy@gmx.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rubocop.yml"
63
+ - ".tool-versions"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - Justfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/doctest2/core.rb
71
+ - lib/doctest2/core/base.rb
72
+ - lib/doctest2/core/doctest.rb
73
+ - lib/doctest2/core/source.rb
74
+ - lib/doctest2/core/version.rb
75
+ - sig/doctest2/core.rbs
76
+ homepage: https://github.com/Qqwy/ruby-doctest2
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/Qqwy/ruby-doctest2
81
+ source_code_uri: https://github.com/Qqwy/ruby-doctest2
82
+ changelog_uri: https://github.com/Qqwy/ruby-doctest2/blob/main/CHANGELOG.md
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.6.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.4.10
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Forms the basis of extracting and running doctests (documentation tests).
102
+ Core used by test-framework-specific gems.
103
+ test_files: []