rbs 2.0.0.pre1 → 2.2.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.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +96 -4
  5. data/README.md +6 -1
  6. data/Rakefile +52 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_name.rb +1 -1
  94. data/lib/rbs/types.rb +1 -1
  95. data/lib/rbs/validator.rb +2 -0
  96. data/lib/rbs/version.rb +1 -1
  97. data/lib/rbs/writer.rb +54 -4
  98. data/lib/rbs.rb +0 -2
  99. data/schema/typeParam.json +3 -3
  100. data/sig/annotate/annotations.rbs +102 -0
  101. data/sig/annotate/formatter.rbs +24 -0
  102. data/sig/annotate/rdoc_annotater.rbs +82 -0
  103. data/sig/annotate/rdoc_source.rbs +30 -0
  104. data/sig/buffer.rbs +6 -2
  105. data/sig/cli.rbs +2 -0
  106. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  107. data/sig/location.rbs +6 -0
  108. data/sig/members.rbs +24 -18
  109. data/sig/method_builder.rbs +5 -4
  110. data/sig/method_types.rbs +5 -1
  111. data/sig/polyfill.rbs +78 -0
  112. data/sig/writer.rbs +79 -2
  113. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  114. data/stdlib/abbrev/0/array.rbs +26 -0
  115. data/stdlib/base64/0/base64.rbs +31 -0
  116. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  117. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  118. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  119. data/stdlib/cgi/0/core.rbs +59 -0
  120. data/stdlib/coverage/0/coverage.rbs +164 -2
  121. data/stdlib/csv/0/csv.rbs +2862 -398
  122. data/stdlib/date/0/date.rbs +483 -25
  123. data/stdlib/date/0/date_time.rbs +187 -12
  124. data/stdlib/dbm/0/dbm.rbs +152 -17
  125. data/stdlib/digest/0/digest.rbs +146 -0
  126. data/stdlib/erb/0/erb.rbs +65 -245
  127. data/stdlib/fiber/0/fiber.rbs +73 -91
  128. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  129. data/stdlib/find/0/find.rbs +9 -0
  130. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  131. data/stdlib/io-console/0/io-console.rbs +227 -15
  132. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  133. data/stdlib/json/0/json.rbs +1146 -144
  134. data/stdlib/logger/0/formatter.rbs +24 -0
  135. data/stdlib/logger/0/log_device.rbs +64 -0
  136. data/stdlib/logger/0/logger.rbs +165 -13
  137. data/stdlib/logger/0/period.rbs +10 -0
  138. data/stdlib/logger/0/severity.rbs +26 -0
  139. data/stdlib/monitor/0/monitor.rbs +163 -0
  140. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  141. data/stdlib/net-http/0/manifest.yaml +1 -0
  142. data/stdlib/net-http/0/net-http.rbs +1513 -683
  143. data/stdlib/nkf/0/nkf.rbs +372 -0
  144. data/stdlib/objspace/0/objspace.rbs +149 -90
  145. data/stdlib/openssl/0/openssl.rbs +8108 -71
  146. data/stdlib/optparse/0/optparse.rbs +487 -19
  147. data/stdlib/pathname/0/pathname.rbs +425 -124
  148. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  149. data/stdlib/prime/0/integer-extension.rbs +20 -2
  150. data/stdlib/prime/0/prime.rbs +88 -21
  151. data/stdlib/pstore/0/pstore.rbs +102 -0
  152. data/stdlib/pty/0/pty.rbs +64 -14
  153. data/stdlib/resolv/0/resolv.rbs +420 -31
  154. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  155. data/stdlib/rubygems/0/config_file.rbs +33 -1
  156. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  157. data/stdlib/rubygems/0/installer.rbs +13 -1
  158. data/stdlib/rubygems/0/path_support.rbs +4 -1
  159. data/stdlib/rubygems/0/platform.rbs +5 -1
  160. data/stdlib/rubygems/0/request_set.rbs +44 -2
  161. data/stdlib/rubygems/0/requirement.rbs +65 -2
  162. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  163. data/stdlib/rubygems/0/source_list.rbs +13 -0
  164. data/stdlib/rubygems/0/specification.rbs +21 -1
  165. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  166. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  167. data/stdlib/rubygems/0/version.rbs +60 -157
  168. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  169. data/stdlib/set/0/set.rbs +420 -106
  170. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  171. data/stdlib/singleton/0/singleton.rbs +20 -0
  172. data/stdlib/socket/0/addrinfo.rbs +210 -9
  173. data/stdlib/socket/0/basic_socket.rbs +103 -11
  174. data/stdlib/socket/0/ip_socket.rbs +31 -9
  175. data/stdlib/socket/0/socket.rbs +586 -38
  176. data/stdlib/socket/0/tcp_server.rbs +22 -2
  177. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  178. data/stdlib/socket/0/udp_socket.rbs +25 -2
  179. data/stdlib/socket/0/unix_server.rbs +22 -2
  180. data/stdlib/socket/0/unix_socket.rbs +45 -5
  181. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  182. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  183. data/stdlib/time/0/time.rbs +208 -116
  184. data/stdlib/timeout/0/timeout.rbs +10 -0
  185. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  186. data/stdlib/tsort/0/cyclic.rbs +1 -0
  187. data/stdlib/tsort/0/interfaces.rbs +1 -0
  188. data/stdlib/tsort/0/tsort.rbs +42 -0
  189. data/stdlib/uri/0/common.rbs +57 -8
  190. data/stdlib/uri/0/file.rbs +55 -109
  191. data/stdlib/uri/0/ftp.rbs +6 -3
  192. data/stdlib/uri/0/generic.rbs +591 -362
  193. data/stdlib/uri/0/http.rbs +60 -114
  194. data/stdlib/uri/0/https.rbs +8 -102
  195. data/stdlib/uri/0/ldap.rbs +143 -137
  196. data/stdlib/uri/0/ldaps.rbs +8 -102
  197. data/stdlib/uri/0/mailto.rbs +3 -0
  198. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  199. data/stdlib/uri/0/ws.rbs +6 -3
  200. data/stdlib/uri/0/wss.rbs +5 -3
  201. data/stdlib/yaml/0/dbm.rbs +151 -87
  202. data/stdlib/yaml/0/store.rbs +6 -0
  203. data/stdlib/zlib/0/zlib.rbs +90 -31
  204. metadata +20 -8
  205. data/lib/rbs/location.rb +0 -221
  206. data/sig/char_scanner.rbs +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df2f2f119ca85f630c640b201ebf9ce72322db96223de2fb1d4ba77df68aee59
