diff --git a/__tests__/index.js b/__tests__/index.js index 29273a6..3294b79 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -6,6 +6,13 @@ function loadFile(name) { } describe("objective-c-parser", () => { + describe("empty file", () => { + const empty = loadFile("empty"); + it("should return an empty list of methods for an empty header file", () => { + expect(objcToJs(empty).methods).toEqual([]); + }); + }); + describe("basic example", () => { const basic = loadFile("basic"); it("should return name of basic example", () => { diff --git a/exampleFiles/empty.h b/exampleFiles/empty.h new file mode 100644 index 0000000..c81145a --- /dev/null +++ b/exampleFiles/empty.h @@ -0,0 +1,5 @@ +#import + +// just an empty header file + +@end diff --git a/index.js b/index.js index 95a4860..441c962 100644 --- a/index.js +++ b/index.js @@ -64,8 +64,9 @@ function extractNameOfMethodWithoutArguments(methodBody, rawArgs) { const parseMethods = file => { const lines = file.split("\n"); + const methodDeclarations = file.match(methodDeclarationRegex) || []; - return file.match(methodDeclarationRegex).map(methodDeclaration => { + return methodDeclarations.map(methodDeclaration => { const returnType = methodDeclaration.match(matchReturnType); const methodBody = methodDeclaration