def __getitem__(self, i):
cc = CompileCommands_getCommand(self.ccmds, i)
- if cc is None:
+ if not cc:
raise IndexError
return CompileCommand(cc, self)
for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
assert arg.spelling == exp
+def test_compilecommand_iterator_stops():
+ """Check that iterator stops after the correct number of elements"""
+ cdb = CompilationDatabase.fromDirectory(kInputsDir)
+ count = 0
+ for cmd in cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp'):
+ count += 1
+ assert count <= 2
+
def test_compilationDB_references():
"""Ensure CompilationsCommands are independent of the database"""
cdb = CompilationDatabase.fromDirectory(kInputsDir)