Class: TestCaseGenerator::GeneratorObjectiveC

Inherits:
Object
  • Object
show all
Defined in:
lib/test_case_generator/generator_objective_c.rb

Instance Method Summary collapse

Instance Method Details

#write_header(dsl_context, header_fn) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/test_case_generator/generator_objective_c.rb', line 36

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

#write_source(dsl_context, source_fn) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/test_case_generator/generator_objective_c.rb', line 57

def write_source(dsl_context, source_fn)
  tmp_fn = source_fn + '.tmp'
  source = File.open(source_fn).read
  File.open(tmp_fn, 'w') do |f|
    source.each_line do |line|
      f.puts line
      break if line =~ /^\s*\/\/\s*%%\s*$/
    end

    writer = IndentedWriter.new f

    dsl_context.each do |pattern|
      method_name = pattern.join '_'
      writer.blank
      writer.puts "- (void)test_#{method_name} {"

      pattern.each do |ptn|
        writer.block_indent '    ' do
          writer.puts "[self #{ptn}];"
        end
      end

      writer.puts '}'
    end

    writer.blank
    writer.puts '@end'
  end

  FileUtils.move tmp_fn, source_fn
end