[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/flx 331ef6f109 001/182: first commit
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/flx 331ef6f109 001/182: first commit |
Date: |
Tue, 13 Dec 2022 03:59:13 -0500 (EST) |
branch: elpa/flx
commit 331ef6f109664f16102164a660046ef8a0cdc807
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>
first commit
---
.gitignore | 1 +
.travis.yml | 14 ++++++++++++
Makefile | 26 ++++++++++++++++++++++
mflex-sort.el | 22 +++++++++++++++++++
tests/mflex-test.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/run-test.el | 42 +++++++++++++++++++++++++++++++++++
6 files changed, 168 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..c531d9867f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.elc
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000..c143c8757c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: emacs-lisp
+before_install:
+ - git submodule update --init
+ - if [ "$EMACS" = 'emacs-snapshot' ]; then
+ sudo add-apt-repository -y ppa:cassou/emacs &&
+ sudo apt-get update -qq &&
+ sudo apt-get install -qq
+ emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot;
+ fi
+env:
+ - EMACS=emacs24
+ # - EMACS=emacs-snapshot
+script:
+ make travis-ci EMACS=$EMACS
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000..990b7e2cb9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+EMACS=emacs
+EMACS23=emacs23
+EMACS-OPTIONS=
+
+.PHONY: test test-nw travis-ci show-version before-test
+
+show-version: show-version
+ echo "*** Emacs version ***"
+ echo "EMACS = `which ${EMACS}`"
+ ${EMACS} --version
+
+install-ert:
+ emacs --batch -L "${PWD}/lib/ert/lisp/emacs-lisp" --eval "(require
'ert)" || ( git clone git://github.com/ohler/ert.git lib/ert && cd lib/ert &&
git checkout 00aef6e43 )
+
+
+before-test: show-version install-ert
+
+test: before-test
+ ${EMACS} -Q -L . -l tests/run-test.el
+
+test-nw: before-test
+ ${EMACS} -Q -nw -L . -l tests/run-test.el
+
+travis-ci: before-test
+ echo ${EMACS-OPTIONS}
+ ${EMACS} -batch -Q -l tests/run-test.el
diff --git a/mflex-sort.el b/mflex-sort.el
new file mode 100644
index 0000000000..a4812605db
--- /dev/null
+++ b/mflex-sort.el
@@ -0,0 +1,22 @@
+
+(defun mflex-all-combinations (list num)
+ "let LENGTH = (length list)
+
+return all combinations of sequences of NUM elements from list.
+
+The length of the resulting list is ("
+ (let ((length (length list))
+ (head (car list))
+ (rest (cdr list)))
+ (cond ((= 0 num)
+ (list nil))
+ ((= length num)
+ (list list))
+ (t
+ (append (mapcar
+ (lambda (list)
+ (cons head list))
+ (mflex-all-combinations rest (1- num)))
+ (mflex-all-combinations rest num))))))
+
+(provide 'mflex)
\ No newline at end of file
diff --git a/tests/mflex-test.el b/tests/mflex-test.el
new file mode 100644
index 0000000000..532b394998
--- /dev/null
+++ b/tests/mflex-test.el
@@ -0,0 +1,63 @@
+(require 'ert)
+(require 'mflex)
+
+
+;; for "every" function
+(require 'cl)
+
+(ert-deftest mflex-test-sanity ()
+ "sanity check."
+ (should (= 1 1)))
+
+
+(ert-deftest mflex-all-combinations ()
+ "making combinations."
+ (should (equal '((1) (2) (3))
+ (mflex-all-combinations '(1 2 3) 1)))
+ (should (= 210
+ (length (mflex-all-combinations '(1 2 3 4 5 6 7 8 9 10) 4)))))
+
+(ert-deftest mflex-basename-basic ()
+ "basic scoring -- matches get number, non-matches get nil"
+ ;; matches
+ (mapc (lambda (str)
+ (should (mflex-score "a" str 'file)))
+ '("a"
+ "ba"
+ "ab"
+ ".a"
+ "aaaa"
+ "foo.bra"
+ "a/foo"
+ "b/a/foo"
+ "b/.a/foo"
+ "b/.a./foo"))
+ ;; empty string should match everything
+ (mapc (lambda (str)
+ (should (mflex-score "" str 'file)))
+ '(""
+ "zz"
+ "."))
+ ;; non-matches
+ (mapc (lambda (str)
+ (should-not (mflex-score "a" str 'file)))
+ '(""
+ "zz"
+ ".")))
+
+
+(ert-deftest mflex-basename-entire ()
+ "whole match is preferred"
+ (let* ((query "a")
+ (higher (mflex-score "a" query 'file))
+ (lower (mflex-score "ab" query 'file)))
+ (should (> higher lowercase))))
+
+(ert-deftest mflex-basename-order ()
+ ""
+ (let* ((query "a")
+ (higher (mflex-score "a_b_c" query 'file))
+ (lower (mflex-score "b_a_c" query 'file)))
+ (should (> higher lowercase))))
+
+
diff --git a/tests/run-test.el b/tests/run-test.el
new file mode 100644
index 0000000000..b9e2eebe42
--- /dev/null
+++ b/tests/run-test.el
@@ -0,0 +1,42 @@
+;; Usage:
+;;
+;; emacs -Q -l tests/run-test.el # interactive mode
+;; emacs -batch -Q -l tests/run-test.el # batch mode
+
+
+;; Utils
+(defun mflex-test-join-path (path &rest rest)
+ "Join a list of PATHS with appropriate separator (such as /).
+
+\(fn &rest paths)"
+ (if rest
+ (concat (file-name-as-directory path) (apply 'mflex-test-join-path rest))
+ path))
+
+(defvar mflex-test-dir (file-name-directory load-file-name))
+(defvar mflex-root-dir (file-name-as-directory (expand-file-name ".."
mflex-test-dir)))
+
+
+;; Setup `load-path'
+(mapc (lambda (p) (add-to-list 'load-path p))
+ (list mflex-test-dir
+ mflex-root-dir))
+
+
+;; Use ERT from github when this Emacs does not have it
+(unless (locate-library "ert")
+ (add-to-list
+ 'load-path
+ (mflex-test-join-path mflex-root-dir "lib" "ert" "lisp" "emacs-lisp"))
+ (require 'ert-batch)
+ (require 'ert-ui))
+
+
+;; Load tests
+(load "mflex-test")
+
+
+;; Run tests
+(if noninteractive
+ (ert-run-tests-batch-and-exit)
+ (ert t))
- [nongnu] branch elpa/flx created (now 7b44a5abb2), ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 331ef6f109 001/182: first commit,
ELPA Syncer <=
- [nongnu] elpa/flx 2348893f90 012/182: flx-ido always use filename cache, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 387d1ee048 008/182: update ido implementation with ido demo, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 47ef1bf377 006/182: update license, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 9fec96087b 010/182: fix sort modifying list by side-effect bug, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx d295ba6a2f 007/182: add test list, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx b1702e2aa1 054/182: Add colon to non-word characters., ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 5a23bc7da3 003/182: update tests, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 64b8e0f934 027/182: work around ido bug 10994, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 8605b4b421 026/182: don't do caching when reading file names, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 8849b39816 066/182: Make flx-capital-p behave correctly for non-latin words, ELPA Syncer, 2022/12/13