generate_test

in lib/twitter_cldr/resources/bidi_test_importer.rb [38:78]


      def generate_test
        run_hash = {}

        File.open(source_file, 'r').each_line do |ln|
          cur_line = ln.strip

          case cur_line[0]
            when '#', '@'
              next
            else
              input, bitset = cur_line.split('; ')

              expand_bitset_str(bitset).each_with_index do |check, index|
                if check
                  types = input.split(" ")
                  direction = get_java_direction(DIRECTIONS[index])
                  bidi = Java::Classpath::Bidi.new(types_to_string(types), direction)
                  levels = types.each_with_index.map { |_, idx| bidi.getLevelAt(idx) }
                  reorder_arr = Java::Classpath::Bidi.reorderVisually(levels.dup, 0, (0...types.size).to_a, 0, types.size).to_a

                  key = "#{levels.join(" ")} | #{reorder_arr.join(" ")}"
                  run_hash[key] ||= {}
                  run_hash[key][input] ||= 0
                  run_hash[key][input] |= (2 ** index)
                end
              end
          end
        end

        File.open(output_file, 'w+') do |out|
          run_hash.each_pair do |levels_and_reorders, inputs|
            levels, reorders = levels_and_reorders.split(' | ')
            out.write("@Levels: #{levels}\n")
            out.write("@Reorder: #{reorders}\n")
            inputs.each_pair do |input, bitset|
              out.write("#{input}; #{bitset}\n")
            end
          end
        end
      end