From 67461fc922d8eaef411caf8d9b8eecdfc3c87938 Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 8 Jan 2026 13:06:17 +0900 Subject: [PATCH 1/3] Import signatures from gem_rbs_collection --- .github/workflows/sig.yml | 20 ++++++++++++ Gemfile | 5 +++ Rakefile | 20 ++++++++++++ abbrev.gemspec | 2 +- sig/abbrev.rbs | 66 +++++++++++++++++++++++++++++++++++++++ sig/array.rbs | 26 +++++++++++++++ test_sig/test_abbrev.rb | 35 +++++++++++++++++++++ 7 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/sig.yml create mode 100644 sig/abbrev.rbs create mode 100644 sig/array.rbs create mode 100644 test_sig/test_abbrev.rb diff --git a/.github/workflows/sig.yml b/.github/workflows/sig.yml new file mode 100644 index 0000000..8efa56a --- /dev/null +++ b/.github/workflows/sig.yml @@ -0,0 +1,20 @@ +name: sig + +on: [push, pull_request] + +jobs: + sig: + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v6 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ruby + - name: Install dependencies + run: | + bundle config set with 'sig' + bundle install + - name: Run RBS test, annotate and confirm + run: bundle exec rake rbs:{test,annotate,confirm} diff --git a/Gemfile b/Gemfile index eb86192..fb08ebd 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,8 @@ source "https://rubygems.org" gem "rake" gem "test-unit" + +group :sig do + gem "rbs" + gem "rdoc" +end diff --git a/Rakefile b/Rakefile index 30baabd..eec6054 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,24 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/test_*.rb"] end +namespace :rbs do + task :test do + sh "ruby -I lib test_sig/test_abbrev.rb" + end + + task :annotate do + require "tmpdir" + + Dir.mktmpdir do |tmpdir| + sh("rdoc --ri --output #{tmpdir}/doc --root=. lib") + sh("rbs annotate --no-system --no-gems --no-site --no-home -d #{tmpdir}/doc sig") + end + end + + task :confirm do + puts "Testing if RBS docs are updated with respect to RDoc" + sh "git diff --exit-code sig/" + end +end + task :default => :test diff --git a/abbrev.gemspec b/abbrev.gemspec index 57ae573..23cf1e6 100644 --- a/abbrev.gemspec +++ b/abbrev.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.metadata["changelog_uri"] = spec.homepage + "/releases" spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|test_sig|spec|features|\.github)/}) } end spec.bindir = "exe" spec.executables = [] diff --git a/sig/abbrev.rbs b/sig/abbrev.rbs new file mode 100644 index 0000000..6370794 --- /dev/null +++ b/sig/abbrev.rbs @@ -0,0 +1,66 @@ +# +# Calculates the set of unambiguous abbreviations for a given set of strings. +# +# require 'abbrev' +# require 'pp' +# +# pp Abbrev.abbrev(['ruby']) +# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"} +# +# pp Abbrev.abbrev(%w{ ruby rules }) +# +# *Generates:* +# { "ruby" => "ruby", +# "rub" => "ruby", +# "rules" => "rules", +# "rule" => "rules", +# "rul" => "rules" } +# +# It also provides an array core extension, Array#abbrev. +# +# pp %w{ summer winter }.abbrev +# +# *Generates:* +# { "summer" => "summer", +# "summe" => "summer", +# "summ" => "summer", +# "sum" => "summer", +# "su" => "summer", +# "s" => "summer", +# "winter" => "winter", +# "winte" => "winter", +# "wint" => "winter", +# "win" => "winter", +# "wi" => "winter", +# "w" => "winter" } +# +module Abbrev + # + # Given a set of strings, calculate the set of unambiguous abbreviations for + # those strings, and return a hash where the keys are all the possible + # abbreviations and the values are the full strings. + # + # Thus, given `words` is "car" and "cone", the keys pointing to "car" would be + # "ca" and "car", while those pointing to "cone" would be "co", "con", and + # "cone". + # + # require 'abbrev' + # + # Abbrev.abbrev(%w{ car cone }) + # #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"} + # + # The optional `pattern` parameter is a pattern or a string. Only input strings + # that match the pattern or start with the string are included in the output + # hash. + # + # Abbrev.abbrev(%w{car box cone crab}, /b/) + # #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"} + # + # Abbrev.abbrev(%w{car box cone}, 'ca') + # #=> {"car"=>"car", "ca"=>"car"} + # + def self?.abbrev: (Array[String], ?String | Regexp | nil) -> Hash[String, String] +end diff --git a/sig/array.rbs b/sig/array.rbs new file mode 100644 index 0000000..5ea1f93 --- /dev/null +++ b/sig/array.rbs @@ -0,0 +1,26 @@ +%a{annotate:rdoc:skip} +class Array[unchecked out Elem] + # + # Calculates the set of unambiguous abbreviations for the strings in `self`. + # + # require 'abbrev' + # %w{ car cone }.abbrev + # #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"} + # + # The optional `pattern` parameter is a pattern or a string. Only input strings + # that match the pattern or start with the string are included in the output + # hash. + # + # %w{ fast boat day }.abbrev(/^.a/) + # #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"} + # + # Abbrev.abbrev(%w{car box cone}, "ca") + # #=> {"car"=>"car", "ca"=>"car"} + # + # See also Abbrev.abbrev + # + def abbrev: (?String | Regexp | nil) -> Hash[String, String] +end diff --git a/test_sig/test_abbrev.rb b/test_sig/test_abbrev.rb new file mode 100644 index 0000000..cf6b442 --- /dev/null +++ b/test_sig/test_abbrev.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'abbrev' +require 'test/unit' +require 'rbs/unit_test' + +class AbbrevSingletonTest < Test::Unit::TestCase + include RBS::UnitTest::TypeAssertions + + library 'abbrev' + testing "singleton(::Abbrev)" + + def test_abbrev + assert_send_type '(Array[String]) -> Hash[String, String]', + Abbrev, :abbrev, %w[car cone] + assert_send_type '(Array[String], Regexp) -> Hash[String, String]', + Abbrev, :abbrev, %w{car box cone crab}, /b/ + assert_send_type '(Array[String], String) -> Hash[String, String]', + Abbrev, :abbrev, %w{car box cone}, 'ca' + end +end + +class AbbrevArrayInstanceTest < Test::Unit::TestCase + include RBS::UnitTest::TypeAssertions + + library 'abbrev' + testing "::Array[String]" + + def test_array + assert_send_type '() -> Hash[String, String]', + %w{ car cone }, :abbrev + assert_send_type '(Regexp) -> Hash[String, String]', + %w{ fast boat day }, :abbrev, /^.a/ + end +end From 1fb1e88f7a50eb6ae0aae8c198934d9658bf7828 Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 8 Jan 2026 14:06:44 +0900 Subject: [PATCH 2/3] Without sig --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74a4e7e..29f2682 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,8 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - name: Install dependencies - run: bundle install + run: | + bundle config set without 'sig' + bundle install - name: Run test run: rake test From 79c1196ce30d43897affd35c2c67edf379a4ab9e Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 3 Mar 2026 14:52:58 +0900 Subject: [PATCH 3/3] Stop using annotate on CI --- .github/workflows/sig.yml | 10 ++++------ .github/workflows/test.yml | 3 ++- Rakefile | 5 ----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/sig.yml b/.github/workflows/sig.yml index 8efa56a..bb6092e 100644 --- a/.github/workflows/sig.yml +++ b/.github/workflows/sig.yml @@ -5,6 +5,8 @@ on: [push, pull_request] jobs: sig: runs-on: "ubuntu-latest" + env: + BUNDLE_WITH: sig steps: - uses: actions/checkout@v6 - name: Set up Ruby @@ -12,9 +14,5 @@ jobs: with: bundler-cache: true ruby-version: ruby - - name: Install dependencies - run: | - bundle config set with 'sig' - bundle install - - name: Run RBS test, annotate and confirm - run: bundle exec rake rbs:{test,annotate,confirm} + - name: Run RBS tests + run: bundle exec rake rbs:test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 29f2682..05712a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,8 @@ jobs: - { os: windows-latest, ruby: truffleruby-head } - { os: windows-latest, ruby: truffleruby } runs-on: ${{ matrix.os }} + env: + BUNDLE_WITHOUT: sig steps: - uses: actions/checkout@v4 - name: Set up Ruby @@ -28,7 +30,6 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Install dependencies run: | - bundle config set without 'sig' bundle install - name: Run test run: rake test diff --git a/Rakefile b/Rakefile index eec6054..34a3747 100644 --- a/Rakefile +++ b/Rakefile @@ -20,11 +20,6 @@ namespace :rbs do sh("rbs annotate --no-system --no-gems --no-site --no-home -d #{tmpdir}/doc sig") end end - - task :confirm do - puts "Testing if RBS docs are updated with respect to RDoc" - sh "git diff --exit-code sig/" - end end task :default => :test