11import os
22
3- from clang .cindex import Config , File , Index
3+ from clang .cindex import Config , File , Index , TranslationUnit
44
55if "CLANG_LIBRARY_PATH" in os .environ :
66 Config .set_library_path (os .environ ["CLANG_LIBRARY_PATH" ])
77
88import unittest
99
10+ inputs_dir = os .path .join (os .path .dirname (__file__ ), "INPUTS" )
1011
1112class TestFile (unittest .TestCase ):
1213 def test_file (self ):
@@ -16,3 +17,54 @@ def test_file(self):
1617 self .assertEqual (str (file ), "t.c" )
1718 self .assertEqual (file .name , "t.c" )
1819 self .assertEqual (repr (file ), "<File: t.c>" )
20+
21+ def test_file_eq (self ):
22+ path = os .path .join (inputs_dir , "testfile.c" )
23+ path_a = os .path .join (inputs_dir , "a.inc" )
24+ path_b = os .path .join (inputs_dir , "b.inc" )
25+ tu = TranslationUnit .from_source (path )
26+ main_file = File .from_name (tu , path )
27+ a_file = File .from_name (tu , path_a )
28+ a_file2 = File .from_name (tu , path_a )
29+ b_file = File .from_name (tu , path_b )
30+
31+ self .assertEqual (a_file , a_file2 )
32+ self .assertNotEqual (a_file , b_file )
33+ self .assertNotEqual (main_file , a_file )
34+ self .assertNotEqual (main_file , b_file )
35+ self .assertNotEqual (main_file , "t.c" )
36+
37+ def test_file_eq_in_memory (self ):
38+ tu = TranslationUnit .from_source (
39+ "testfile.c" ,
40+ unsaved_files = [
41+ (
42+ "testfile.c" ,
43+ """
44+ int a[] = {
45+ #include "a.inc"
46+ };
47+ int b[] = {
48+ #include "b.inc"
49+ };
50+ """ ,
51+ ),
52+ ("a.inc" , "1,2,3" ),
53+ ("b.inc" , "1,2,3" ),
54+ ],
55+ )
56+
57+ path = os .path .join (inputs_dir , "testfile.c" )
58+ path_a = os .path .join (inputs_dir , "a.inc" )
59+ path_b = os .path .join (inputs_dir , "b.inc" )
60+ tu = TranslationUnit .from_source (path )
61+ main_file = File .from_name (tu , path )
62+ a_file = File .from_name (tu , path_a )
63+ a_file2 = File .from_name (tu , path_a )
64+ b_file = File .from_name (tu , path_b )
65+
66+ self .assertEqual (a_file , a_file2 )
67+ self .assertNotEqual (a_file , b_file )
68+ self .assertNotEqual (main_file , a_file )
69+ self .assertNotEqual (main_file , b_file )
70+ self .assertNotEqual (main_file , "a.inc" )
0 commit comments