<commit_before>require 'gir_ffi_test_helper'

describe GirFFI::Builders::SignalBuilder do
  let(:builder) { GirFFI::Builders::SignalBuilder.new signal_info }

  describe "#mapping_method_definition" do
    describe "for a signal with no arguments or return value" do
      let(:signal_info) {
        get_signal_introspection_data "Regress", "TestObj", "test" }

      it "returns a valid mapping method including receiver and user data" do
        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2)
          _v3 = ::Regress::TestObj.wrap(_v1)
          _v4 = GirFFI::ArgHelper::OBJECT_STORE[_v2.address]
          _proc.call(_v3, _v4)
        end
        CODE

        builder.mapping_method_definition.must_equal expected
      end
    end

    describe "for a signal with an argument and a return value" do
      let(:signal_info) {
        get_signal_introspection_data "Regress", "TestObj", "sig-with-int64-prop" }

      it "returns a valid mapping method" do
        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
          _v4 = ::Regress::TestObj.wrap(_v1)
          _v5 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
          _v6 = _proc.call(_v4, _v2, _v5)
          return _v6
        end
        CODE

        builder.mapping_method_definition.must_equal expected
      end
    end

    describe "for a signal with an enum argument" do
      let(:signal_info) {
        get_signal_introspection_data "Gio", "MountOperation", "reply" }

      it "returns a valid mapping method" do
        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
          _v4 = ::Gio::MountOperation.wrap(_v1)
          _v5 = ::Gio::MountOperationResult[_v2]
          _v6 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
          _proc.call(_v4, _v5, _v6)
        end
        CODE<commit_msg>Add skip guard<commit_after>require 'gir_ffi_test_helper'

describe GirFFI::Builders::SignalBuilder do
  let(:builder) { GirFFI::Builders::SignalBuilder.new signal_info }

  describe "#mapping_method_definition" do
    describe "for a signal with no arguments or return value" do
      let(:signal_info) {
        get_signal_introspection_data "Regress", "TestObj", "test" }

      it "returns a valid mapping method including receiver and user data" do
        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2)
          _v3 = ::Regress::TestObj.wrap(_v1)
          _v4 = GirFFI::ArgHelper::OBJECT_STORE[_v2.address]
          _proc.call(_v3, _v4)
        end
        CODE

        builder.mapping_method_definition.must_equal expected
      end
    end

    describe "for a signal with an argument and a return value" do
      let(:signal_info) {
        get_signal_introspection_data "Regress", "TestObj", "sig-with-int64-prop" }

      it "returns a valid mapping method" do
        skip unless signal_info

        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
          _v4 = ::Regress::TestObj.wrap(_v1)
          _v5 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
          _v6 = _proc.call(_v4, _v2, _v5)
          return _v6
        end
        CODE

        builder.mapping_method_definition.must_equal expected
      end
    end

    describe "for a signal with an enum argument" do
      let(:signal_info) {
        get_signal_introspection_data "Gio", "MountOperation", "reply" }

      it "returns a valid mapping method" do
        expected = <<-CODE.reset_indentation
        def self.call_with_argument_mapping(_proc, _v1, _v2, _v3)
          _v4 = ::Gio::MountOperation.wrap(_v1)
          _v5 = ::Gio::MountOperationResult[_v2]
          _v6 = GirFFI::ArgHelper::OBJECT_STORE[_v3.address]
          _proc.call(_v4, _v5, _v6)
        end
        CODE
{'fraction_non_alphanumeric': 0.09299948901379662, 'fraction_numerical': 0.017373530914665303, 'mean_word_length': 2.7535953978906997, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968161', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1253, 'n_words': 290}