From 8da1115a8791ab43ef2da18e07a1de66e6ed2d2c Mon Sep 17 00:00:00 2001 From: kostafey Date: Sun, 10 Nov 2024 03:33:28 +0300 Subject: [PATCH] Add regexp-test --- src/ejc_sql/connect.clj | 4 ++-- test/ejc_sql/regexp_test.clj | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/ejc_sql/regexp_test.clj diff --git a/src/ejc_sql/connect.clj b/src/ejc_sql/connect.clj index 645d8a3..4f83119 100644 --- a/src/ejc_sql/connect.clj +++ b/src/ejc_sql/connect.clj @@ -1,6 +1,6 @@ ;;; connect.clj -- Core clojure functions for ejc-sql emacs extension. -;;; Copyright © 2013-2023 - Kostafey +;;; Copyright © 2013-2024 - Kostafey ;;; 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 @@ -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))) diff --git a/test/ejc_sql/regexp_test.clj b/test/ejc_sql/regexp_test.clj new file mode 100644 index 0000000..16cac89 --- /dev/null +++ b/test/ejc_sql/regexp_test.clj @@ -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 "")))))