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

index_spec.rb (3577B)


      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 Index do
     22 	before :all do
     23 		FileUtils.mkdir_p TMP_DIR
     24 	end
     25 
     26 	after :all do
     27 		# FileUtils.rm_rf TMP_DIR
     28 	end
     29 
     30 	let(:index) { Index.new }
     31 
     32 	it "calls dispose_index on GC" do
     33 		index.autorelease = false
     34 		# It's possible for this to be called multiple times if there are other Index instances created during test
     35 		# expect(Lib).to receive(:dispose_index).with(index).once
     36 		expect{index.free}.not_to raise_error
     37 	end
     38 
     39 	describe '#parse_translation_unit' do
     40 		it "can parse a source file" do
     41 			translation_unit = index.parse_translation_unit fixture_path("a.c")
     42 			expect(translation_unit).to be_kind_of(TranslationUnit)
     43 		end
     44 
     45 		it "raises error when file is not found" do
     46 			expect { index.parse_translation_unit fixture_path("xxxxxxxxx.c") }.to raise_error(FFI::Clang::Error)
     47 		end
     48 
     49 		it "can handle command line options" do
     50 			expect{index.parse_translation_unit(fixture_path("a.c"), ["-std=c++11"])}.not_to raise_error
     51 		end
     52 
     53 		it 'can handle translation unit options' do 
     54 			expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [:incomplete, :single_file_parse, :cache_completion_results])}.not_to raise_error
     55 		end
     56 
     57 		it 'can handle missing translation options' do 
     58 			expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [])}.not_to raise_error
     59 		end
     60 
     61 		it 'can handle translation options with random values' do 
     62 			expect{index.parse_translation_unit(fixture_path("a.c"), [], [], {:incomplete => 654, :single_file_parse => 8, :cache_completion_results => 93})}.not_to raise_error
     63 		end
     64 
     65 		it "raises error when one of the translation options is invalid" do
     66 			expect{index.parse_translation_unit(fixture_path("a.c"), [], [], [:incomplete, :random_option, :cache_completion_results])}.to raise_error(FFI::Clang::Error)
     67 		end
     68 	end
     69 
     70 	describe '#create_translation_unit' do
     71 		let(:simple_ast_path) {"#{TMP_DIR}/simple.ast"}
     72 		
     73 		before :each do
     74 			translation_unit = index.parse_translation_unit fixture_path("simple.c")
     75 			
     76 			translation_unit.save(simple_ast_path)
     77 		end
     78 
     79 		it "can create translation unit from a ast file" do
     80 			expect(FileTest.exist?("#{TMP_DIR}/simple.ast")).to be true
     81 			translation_unit = index.create_translation_unit "#{TMP_DIR}/simple.ast"
     82 			expect(translation_unit).to be_kind_of(TranslationUnit)
     83 		end
     84 
     85 		it "raises error when file is not found" do
     86 			expect(FileTest.exist?('not_found.ast')).to be false
     87 			expect { index.create_translation_unit 'not_found.ast' }.to raise_error(FFI::Clang::Error)
     88 		end
     89 	end
     90 end