From 19af495f4152cd7b8580ceab2a168182f44bedbb Mon Sep 17 00:00:00 2001 From: Ian Martins Date: Thu, 12 Nov 2020 05:18:48 -0500 Subject: [PATCH 2/2] ob-java.el: Allow for more whitespace in java code * lisp/ob-java.el (defconst *-re): Updated regexps to allow for more whitespace in the content of java code blocks, and removed some redundancies. * testing/lisp/test-ob-java.el (ob-java/simple-with-main-whitespace): Added test case with lots of whitespace. --- lisp/ob-java.el | 10 +++++----- testing/lisp/test-ob-java.el | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lisp/ob-java.el b/lisp/ob-java.el index 92e873f0d..d65176d4e 100644 --- a/lisp/ob-java.el +++ b/lisp/ob-java.el @@ -77,15 +77,15 @@ like javac -verbose." :package-version '(Org . "9.5") :type 'symbol) -(defconst org-babel-java--package-re "^[[:space:]]*package[[:space:]]+\\\([[:alnum:]_\.]+\\\);$" +(defconst org-babel-java--package-re "^[[:space:]]*package[[:space:]]+\\\([[:alnum:]_\.]+\\\)[[:space:]]*;$" "Regexp for the package statement.") -(defconst org-babel-java--imports-re "^[[:space:]]*import[[:space:]]+\\\([[:alnum:]_\.]+\\\);$" +(defconst org-babel-java--imports-re "^[[:space:]]*import[[:space:]]+\\\([[:alnum:]_\.]+\\\)[[:space:]]*;$" "Regexp for import statements.") -(defconst org-babel-java--class-re "^[[:space:]]*\\\(?:public[[:space:]]+\\\)?class[[:space:]]+\\\([[:alnum:]_]+\\\)[[:space:]]*\n?[[:space:]]*{" +(defconst org-babel-java--class-re "^[[:space:]]*\\\(?:public[[:space:]]+\\\)?class[[:space:]]+\\\([[:alnum:]_]+\\\)[[:space:]]*{" "Regexp for the class declaration.") -(defconst org-babel-java--main-re "public static void main(String\\\(?:\\[]\\\)?[[:space:]]+[^ ]+\\\(?:\\[]\\\)?).*\n?[[:space:]]*{" +(defconst org-babel-java--main-re "public[[:space:]]+static[[:space:]]+void[[:space:]]+main[[:space:]]*([[:space:]]*String[[:space:]]*.*[[:space:]]*)[[:space:]]*.*[[:space:]]*{" "Regexp for the main method declaration.") -(defconst org-babel-java--any-method-re "public .*(.*).*\n?[[:space:]]*{" +(defconst org-babel-java--any-method-re "public[[:space:]]+.*[[:space:]]*([[:space:]]*.*[[:space:]]*)[[:space:]]*.*[[:space:]]*{" "Regexp for any method.") (defconst org-babel-java--result-wrapper "\n public static String __toString(Object val) { if (val instanceof String) { diff --git a/testing/lisp/test-ob-java.el b/testing/lisp/test-ob-java.el index e14975412..50d3ef5b0 100644 --- a/testing/lisp/test-ob-java.el +++ b/testing/lisp/test-ob-java.el @@ -128,6 +128,24 @@ public static void main(String args[]) { #+end_src" (should (string= "42" (org-babel-execute-src-block))))) +(ert-deftest ob-java/simple-with-main-whitespace () + "Hello world program that defines a main function with the square brackets after `args'." + (org-test-with-temp-text + "#+begin_src java :results output silent +public +static +void +main + ( + String + args [] + ) +{ + System.out.print(42); +} +#+end_src" + (should (string= "42" (org-babel-execute-src-block))))) + (ert-deftest ob-java/simple-with-class () "Hello world program that defines a class." (org-test-with-temp-text -- 2.25.1