<commit_before>require 'res/ir'

module Res
  module Parsers
    class AndroidJunit
      attr_accessor :io
     
      def initialize(instrument_output)
        result = Array.new
        result = parse(instrument_output)
        ir = ::Res::IR.new( :type        => 'AndroidJUnitRunner', 
                            :started     => "",
                            :finished    => Time.now(),
                            :results     => result
                            )
        @io = File.open("./instruments.res", "w")
        @io.puts ir.json
        @io.close
      end

      def parse(output)
        class_name = Array.new
        test = Array.new
        result = Array.new
        test = {
          type: "AndroidJUnit::Test",
          name: 'UNKNOWN',
          status: "passed"
        }
        File.open(output) do |f|
          f.each_line do |line|
            if line.include?("INSTRUMENTATION_STATUS_CODE")
              # TODO Check that this indicates the end of test information
              result.last[:children] << test
              test = {
                type: "AndroidJUnit::Test",
                name: 'UNKNOWN',
                status: "passed"
              }
            end

            if line.include?("class")
              line = line.gsub("INSTRUMENTATION_STATUS: class=", "").strip
              if !class_name.include? line
                class_name.push(line) 
                result << {
                  type: "AndroidJUnit::Class",
                  name: class_name.last,
                  children: Array.new
                }
              end
            elsif line.include?("test=")
              test[:name] = line.gsub("INSTRUMENTATION_STATUS: test=", "").strip
            elsif line.include?("Error in ")
              test[:status] = 'failed'
            end
          end
        end
        result
      end
    end
  end
end
<commit_msg>Assumptions about output format have been checked<commit_after>require 'res/ir'

module Res
  module Parsers
    class AndroidJunit
      attr_accessor :io
     
      def initialize(instrument_output)
        result = Array.new
        result = parse(instrument_output)
        ir = ::Res::IR.new( :type        => 'AndroidJUnitRunner', 
                            :started     => "",
                            :finished    => Time.now(),
                            :results     => result
                            )
        @io = File.open("./instruments.res", "w")
        @io.puts ir.json
        @io.close
      end

      def parse(output)
        class_name = Array.new
        test = Array.new
        result = Array.new
        test = {
          type: "AndroidJUnit::Test",
          name: 'UNKNOWN',
          status: "passed"
        }
        File.open(output) do |f|
          f.each_line do |line|
            if line.include?("INSTRUMENTATION_STATUS_CODE")
              result.last[:children] << test
              test = {
                type: "AndroidJUnit::Test",
                name: 'UNKNOWN',
                status: "passed"
              }
            end

            if line.include?("class")
              line = line.gsub("INSTRUMENTATION_STATUS: class=", "").strip
              if !class_name.include? line
                class_name.push(line) 
                result << {
                  type: "AndroidJUnit::Class",
                  name: class_name.last,
                  children: Array.new
                }
              end
            elsif line.include?("test=")
              test[:name] = line.gsub("INSTRUMENTATION_STATUS: test=", "").strip
            elsif line.include?("Error in ")
              test[:status] = 'failed'
            end
          end
        end
        result
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1037410453701247, 'fraction_numerical': 0.0, 'mean_word_length': 1.2098475967174678, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4759187', 'n_tokens_mistral': 1014, 'n_tokens_neox': 985, 'n_words': 220}