branch: scratch/editorconfig-cc
commit b08e13aefa2d3a8cfdd11ad358d13d0bf2d445bd
Author: 10sr <8slashes+...@gmail.com>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Add files used to test core functions
---
 .gitmodules                           |   3 +
 core-test                             |   1 +
 ert-tests/editorconfig-core-handle.el |  50 +++++++++++++++
 ert-tests/editorconfig-core.el        |  24 ++++++++
 ert-tests/editorconfig-fnmatch.el     | 113 ++++++++++++++++++++++++++++++++++
 ert-tests/editorconfig.el             |   0
 ert-tests/fixtures/dir1/parent.ini    |   2 +
 ert-tests/fixtures/handle.ini         |  10 +++
 ert-tests/fixtures/handle2.ini        |   3 +
 ert-tests/fixtures/parent.ini         |   4 ++
 10 files changed, 210 insertions(+)

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000..8941e6ddf6
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "editorconfig-core-test"]
+       path = core-test
+       url = https://github.com/editorconfig/editorconfig-core-test.git
diff --git a/core-test b/core-test
new file mode 160000
index 0000000000..a1fb189138
--- /dev/null
+++ b/core-test
@@ -0,0 +1 @@
+Subproject commit a1fb18913845e12b84835da8ea01a855d4c8be46
diff --git a/ert-tests/editorconfig-core-handle.el 
b/ert-tests/editorconfig-core-handle.el
new file mode 100644
index 0000000000..4f251d3889
--- /dev/null
+++ b/ert-tests/editorconfig-core-handle.el
@@ -0,0 +1,50 @@
+(require 'editorconfig-core-handle)
+
+(ert-deftest editorconfig-core-handle ()
+  ;; handle.ini
+  (let* ((fixtures (concat default-directory
+                           "ert-tests/fixtures/"))
+         (conf (concat fixtures
+                       "handle.ini"))
+         (handle (editorconfig-core-handle conf)))
+    (should (editorconfig-core-handle-root-p handle))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "b.js"))
+                   '((("key2" . "value2")))))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "a.js"))
+                   '((("key1" . "value1")) (("key2" . "value2"))))))
+  ;; Test twice for checking cache
+  (let* ((fixtures (concat default-directory
+                           "ert-tests/fixtures/"))
+         (conf (concat fixtures
+                       "handle.ini"))
+         (handle (editorconfig-core-handle conf)))
+    (should (editorconfig-core-handle-root-p handle))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "b.js"))
+                   '((("key2" . "value2")))))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "a.js"))
+                   '((("key1" . "value1")) (("key2" . "value2"))))))
+
+  ;; handle2.ini
+  (let* ((fixtures (concat default-directory
+                           "ert-tests/fixtures/"))
+         (conf (concat fixtures
+                       "handle2.ini"))
+         (handle (editorconfig-core-handle conf)))
+    (should-not (editorconfig-core-handle-root-p handle))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "b.js"))
+                   nil))
+    (should (equal (editorconfig-core-handle-get-properties handle
+                                                            (concat fixtures
+                                                                    "a.js"))
+                   '((("key" . "value"))))))
+  )
diff --git a/ert-tests/editorconfig-core.el b/ert-tests/editorconfig-core.el
new file mode 100644
index 0000000000..5dceda9789
--- /dev/null
+++ b/ert-tests/editorconfig-core.el
@@ -0,0 +1,24 @@
+(require 'editorconfig-core)
+
+(ert-deftest editorconfig-core--remove-duplicate ()
+  (should (equal (editorconfig-core--remove-duplicate '(("a" . 1) ("b" . 2) 
("c" . 3) ("b" . 4)))
+                 '(("a" . 1) ("b" . 4) ("c" . 3))))
+  (should (equal (editorconfig-core--remove-duplicate '(("a" . 1) ("b" . 2) 
("c" . 3)))
+                 '(("a" . 1) ("b" . 2) ("c" . 3))))
+  (should (equal (editorconfig-core--remove-duplicate nil)
+                 nil))
+  )
+
+
+(ert-deftest editorconfig-core--get-handles ()
+  (let* ((fixtures (concat default-directory
+                          "/ert-tests/fixtures/"))
+         (dir (concat fixtures
+                      "dir1"))
+         (confname "parent.ini")
+         (handles (editorconfig-core--get-handles dir
+                                                 confname)))
+    (should (= 2
+               (length handles)))
+    (should (editorconfig-core-handle-p (car handles)))
+    (should (editorconfig-core-handle-p (cadr handles)))))
diff --git a/ert-tests/editorconfig-fnmatch.el 
b/ert-tests/editorconfig-fnmatch.el
new file mode 100644
index 0000000000..41421589ee
--- /dev/null
+++ b/ert-tests/editorconfig-fnmatch.el
@@ -0,0 +1,113 @@
+(require 'editorconfig-fnmatch)
+
+
+(ert-deftest test-editorconfig-fnmatch-p ()
+  (let ((cases-t
+         '(("a.js" "a.js")
+           ("/dir/a.js" "/dir/a.js")
+
+           ("a.js" "*.js")
+           ("a.js" "**.js")
+           ("/dir/a.js" "/dir/*.js")
+           ("/dir/a.js" "/dir/*")
+
+           ("/dir/sub/a.js" "**.js")
+           ("/dir/sub/a.py" "/dir/**.py")
+
+           ("a.js" "?.js")
+           ("abc.js" "a?c.js")
+           ("/dir/a.js" "/dir/?.js")
+
+           ("a.js" "[abc].js")
+           ("b.js" "[abc].js")
+           ("ab.js" "[abc]b.js")
+           ("/dir/a.js" "/dir/[abc].js")
+           ("ab[e/]cd.i" "ab[e/]cd.i")
+           ("a.js" "[a-c].js")
+           ("1.js" "[1-3].js")
+           ("a.js" "[a-c1-3].js")
+           ("1.js" "[a-c1-3].js")
+
+           ("d.js" "[^abc].js")
+           ("db.js" "[^abc]b.js")
+           ("/dir/d.js" "/dir/[^abc].js")
+           ("d.js" "[^a-c].js")
+
+           ("a.js" "a.{py,js}")
+           ("a.py" "a.{py,js}")
+           ("/dir/a.py" "/dir/a.{py,js}")
+           ("/dir/a.py" "/dir/a.{py,js}")
+           ("a.js" "*.{py,js}")
+           ("a.py" "*.{py,js}")
+           ("/dir/a.js" "/dir/*.{py,js}")
+           ("/dir/a.py" "/dir/*.{py,js}")
+           ("/dir/sub/a.py" "**.{py,js}")
+           ("/dir/sub/a.py" "/dir/**.{py,js}")
+           ("{single}.b" "{single}.b")
+           ("{.f" "{.f")
+           ("}.f" "}.f")
+
+           ("a.js" "{a,[0-9]}.js")
+           ("1.js" "{a,[0-9]}.js")
+           ("-3.py" "{-3..3}.{js,py}")
+
+           ("1.js" "{0..3}.js")
+           ("1.js" "{0..+3}.js")
+           ("-1.js" "{-3..3}.js")
+           ("-1.js" "{-3..3}.js")
+
+           ("test3" 
"{test3,test0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 [...]
+           ))
+        (cases-nil
+         '(("a.js" "b.js")
+
+           ("a.js" "*.py")
+           ("/dir/a.js" "/dir/*.py")
+           ("/dir/sub/a.js" "/dir/*.js")
+
+           ("/dir/a.js" "/sub/**.js")
+           ("/dir/sub/a.js" "/sub/**.js")
+
+           ("ab.js" "?.js")
+           ("ab.js" "?a.js")
+           ("/dir/ab.js" "/dir/?.js")
+           ("/dir/ab.js" "/dir/?a.js")
+
+           ("d.js" "[abc].js")
+           ("db.js" "[abc]b.js")
+           ("/dir/d.js" "/dir/[abc].js")
+           ("d.js" "[a-c].js")
+           ("4.js" "[1-3].js")
+           ("d.js" "[a-c1-3].js")
+           ("4.js" "[a-c1-3].js")
+
+           ("a.js" "[^abc].js")
+           ("ab.js" "[^abc]b.js")
+           ("/dir/a.js" "/dir/[^abc].js")
+           ("a.js" "[^a-c].js")
+           ("a.js" "[^a-c1-3].js")
+           ("1.js" "[^a-c1-3].js")
+
+           ("a.el" "a.{py,js}")
+           ("a.el" "*.{py,js}")
+           ("/dir/a.el" "/dir/a.{py,js}")
+           ("/dir/a.el" "/dir/*.{py,js}")
+           ("/dir/a.el" "**.{py,js}")
+
+           ("1.js" "{3..6}.js")
+           ("-1.js" "{0..3}.js")
+           ("-1.js" "{3..-3}.js")
+           )))
+    (dolist (args cases-t)
+      (message "-> t: %S"
+               `(editorconfig-fnmatch-p ,@args))
+      (message "   Elapsed: %S"
+               (car (benchmark-run 3 (should (apply 'editorconfig-fnmatch-p
+                                                    args))))))
+    (dolist (args cases-nil)
+      (message "-> nil: %S"
+               `(editorconfig-fnmatch-p ,@args))
+      (message "   Elapsed: %S"
+               (car (benchmark-run 3 (should-not (apply 'editorconfig-fnmatch-p
+                                                        args)))))))
+  )
diff --git a/ert-tests/editorconfig.el b/ert-tests/editorconfig.el
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/ert-tests/fixtures/dir1/parent.ini 
b/ert-tests/fixtures/dir1/parent.ini
new file mode 100644
index 0000000000..0ced5f4659
--- /dev/null
+++ b/ert-tests/fixtures/dir1/parent.ini
@@ -0,0 +1,2 @@
+[a.js]
+key=none
diff --git a/ert-tests/fixtures/handle.ini b/ert-tests/fixtures/handle.ini
new file mode 100644
index 0000000000..2232b3f497
--- /dev/null
+++ b/ert-tests/fixtures/handle.ini
@@ -0,0 +1,10 @@
+root = true
+
+[a.js]
+key1=value1
+
+[*.js]
+key2=value2
+
+[*.py]
+key3=value3
diff --git a/ert-tests/fixtures/handle2.ini b/ert-tests/fixtures/handle2.ini
new file mode 100644
index 0000000000..3d0e134664
--- /dev/null
+++ b/ert-tests/fixtures/handle2.ini
@@ -0,0 +1,3 @@
+[a.js]
+
+key = value
diff --git a/ert-tests/fixtures/parent.ini b/ert-tests/fixtures/parent.ini
new file mode 100644
index 0000000000..57c72a852f
--- /dev/null
+++ b/ert-tests/fixtures/parent.ini
@@ -0,0 +1,4 @@
+root=true
+
+[a.js]
+key=value1

Reply via email to