From c094743e840efcc844fe1241ba656c270f033e45 Mon Sep 17 00:00:00 2001 From: James Westman Date: Fri, 17 Jun 2022 11:10:43 -0500 Subject: [PATCH] Fix compiling empty file --- blueprintcompiler/utils.py | 2 +- tests/sample_errors/empty.blp | 0 tests/sample_errors/empty.err | 1 + tests/test_samples.py | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/sample_errors/empty.blp create mode 100644 tests/sample_errors/empty.err diff --git a/blueprintcompiler/utils.py b/blueprintcompiler/utils.py index 6befea8..2d5451d 100644 --- a/blueprintcompiler/utils.py +++ b/blueprintcompiler/utils.py @@ -68,7 +68,7 @@ def did_you_mean(word: str, options: T.List[str]) -> T.Optional[str]: def idx_to_pos(idx: int, text: str) -> T.Tuple[int, int]: - if idx == 0: + if idx == 0 or len(text) == 0: return (0, 0) sp = text[:idx].splitlines(keepends=True) line_num = len(sp) diff --git a/tests/sample_errors/empty.blp b/tests/sample_errors/empty.blp new file mode 100644 index 0000000..e69de29 diff --git a/tests/sample_errors/empty.err b/tests/sample_errors/empty.err new file mode 100644 index 0000000..854962f --- /dev/null +++ b/tests/sample_errors/empty.err @@ -0,0 +1 @@ +1,0,0,File must start with a "using Gtk" directive (e.g. `using Gtk 4.0;`) \ No newline at end of file diff --git a/tests/test_samples.py b/tests/test_samples.py index 40e9d0b..51af836 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -180,6 +180,7 @@ class TestSamples(unittest.TestCase): self.assert_sample_error("does_not_implement") self.assert_sample_error("duplicate_obj_id") self.assert_sample_error("duplicates") + self.assert_sample_error("empty") self.assert_sample_error("enum_member_dne") self.assert_sample_error("filters_in_non_file_filter") self.assert_sample_error("gtk_3")