4
- data.tar.gz: 82943e12963a10f2a4dbd30096fe40fb90ee4b23d6239bd515526a39d2af3b97
3
+ metadata.gz: f4afaa0d6ac4b7b74aae38aa7cd04679dad881ad073ca496aa06f272a7261cfe
4
+ data.tar.gz: 041f1bf758d156f9a968ae3cb460da45a99f80aacb2868513549687ee4e4ad76
5
5
  SHA512:
6
- metadata.gz: 9dbd99091da5e5d116a5bb428383c3e63e8b8ee4207ea859e177577b33a1d1dc3d312bb31f03fcda61d90993b4a9ab1ccab69855e7ecb8e986f9696a638c618d
7
- data.tar.gz: dc05caaa25da531bbe353eb0294fbe016a90039eef12a040f2c5b07f409683c9fbc6c3406beba8c8d76f25f5b0ed7bbc3501967cc84fcc000a2e49fda85e84a3
6
+ metadata.gz: 8891199897e1ef1574b8009bc810c0d60a1a8fbe4a9f2d5d6658b703c75d515d6e89022e5246a6196657775d8f0ea2bd44db13718a425face5d16d3e5cff38dd
7
+ data.tar.gz: faa9199018c944a87de33fc99a4bf203e73f2f24d27960d79cd92fb82aaa6be2218cae07a2bb6887ad1dee2df96e8abc7b43ec818bf11d5a40dfabf3e782f1c2
@@ -0,0 +1,34 @@
1
+ name: RBS Comments
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request: {}
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: "ubuntu-latest"
12
+ container:
13
+ image: rubylang/ruby:3.1-focal
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Install dependencies
17
+ run: |
18
+ apt-get update
19
+ apt-get install -y libdb-dev
20
+ - name: Update rubygems & bundler
21
+ run: |
22
+ ruby -v
23
+ gem update --system
24
+ - name: bundle config set with
25
+ run: |
26
+ echo "NO_MINITEST=true" >> $GITHUB_ENV
27
+ bundle config set --local without 'minitest'
28
+ if: "contains(matrix.container_tag, 'master-nightly')"
29
+ - name: bin/setup
30
+ run: |
31
+ bin/setup
32
+ - name: Run test
33
+ run: |
34
+ bundle exec rake annotate confirm_annotation
@@ -13,6 +13,7 @@ jobs:
13
13
  matrix:
