diagnostic_spec.rb (2877B)
1 2 describe Diagnostic do 3 let(:diagnostics) { Index.new.parse_translation_unit(fixture_path("list.c")).diagnostics } 4 let(:diagnostic) { diagnostics.first } 5 6 it "returns a string representation of the diagnostic" do 7 str = diagnostic.format 8 expect(str).to be_kind_of(String) 9 expect(str).to match(/does not match previous/) 10 end 11 12 it "returns a string representation according to the given opts" do 13 expect(diagnostic.format(:source_location => true)).to include("list.c:5") 14 end 15 16 it "returns the text of the diagnostic" do 17 expect(diagnostic.spelling).to be_kind_of(String) 18 end 19 20 it "returns the severity of the diagnostic" do 21 expect(diagnostic.severity).to eq(:error) 22 end 23 24 it "returns the ranges of the diagnostic" do 25 rs = diagnostics[1].ranges 26 expect(rs).to be_kind_of(Array) 27 expect(rs).not_to be_empty 28 expect(rs.first).to be_kind_of(SourceRange) 29 end 30 31 it "calls dispose_diagnostic on GC" do 32 diagnostic.autorelease = false 33 # expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).once 34 expect{diagnostic.free}.not_to raise_error 35 end 36 37 context "#self.default_display_opts" do 38 it "returns the set of display options" do 39 expect(FFI::Clang::Diagnostic.default_display_opts).to be_kind_of(Hash) 40 expect(FFI::Clang::Diagnostic.default_display_opts.keys.map(&:class).uniq).to eq([Symbol]) 41 expect(FFI::Clang::Diagnostic.default_display_opts.values.uniq).to eq([true]) 42 end 43 end 44 45 context "#fixits" do 46 it "returns the replacement information by Array of Hash" do 47 expect(diagnostic.fixits).to be_kind_of(Array) 48 expect(diagnostic.fixits.first).to be_kind_of(Hash) 49 expect(diagnostic.fixits.first[:text]).to eq('struct') 50 expect(diagnostic.fixits.first[:range]).to be_kind_of(SourceRange) 51 end 52 end 53 54 context "#children" do 55 it "returns child diagnostics by Array" do 56 expect(diagnostic.children).to be_kind_of(Array) 57 expect(diagnostic.children.first).to be_kind_of(Diagnostic) 58 expect(diagnostic.children.first.severity).to eq(:note) 59 end 60 end 61 62 context "#enable_option" do 63 it "returns the name of the command-line option that enabled this diagnostic" do 64 expect(diagnostics[3].enable_option).to be_kind_of(String) 65 expect(diagnostics[3].enable_option).to eq('-Wempty-body') 66 end 67 end 68 69 context "#disable_option" do 70 it "returns the name of the command-line option that disables this diagnostic" do 71 expect(diagnostics[3].disable_option).to be_kind_of(String) 72 expect(diagnostics[3].disable_option).to eq('-Wno-empty-body') 73 end 74 end 75 76 context "#category" do 77 it "returns the diagnostic category text" do 78 expect(diagnostic.category).to be_kind_of(String) 79 expect(diagnostic.category).to eq('Semantic Issue') 80 end 81 end 82 83 context "#category_id" do 84 it "returns the category number" do 85 expect(diagnostic.category_id).to be_kind_of(Integer) 86 expect(diagnostic.category_id).to eq(2) 87 end 88 end 89 end