Skip to content

Commit

Permalink
Add regexp-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kostafey committed Nov 10, 2024
1 parent 87862cb commit 8da1115
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ejc_sql/connect.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; connect.clj -- Core clojure functions for ejc-sql emacs extension.

;;; Copyright © 2013-2023 - Kostafey <[email protected]>
;;; Copyright © 2013-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 Down Expand Up @@ -119,7 +119,7 @@ SELECT * FROM urls WHERE path like '%http://localhost%'"
(def comments-re
"Regex to search comments in SQL expression."
(java.util.regex.Pattern/compile
"(?:/\\*.*?\\*/)|(?:--.*?$)",
"(?:/\\*.*?\\*/[\\s;]*\n?)|(?:--.*?$\n)",
(bit-or java.util.regex.Pattern/DOTALL
java.util.regex.Pattern/MULTILINE)))

Expand Down
45 changes: 45 additions & 0 deletions test/ejc_sql/regexp_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns ejc-sql.regexp-test
(:require [clojure.string :as s]
[clojure.test :refer [deftest testing is]]
[ejc-sql.connect :as conn]))

(deftest comments-re-test
(testing "comments-re test."

(is (= "
DROP TABLE IF EXISTS `user`;
" (s/replace "
DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
DROP TABLE IF EXISTS `user`;
" (s/replace "
-- Remove before recreate
DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
" (s/replace "
-- Remove before recreate DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
DROP TABLE IF EXISTS `user`;
" (s/replace "
/* Remove before recreate */
DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
DROP TABLE IF EXISTS `user`;
" (s/replace "
/* Remove before recreate */;
DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))

(is (= "
DROP TABLE IF EXISTS `user`;
" (s/replace "
/* Remove before recreate */; DROP TABLE IF EXISTS `user`;
" conn/comments-re "")))))

0 comments on commit 8da1115

Please sign in to comment.