14
14
  container_tag:
15
15
  - master-nightly-focal
16
+ - 3.1-focal
16
17
  - 3.0-focal
17
18
  - 2.7-bionic
18
19
  - 2.6-bionic
@@ -27,6 +28,10 @@ jobs:
27
28
  job: confirm_lexer
28
29
  - container_tag: 2.6-bionic
29
30
  job: stdlib_test
31
+ - container_tag: 2.7-bionic
32
+ job: stdlib_test
33
+ - container_tag: 3.0-focal
34
+ job: stdlib_test
30
35
  container:
31
36
  image: rubylang/ruby:${{ matrix.container_tag }}
32
37
  steps:
data/CHANGELOG.md CHANGED
@@ -2,11 +2,79 @@
2
2
 
3
3
  ## master
4
4
 
5
- ## 2.0.0 (pre1)
5
+ ## 2.2.0 (2022-02-22)
6
+
7
+ RBS 2.2 ships with a new syntax to specify the visibility of a method per definition bases.
8
+
9
+ ```rbs
10
+ class Foo
11
+ private def hello: () -> void
12
+
13
+ private attr_accessor world: String
14
+ end
15
+ ```
16
+
17
+ It also changes the semantics of `self?` method.
18
+ It defines both _public_ singleton method and _private_ instance method, which is equivalent to `module_function`.
19
+
20
+ ## Signature updates
21
+
22
+ * `net-http` ([\#892](https://github.com/ruby/rbs/pull/892))
23
+ * `uri` ([\#864](https://github.com/ruby/rbs/pull/864))
24
+ * `Encoding` ([\#897](https://github.com/ruby/rbs/pull/897), [\#898](https://github.com/ruby/rbs/pull/898))
25
+ * `File::Stat` ([\#879](https://github.com/ruby/rbs/pull/879))
26
+ * `Kernel#sleep` ([\#893](https://github.com/ruby/rbs/pull/893))
27
+
28
+ ### Language updates
29
+
30
+ * Add public/private per member modifier ([\#911](https://github.com/ruby/rbs/pull/911))
31
+ * Let `self?.` be equivalent to `module_function` ([\#910](https://github.com/ruby/rbs/pull/910))
32
+
33
+ ### Library changes
34
+
35
+ * Add c99 flag for compiling on Ruby 2 ([\#895](https://github.com/ruby/rbs/pull/895))
36
+ * Fix incorrect URI reference in `schema/typeParam.json` ([\#891](https://github.com/ruby/rbs/pull/891))
37
+ * Allow scaffolding below namespace ([\#894](https://github.com/ruby/rbs/pull/894))
38
+ * Let `Writer` preserve format ([\#900](https://github.com/ruby/rbs/pull/900))
39
+ * Reduce memory usage of `RBS::Buffer` ([\#907](https://github.com/ruby/rbs/pull/907))
40
+ * Do not call `#class` from `#hash` to improve performance ([\#906](https://github.com/ruby/rbs/pull/906))
41
+ * Skip type variable validation if `unchcked` ([\#909](https://github.com/ruby/rbs/pull/909))
42
+
43
+ ### Miscellaneous
44
+
45
+ * Add `Thread::Backtrace` and `Thread::Backtrace::Location` test ([\#896](https://github.com/ruby/rbs/pull/896))
46
+ * Test annotations ([\#902](https://github.com/ruby/rbs/pull/902))
47
+ * Remove goodcheck rule for arglists section ([\#901](https://github.com/ruby/rbs/pull/901))
48
+ * Remove `CharScanner` due to no longer used ([\#905](https://github.com/ruby/rbs/pull/905))
49
+
50
+ ## 2.1.0 (2022-02-02)
51
+
52
+ RBS 2.1 is a release to deliver the types and documents of the new and updated methods of Ruby 3.1.
53
+
54
+ ### Signature updates
55
+
56
+ * Documents imported from Ruby 3.1 ([\#881](https://github.com/ruby/rbs/pull/881))
57
+ * Methods/classes updated in Ruby 3.1 ([\#886](https://github.com/ruby/rbs/pull/886))
58
+ * io/wait ([\#865](https://github.com/ruby/rbs/pull/865))
59
+ * json ([\#863](https://github.com/ruby/rbs/pull/863))
60
+ * nkf ([\#873](https://github.com/ruby/rbs/pull/873))
61
+ * openssl ([\#866](https://github.com/ruby/rbs/pull/866))
62
+ * `Dir.exists?`, `FileTest#exists?` ([\#884](https://github.com/ruby/rbs/pull/884))
63
+ * `FileTest` ([\#880](https://github.com/ruby/rbs/pull/880))
64
+ * `Gem::Version#<=>` ([\#869](https://github.com/ruby/rbs/pull/869))
65
+ * `Process.clock_gettime` ([\#858](https://github.com/ruby/rbs/pull/858))
66
+
67
+ ### Library changes
68
+
69
+ * Introduce `rbs annotate` command ([\#881](https://github.com/ruby/rbs/pull/881))
70
+ * Make prototype rb to be aware of prepend ([\#861](https://github.com/ruby/rbs/pull/861))
71
+ * Fixes incorrect "Invalid Variance" error when method type variable shadows outer type variable ([#889](https://github.com/ruby/rbs/pull/889))
72
+
73
+ ## 2.0.0 (2021-12-24)
6
74
 
7
75
  ### Bounded Generics
8
76
 
9
- RBS 2.0 ships with _bounded generics_, which improves the expressiveness of the language by adding new syntax to define the constraint on type parameters.
77
+ RBS 2.0 ships with _bounded generics_, which improves the expressiveness of the language by adding a new syntax to define constraints on type parameters.
10
78
 
11
79
  ```rbs
12
80
  class PrettyPrint[T < _Output]
@@ -28,7 +96,31 @@ It means _`T` has to be compatible with `_Output` interface._
28
96
 
29
97
  See [the PR for details](https://github.com/ruby/rbs/pull/844).
30
98
 
31
- `manifest.yaml` allows declaring the dependencies from your gems to standard libraries explicitly.
99
+ ### RBS Collection manager
100
+
101
+ RBS Collection feature is generally available on RBS 2.0. In short, it is Bundler for RBS. You can manage RBSs of standard libraries and third party gems with `rbs collection` subcommand.
102
+
103
+ ```bash
104
+ $ rbs collection init
105
+ created: rbs_collection.yaml
106
+
107
+ # The `install` command set up RBS files and creates `rbs_collection.lock.yaml` file
108
+ $ rbs collection install
109
+ Installing actionpack:6.0 (actionpack@ce6664cec73)
110
+ (...snip...)
111
+ Using tsort:0 (/path/to/rbs-2.0.0/stdlib/tsort/0)
112
+ It's done! 21 gems' RBSs now installed.
113
+
114
+ # Now you can use `rbs`, `typeprof` and `steep` commands with the dependencies out of the box!
115
+ $ rbs validate
116
+ $ typeprof app.rb
117
+ $ steep check
118
+ ```
119
+
120
+ RBS 2.0 also introduces `manifest.yaml` to declare the dependencies from your gems to standard libraries explicitly.
121
+ See [the documentation](https://github.com/ruby/rbs/blob/master/docs/collection.md) for more information.
122
+
123
+ ### Breaking changes
32
124
 
33
125
  This version contains a bug fix, which potentially breaks the compatibility with older versions.
34
126
  The super class names in class definitions are now resolved in _outer_ context.
@@ -36,7 +128,7 @@ It was an incompatibility with Ruby and [this PR](https://github.com/ruby/rbs/pu
36
128
 
37
129
  ### Signature updates
38
130
 
39
- * uri ([\#846](https://github.com/ruby/rbs/pull/846), [\#852](https://github.com/ruby/rbs/pull/852), [\#851](https://github.com/ruby/rbs/pull/851), [\#850](https://github.com/ruby/rbs/pull/850))
131
+ * uri ([\#846](https://github.com/ruby/rbs/pull/846), [\#852](https://github.com/ruby/rbs/pull/852), [\#851](https://github.com/ruby/rbs/pull/851), [\#850](https://github.com/ruby/rbs/pull/850), [#849](https://github.com/ruby/rbs/pull/849))
40
132
 
41
133
  ### Language updates
42
134
 
data/README.md CHANGED
@@ -52,6 +52,11 @@ end
52
52
  ```
53
53
  <!-- run-end -->
54
54
 
55
+ ## The Target Version
56
+
57
+ * The standard library signatures targets Ruby 3.1. (The latest release of Ruby.)
58
+ * The library code targets Ruby 3.1, 3.0, and 2.7. (It runs on 2.6 in fact.)
59
+
55
60
  ## Installation
56
61
 
57
62
  Install the `rbs` gem. `$ gem install rbs` from the command line, or add a line in your `Gemfile`.
@@ -122,7 +127,7 @@ puts singleton.methods[:gsub]
122
127
 
123
128
  ## Guides
124
129
 
125
- - [Standard library signature contribution guide](docs/CONTRIBUTING.md)
130
+ - [Core and standard library signature contribution guide](docs/CONTRIBUTING.md)
126
131
  - [Writing signatures guide](docs/sigs.md)
127
132
  - [Stdlib signatures guide](docs/stdlib.md)
128
133
  - [Syntax](docs/syntax.md)
data/Rakefile CHANGED
@@ -34,6 +34,15 @@ rule ".c" => ".re" do |t|
34
34
  puts "⚠️⚠️⚠️ #{t.name} is older than #{t.source}. You may need to run `rake lexer` ⚠️⚠️⚠️"
35
35
  end
36
36
 
37
+ task :annotate do
38
+ sh "rbs annotate core stdlib"
39
+ end
40
+
41
+ task :confirm_annotation do
42
+ puts "Testing if RBS docs are updated with respect to RDoc"
43
+ sh "git diff --exit-code core stdlib"
44
+ end
45
+
37
46
  task :compile => "ext/rbs_extension/lexer.c"
38
47
 
39
48
  task :test_doc do
@@ -73,6 +82,7 @@ task :validate => :compile do
73
82
 
74
83
  if lib == ["net-http"]
75
84
  lib << "uri"
85
+ lib << "timeout"
76
86
  end
77
87
 
78
88
  if lib == ["resolv"]
@@ -106,17 +116,40 @@ namespace :generate do
106
116
  raise "Class name is necessary. e.g. rake 'generate:stdlib_test[String]'"
107
117
  end
108
118
 
109
- path = Pathname(ENV["RBS_GENERATE_TEST_PATH"] || "test/stdlib/#{klass}_test.rb")
110
- raise "#{path} already exists!" if path.exist?
111
-
112
119
  require "erb"
113
120
  require "rbs"
114
121
 
122
+ class TestTarget
123
+ def initialize(klass)
124
+ @type_name = RBS::Namespace.parse(klass).to_type_name
125
+ end
126
+
127
+ def path
128
+ Pathname(ENV['RBS_GENERATE_TEST_PATH'] || "test/stdlib/#{file_name}_test.rb")
129
+ end
130
+
131
+ def file_name
132
+ @type_name.to_s.gsub(/\A::/, '').gsub(/::/, '_')
133
+ end
134
+
135
+ def to_s
136
+ @type_name.to_s
137
+ end
138
+
139
+ def absolute_type_name
140
+ @absolute_type_name ||= @type_name.absolute!
141
+ end
142
+ end
143
+
144
+ target = TestTarget.new(klass)
145
+ path = target.path
146
+ raise "#{path} already exists!" if path.exist?
147
+
115
148
  class TestTemplateBuilder
116
- attr_reader :klass, :env
149
+ attr_reader :target, :env
117
150
 
118
- def initialize(klass)
119
- @klass = klass
151
+ def initialize(target)
152
+ @target = target
120
153
 
121
154
  loader = RBS::EnvironmentLoader.new
122
155
  Dir['stdlib/*'].each do |lib|
@@ -132,17 +165,17 @@ namespace :generate do
132
165
  require_relative "test_helper"
133
166
 
134
167
  <%- unless class_methods.empty? -%>
135
- class <%= klass %>SingletonTest < Test::Unit::TestCase
168
+ class <%= target %>SingletonTest < Test::Unit::TestCase
136
169
  include TypeAssertions
137
170
 
138
171
  # library "pathname", "set", "securerandom" # Declare library signatures to load
139
- testing "singleton(::<%= klass %>)"
172
+ testing "singleton(::<%= target %>)"
140
173
 
141
174
  <%- class_methods.each do |method_name, definition| %>
142
175
  def test_<%= test_name_for(method_name) %>
143
176
  <%- definition.method_types.each do |method_type| -%>
144
177
  assert_send_type "<%= method_type %>",
145
- <%= klass %>, :<%= method_name %>
178
+ <%= target %>, :<%= method_name %>
146
179
  <%- end -%>
147
180
  end
148
181
  <%- end -%>
@@ -150,17 +183,17 @@ namespace :generate do
150
183
  <%- end -%>
151
184
 
152
185
  <%- unless instance_methods.empty? -%>
153
- class <%= klass %>Test < Test::Unit::TestCase
186
+ class <%= target %>Test < Test::Unit::TestCase
154
187
  include TypeAssertions
155
188
 
156
189
  # library "pathname", "set", "securerandom" # Declare library signatures to load
157
- testing "::<%= klass %>"
190
+ testing "::<%= target %>"
158
191
 
159
192
  <%- instance_methods.each do |method_name, definition| %>
160
193
  def test_<%= test_name_for(method_name) %>
161
194
  <%- definition.method_types.each do |method_type| -%>
162
195
  assert_send_type "<%= method_type %>",
163
- <%= klass %>.new, :<%= method_name %>
196
+ <%= target %>.new, :<%= method_name %>
164
197
  <%- end -%>
165
198
  end
166
199
  <%- end -%>
@@ -200,24 +233,20 @@ namespace :generate do
200
233
  }.fetch(method_name, method_name)
201
234
  end
202
235
 
203
- def type_name
204
- @type_name ||= RBS::TypeName.new(name: klass.to_sym, namespace: RBS::Namespace.new(path: [], absolute: true))
205
- end
206
-
207
236
  def class_methods
208
- @class_methods ||= RBS::DefinitionBuilder.new(env: env).build_singleton(type_name).methods.select {|_, definition|
209
- definition.implemented_in == type_name
237
+ @class_methods ||= RBS::DefinitionBuilder.new(env: env).build_singleton(target.absolute_type_name).methods.select {|_, definition|
238
+ definition.implemented_in == target.absolute_type_name
210
239
  }
211
240
  end
212
241
 
213
242
  def instance_methods
214
- @instance_methods ||= RBS::DefinitionBuilder.new(env: env).build_instance(type_name).methods.select {|_, definition|
215
- definition.implemented_in == type_name
243
+ @instance_methods ||= RBS::DefinitionBuilder.new(env: env).build_instance(target.absolute_type_name).methods.select {|_, definition|
244
+ definition.implemented_in == target.absolute_type_name
216
245
  }
217
246
  end
218
247
  end
219
248
 
220
- path.write TestTemplateBuilder.new(klass).call
249
+ path.write TestTemplateBuilder.new(target).call
221
250
 
222
251
  puts "Created: #{path}"
223
252
  end
@@ -226,4 +255,6 @@ end
226
255
  task :test_generate_stdlib do
227
256
  sh "RBS_GENERATE_TEST_PATH=/tmp/Array_test.rb rake 'generate:stdlib_test[Array]'"
228
257
  sh "ruby -c /tmp/Array_test.rb"
258
+ sh "RBS_GENERATE_TEST_PATH=/tmp/Thread_Mutex_test.rb rake 'generate:stdlib_test[Thread::Mutex]'"
259
+ sh "ruby -c /tmp/Thread_Mutex_test.rb"
229
260
  end