Sha256: dc6221dbe3cd143087763c72820b8ee2ec584650209a2da28a733c1037aa8361

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module W3cRspecValidators
  class ErrorParser
    def self.parse_html_error err, actual
      seperator = "######\n"
      error = /line \d.*/.match err.to_s
      line_number = /line (\d*)/.match(err.to_s)[1].to_i

      sbody = actual.split("\n")
      context = sbody[[line_number-3,0].max...line_number-1].join("\n")
      context += "\n>>" + sbody[line_number-1] + "\n"
      context += sbody[line_number..line_number+2].join("\n")

      seperator + error.to_s + "\n\n" + context + "\n"
    end

    def self.parse_css_error err, actual
      seperator = "######\n"
      error = /line \d*:(.*)/m.match(err.to_s)[1]
      line_number = /line (\d*)/.match(err.to_s)[1].to_i

      stext = actual.split("\n")

      i = line_number
      file = ""
      while true do
        if i == 0 || match = /\/\* line \d*,(.*)\*\//.match(stext[i])
          unless match.nil?
            file = match[1].strip
          end
          break
        end
        i -= 1
      end
      real_line_number = line_number - i - 1

      context = stext[[line_number-3,0].max...line_number-1].join("\n")
      context += "\n>>" + stext[line_number-1] + "\n"
      context += stext[line_number..line_number+2].join("\n")

      seperator + error.to_s.gsub(/\n/,"").gsub("  ", "") + "\nReal code location(guessed) in File " + file + " on line #{real_line_number}\n\nCode context:\n" + context + "\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
w3c_rspec_validators-0.3.0 lib/w3c_rspec_validators/error_parser.rb
w3c_rspec_validators-0.2.1 lib/w3c_rspec_validators/error_parser.rb
w3c_rspec_validators-0.2.0 lib/w3c_rspec_validators/error_parser.rb