ffi-clang

FORK: Ruby FFI bindings for my custom patched clang 8.0.
git clone https://git.neptards.moe/neptards/ffi-clang.git
Log | Files | Refs | README

source_location_spec.rb (5030B)


      1 # Copyright, 2010-2012 by Jari Bakken.
      2 # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
      3 # Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
      4 # Copyright, 2014, by Masahiro Sano.
      5 # 
      6 # Permission is hereby granted, free of charge, to any person obtaining a copy
      7 # of this software and associated documentation files (the "Software"), to deal
      8 # in the Software without restriction, including without limitation the rights
      9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     10 # copies of the Software, and to permit persons to whom the Software is
     11 # furnished to do so, subject to the following conditions:
     12 # 
     13 # The above copyright notice and this permission notice shall be included in
     14 # all copies or substantial portions of the Software.
     15 # 
     16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     22 # THE SOFTWARE.
     23 
     24 describe SourceLocation do
     25 	let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
     26 	let(:translation_unit_location) { translation_unit.cursor.location }
     27 	let(:diagnostic_location) { translation_unit.diagnostics.first.location }
     28 	let(:loc1_translation_unit) { Index.new.parse_translation_unit(fixture_path("location1.c")) }
     29 	let(:loc1_cursor) { find_first(loc1_translation_unit.cursor, :cursor_function) }
     30 	let(:docs_cursor) { Index.new.parse_translation_unit(fixture_path("docs.c")).cursor }
     31 
     32 	it "should have a nil File if the SourceLocation is for a Translation Unit" do
     33 		expect(translation_unit_location.file).to be_nil
     34 	end
     35 
     36 	it "should provide a File, line and column for a Diagnostic" do
     37 		expect(diagnostic_location.file).to eq(fixture_path("list.c"))
     38 		expect(diagnostic_location.line).to equal(5)
     39 		expect(diagnostic_location.column).to equal(9)
     40 	end
     41 
     42 	it "should be ExpansionLocation" do
     43 		expect(translation_unit_location).to be_kind_of(SourceLocation)
     44 		expect(translation_unit_location).to be_kind_of(ExpansionLocation)
     45 	end
     46 
     47 	describe "Null Location" do
     48 		let(:null_location) { SourceLocation.null_location }
     49 		it "can be a null location" do
     50 			expect(null_location).to be_kind_of(SourceLocation)
     51 			expect(null_location.file).to be_nil
     52 			expect(null_location.line).to eq(0)
     53 			expect(null_location.column).to eq(0)
     54 			expect(null_location.offset).to eq(0)
     55 		end
     56 
     57 		it "is null?" do
     58 			expect(null_location.null?).to equal(true)
     59 		end
     60 
     61 		it "compares as equal to another null location instance" do
     62 			expect(null_location).to eq(SourceLocation.null_location)
     63 		end
     64 	end
     65 
     66 	describe "#from_main_file?" do
     67 		it "returns true if the cursor location is in main file" do
     68 			expect(loc1_cursor.location.from_main_file?).to be true
     69 		end
     70 
     71 		it "returns false if the cursor location is not in main file" do
     72 			expect(docs_cursor.location.from_main_file?).to be false
     73 		end
     74 	end
     75 
     76 	describe "#in_system_header?" do
     77 		it "returns false if the cursor location is not in system header" do
     78 			expect(loc1_cursor.location.in_system_header?).to be false
     79 		end
     80 	end
     81 
     82 	describe "#expansion_location" do
     83 		let (:expansion_location) { loc1_cursor.location.expansion_location }
     84 
     85 		it "should be ExpansionLocaion" do
     86 			expect(expansion_location).to be_kind_of(SourceLocation)
     87 			expect(expansion_location).to be_kind_of(ExpansionLocation)
     88 		end
     89 
     90 		it "returns source location that does not care a # line directive" do
     91 			expect(expansion_location.line).to eq(3)
     92 		end
     93 	end
     94 
     95 	describe "#presumed_location" do
     96 		let (:presumed_location) { loc1_cursor.location.presumed_location }
     97 
     98 		it "should be FileLocaion" do
     99 			expect(presumed_location).to be_kind_of(SourceLocation)
    100 			expect(presumed_location).to be_kind_of(PresumedLocation)
    101 		end
    102 
    103 		it "returns preprocessed filename" do
    104 			expect(presumed_location.filename).to eq("dummy.c")
    105 		end
    106 
    107 		it "returns source location specified by a # line directive" do
    108 			expect(presumed_location.line).to eq(124)
    109 		end
    110 	end
    111 
    112 	describe "#file_location" do
    113 		let (:file_location) { loc1_cursor.location.file_location }
    114 
    115 		it "should be FileLocaion" do
    116 			expect(file_location).to be_kind_of(SourceLocation)
    117 			expect(file_location).to be_kind_of(FileLocation)
    118 		end
    119 
    120 		it "returns source location that does not care a # line directive" do
    121 			expect(file_location.line).to eq(3)
    122 		end
    123 	end
    124 
    125 	describe "#spelling_location" do
    126 		let (:spelling_location) { loc1_cursor.location.spelling_location }
    127 
    128 		it "should be SpellingLocaion" do
    129 			expect(spelling_location).to be_kind_of(SourceLocation)
    130 			expect(spelling_location).to be_kind_of(SpellingLocation)
    131 		end
    132 
    133 		it "returns source location that does not care a # line directive" do
    134 			expect(spelling_location.line).to eq(3)
    135 		end
    136 	end
    137 
    138 end