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_range_spec.rb (2791B)


      1 # Copyright, 2014, by Masahiro Sano.
      2 # 
      3 # Permission is hereby granted, free of charge, to any person obtaining a copy
      4 # of this software and associated documentation files (the "Software"), to deal
      5 # in the Software without restriction, including without limitation the rights
      6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      7 # copies of the Software, and to permit persons to whom the Software is
      8 # furnished to do so, subject to the following conditions:
      9 # 
     10 # The above copyright notice and this permission notice shall be included in
     11 # all copies or substantial portions of the Software.
     12 # 
     13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     19 # THE SOFTWARE.
     20 
     21 describe SourceRange do
     22 	let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
     23 	let(:translation_unit_range) { translation_unit.cursor.extent }
     24 
     25 	it "can be obtained from a cursor" do
     26 		expect(translation_unit_range).to be_kind_of(SourceRange)
     27 		expect(translation_unit_range.null?).to be false
     28 	end
     29 
     30 	it "has start and end source location" do
     31 		expect(translation_unit_range.start).to be_kind_of(SourceLocation)
     32 		expect(translation_unit_range.start.null?).to be false
     33 		expect(translation_unit_range.end).to be_kind_of(SourceLocation)
     34 		expect(translation_unit_range.end.null?).to be false
     35 	end
     36 
     37 	describe "Null Range" do
     38 		let(:null_range) { SourceRange.null_range }
     39 		it "can be a null range" do
     40 			expect(null_range).to be_kind_of(SourceRange)
     41 		end
     42 
     43 		it "is null?" do
     44 			expect(null_range.null?).to equal(true)
     45 		end
     46 
     47 		it "has null locations" do
     48 		    expect(null_range.start.null?).to be true
     49 		    expect(null_range.end.null?).to be true
     50 		end
     51 
     52 		it "compares as equal to another null range instance" do
     53 			expect(null_range).to eq(SourceRange.null_range)
     54 		end
     55 	end
     56 
     57     describe "Get Range" do
     58         let(:range) { SourceRange.new(translation_unit_range.start, translation_unit_range.end) }
     59 
     60         it "can be obtained from two source locations" do
     61 			expect(range).to be_kind_of(SourceRange)
     62 			expect(range.null?).to be false
     63         end
     64 
     65         it "is same to original source range" do
     66 			expect(range).to eq(translation_unit_range)
     67         end
     68 
     69         it "is same to original source range's locations" do
     70 			expect(range.start).to eq(translation_unit_range.start)
     71 			expect(range.end).to eq(translation_unit_range.end)
     72         end
     73     end
     74 end