diff --git a/src/jasentaa/position.clj b/src/jasentaa/position.clj index b69e14e..6266395 100644 --- a/src/jasentaa/position.clj +++ b/src/jasentaa/position.clj @@ -22,6 +22,8 @@ (apply str (map :char augmented-text))) (defn parse-exception [location] - (java.text.ParseException. - (str "Failed to parse text at line: " (:line location) ", col: " (:col location)) - (int (:offset location)))) + (if (nil? location) + (java.text.ParseException. (str "Unable to parse empty text") 0) + (java.text.ParseException. + (str "Failed to parse text at line: " (:line location) ", col: " (:col location)) + (int (:offset location))))) diff --git a/test/jasentaa/position_test.clj b/test/jasentaa/position_test.clj index eff3984..a64e90e 100644 --- a/test/jasentaa/position_test.clj +++ b/test/jasentaa/position_test.clj @@ -30,5 +30,8 @@ (deftest check-exception (is (thrown-with-msg? java.text.ParseException - #"Failed to parse text at line: 6, col: 31" - (throw (parse-exception (Location. \Y 6 31 321)))))) + #"Unable to parse empty text" + (throw (parse-exception nil)))) + (is (thrown-with-msg? java.text.ParseException + #"Failed to parse text at line: 6, col: 31" + (throw (parse-exception (Location. \Y 6 31 321)))))) diff --git a/test/jasentaa/worked_example_1.clj b/test/jasentaa/worked_example_1.clj index 5e7c4d6..2c67abc 100644 --- a/test/jasentaa/worked_example_1.clj +++ b/test/jasentaa/worked_example_1.clj @@ -76,4 +76,9 @@ (is (thrown-with-msg? java.text.ParseException #"Failed to parse text at line: 1, col: 7" - (parse-all search-expr "steel iron")))) + (parse-all search-expr "steel iron"))) + + (is (thrown-with-msg? + java.text.ParseException + #"Unable to parse empty text" + (parse-all search-expr ""))))