From f0b3edea181f65b5c1c669e83c88960e973cb0d0 Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Tue, 14 Feb 2023 15:58:37 +0900 Subject: [PATCH] Add `Environment#unload`, remove `#reject` --- lib/rbs/environment.rb | 11 ++++++----- sig/environment.rbs | 5 ++--- test/rbs/environment_test.rb | 34 ---------------------------------- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/lib/rbs/environment.rb b/lib/rbs/environment.rb index bb0ae64d2..dc1145b4a 100644 --- a/lib/rbs/environment.rb +++ b/lib/rbs/environment.rb @@ -773,13 +773,14 @@ def buffers_decls hash end - def reject + def unload(buffers) env = Environment.new - declarations.each do |decl| - unless yield(decl) - env << decl - end + buffers_decls.each do |buf, decls| + next if buffers.include?(buf) + + dirs = buffer_directives.fetch(buf) + env.add_signature(buffer: buf, directives: dirs, decls: decls) end env diff --git a/sig/environment.rbs b/sig/environment.rbs index 18e821d5d..40f274bbc 100644 --- a/sig/environment.rbs +++ b/sig/environment.rbs @@ -147,10 +147,9 @@ module RBS def buffers_decls: () -> Hash[Buffer, Array[AST::Declarations::t]] - # Construct new environment without declarations tested `true` by block. - # Construction of new environment is done with `<<` so that nested declarations will work well. + # Remove declarations and directives that are loaded from `buffers` # - def reject: () { (AST::Declarations::t) -> boolish } -> Environment + def unload: (Set[Buffer] buffers) -> Environment # Returns true if an interface with the type name is defined # diff --git a/test/rbs/environment_test.rb b/test/rbs/environment_test.rb index b0edf3fbe..47caa3efd 100644 --- a/test/rbs/environment_test.rb +++ b/test/rbs/environment_test.rb @@ -437,40 +437,6 @@ class C end end - def test_reject - env = Environment.new - - foo = RBS::Buffer.new(content: < Integer -end -EOF - - RBS::Parser.parse_signature(foo)[2].each do |decl| - env << decl - end - - bar = RBS::Buffer.new(content: < void -end -EOF - - RBS::Parser.parse_signature(bar)[2].each do |decl| - env << decl - end - - assert env.buffers.any? {|buf| buf.name == Pathname("foo.rbs") } - assert env.buffers.any? {|buf| buf.name == Pathname("bar.rbs") } - - env_ = env.reject do |decl| - decl.location.buffer.name == Pathname("foo.rbs") - end - - assert env_.buffers.none? {|buf| buf.name == Pathname("foo.rbs") } - assert env_.buffers.any? {|buf| buf.name == Pathname("bar.rbs") } - end - def test_absolute_type_generics_upper_bound env = Environment.new