<commit_before>require 'test_case_generator/dsl_context'
require 'test_case_generator/indented_writer'

module TestCaseGenerator
  class GeneratorObjectiveC
    def can_handle?(source_fn)
      File.extname(source_fn).eql? '.m'
    end

    def write(ctx, source_fn)
      write_skeleton source_fn unless File.exists? source_fn
      write_header ctx, File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn)) + 'Generated.h')
      write_source ctx, source_fn
    end

    def make_class_name(filename)
      File.basename filename, ".*"
    end

    def write_skeleton(source_fn)
      class_name = make_class_name(source_fn)
      File.open(source_fn, 'w') do |f|
        writer = IndentedWriter.new f
        writer.puts <<EOS
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "#{class_name}Generated.h"
#pragma mark -

@interface #{class_name} : XCTestCase <#{class_name}Generated>
@end

@implementation #{class_name}

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

// %%
EOS
      end
    end

    def write_header(dsl_context, header_fn)
      protocol_name = File.basename(header_fn, File.extname(header_fn))
      tmp_fn = header_fn + '.tmp'
      File.open(tmp_fn, 'w') do |f|
        writer = IndentedWriter.new f

        writer.puts '#import <Foundation/Foundation.h>'
        writer.blank
        writer.puts "@protocol #{protocol_name} <NSObject>"

        dsl_context.labels.each do |label|
          method_name = label
          writer.puts "- (void)#{method_name};"
        end

        writer.puts '@end'
      end

      FileUtils.move tmp_fn, header_fn
    end
<commit_msg>ObjC: bug fix<commit_after>require 'test_case_generator/dsl_context'
require 'test_case_generator/indented_writer'

module TestCaseGenerator
  class GeneratorObjectiveC
    def can_handle?(source_fn)
      File.extname(source_fn).eql? '.m'
    end

    def write(ctx, source_fn)
      write_skeleton source_fn unless File.exists? source_fn
      write_header ctx, File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn)) + 'Generated.h')
      write_source ctx, source_fn
    end

    def make_class_name(filename)
      File.basename filename, ".*"
    end

    def write_skeleton(source_fn)
      class_name = make_class_name(source_fn)
      File.open(source_fn, 'w') do |f|
        writer = IndentedWriter.new f
        writer.puts <<EOS
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "#{class_name}Generated.h"

#pragma mark - #{class_name}

@interface #{class_name} : XCTestCase <#{class_name}Generated>
@end

@implementation #{class_name}

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

#pragma mark #{class_name}Generated

// TODO: ここにアクションを書いてください

// %%
EOS
      end
    end

    def write_header(dsl_context, header_fn)
      protocol_name = File.basename(header_fn, File.extname(header_fn))
      tmp_fn = header_fn + '.tmp'
      File.open(tmp_fn, 'w') do |f|
        writer = IndentedWriter.new f

        writer.puts '#import <Foundation/Foundation.h>'
        writer.blank
        writer.puts "@protocol #{protocol_name} <NSObject>"

        dsl_context.labels.each do |label|
          method_name = Utils.make_method_name label
          writer.puts "- (void)#{method_name};"
        end

        writer.puts '@end'
      end

      FileUtils.move tmp_fn, header_fn
    end

{'fraction_non_alphanumeric': 0.11421911421911422, 'fraction_numerical': 0.0, 'mean_word_length': 3.12124849939976, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '1880972', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1190, 'n_words': 233}