Skip to content

Commit

Permalink
Fix ejc-sql-separator-re & add tests to regexp_test
Browse files Browse the repository at this point in the history
  • Loading branch information
kostafey committed Nov 10, 2024
1 parent 8da1115 commit 1b5b87e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ejc-format.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; ejc-format.el -- SQL formatting library (the part of ejc-sql).

;;; Copyright © 2012-2019 - Kostafey <[email protected]>
;;; Copyright © 2012-2024 - Kostafey <[email protected]>

;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
Expand All @@ -27,8 +27,8 @@
"The char with purpose to separate the SQL statement both other.")

(defun ejc-sql-separator-re ()
(format "^\\s-*%s\\s-*" (or (alist-get :separator ejc-db)
ejc-sql-separator)))
(format "^\\s-*%s\\(\\s-+\\|\n\\)" (or (alist-get :separator ejc-db)
ejc-sql-separator)))

(defun ejc-get-border-top ()
"Get top position of batch statement(s) seperator `ejc-sql-separator'.
Expand Down
15 changes: 15 additions & 0 deletions test/ejc_sql/regexp_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ DROP TABLE IF EXISTS `user`;
(is (= "
" (s/replace "
-- Remove before recreate DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
" (s/replace "
/* Remove before recreate */;
" conn/comments-re "")))

(is (= "
Expand All @@ -43,3 +48,13 @@ DROP TABLE IF EXISTS `user`;
" (s/replace "
/* Remove before recreate */; DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))))

(deftest separator-re-test
(testing "get-separator-re test."
(is (= ["\n/* Remove before recreate */"
"\nDROP TABLE IF EXISTS `user`"
"\n"]
(s/split "
/* Remove before recreate */;
DROP TABLE IF EXISTS `user`;
" (conn/get-separator-re ";"))))))

0 comments on commit 1b5b87e

Please sign in to comment.