require 'spec_helper' RSpec.describe Pluginscan::ErrorListPrinter do describe "error_lines" do it 'returns nothing when there are no issues' do issues = Pluginscan::Issues.new({}) expect(Pluginscan::ErrorListPrinter.new.error_lines(issues)).to eq [] end it 'returns an array of vim-compatible error lines when there were two issues in two different files' do check1 = double(name: "Bad thing") check_findings1 = Pluginscan::CheckFindings.new(check1) check_findings1.add [Pluginscan::Finding.new(17, " foo bar baz", "bar")] check2 = double(name: "Other bad thing") check_findings2 = Pluginscan::CheckFindings.new(check2) check_findings2.add [Pluginscan::Finding.new(23, "\thaz qux qix", "qux")] issues = Pluginscan::Issues.new( "./foo/bar.php" => [check_findings1], "./foo/bar/baz.php" => [], "./foo/bar/qux.php" => [check_findings2], ) expect(Pluginscan::ErrorListPrinter.new.error_lines(issues)).to eq [ %("./foo/bar.php", line 17, col 7: [Bad thing] foo bar baz), %("./foo/bar/qux.php", line 23, col 6: [Other bad thing] haz qux qix), # looks like vim treats tabs as single spaces for the purposes of using columns ] end it 'escapes colons (:) - these mess with the formatting' do check = double(name: "Bad thing") check_findings = Pluginscan::CheckFindings.new(check) source_line = %($retrieved_stats = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "mlw_results W HERE (time_taken_real BETWEEN '".$stat_date." 00:00:00' AND '".$stat_end_date." 23:59:59') AND deleted=0");) check_findings.add [Pluginscan::Finding.new(23, source_line, '$wpdb')] issues = Pluginscan::Issues.new( "./foo/bar.php" => [check_findings], ) expect(Pluginscan::ErrorListPrinter.new.error_lines(issues).first).to include %q(00\:00\:00) end end end