aboutsummaryrefslogtreecommitdiff
path: root/test/tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/tests.el')
-rw-r--r--test/tests.el68
1 files changed, 45 insertions, 23 deletions
diff --git a/test/tests.el b/test/tests.el
index e8452af..44b0de0 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -3,7 +3,22 @@
(mapatoms
(lambda (symbol)
(if (string-prefix-p "stack-" (symbol-name symbol))
- (unintern symbol)))))
+ (unintern symbol)))))
+
+(defun stack-test-sample-data (method &optional directory)
+ (with-current-buffer
+ (find-file-noselect
+ (concat "data-samples/"
+ (when directory (concat directory "/"))
+ method ".el"))
+ (eval (read (if (string-equal "" (buffer-string))
+ "'no-value"
+ (buffer-string))))))
+
+(setq stack-test-data-questions
+ (stack-test-sample-data "questions")
+ stack-test-data-sites
+ (stack-test-sample-data "sites"))
;;; Tests
@@ -26,30 +41,37 @@
(should-error
(stack-core-make-request "questions" '(()))))
-(ert-deftest test-data-filter-1 ()
- "Test the meta-convenience function -- flat structure"
+(ert-deftest test-tree-filter ()
+ "`stack-core-filter-data'"
+ ;; flat
(should
(equal
'((1 . t) (2 . [1 2]) (3))
- (stack-core-filter-data '((0 . 3)
- (1 . t)
- (a . five)
- (2 . [1 2])
- ("5" . bop)
- (3)
- (p . 4))
- '(1 2 3)))))
-
-(ert-deftest test-data-filter-2 ()
- "Test the meta-convenience function -- complex structure"
+ (stack-core-filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2])
+ ("5" . bop) (3) (p . 4))
+ '(1 2 3))))
+ ;; complex
+ (should
+ (equal
+ '((1 . [a b c])
+ (2 . [((a . 1) (c . 3))
+ ((a . 4) (c . 6))])
+ (3 . peach))
+ (stack-core-filter-data '((1 . [a b c])
+ (2 . [((a . 1) (b . 2) (c . 3))
+ ((a . 4) (b . 5) (c . 6))])
+ (3 . peach)
+ (4 . banana))
+ '(1 (2 a c) 3))))
+
+ ;; vector
(should
(equal
- '([()])
- (stack-core-filter-data '((0 . 3)
- (1 . t)
- (a . five)
- (2 . [1 2])
- ("5" . bop)
- (3)
- (p . 4))
- '(1 2 3)))))
+ [((1 . 2) (2 . 3) (3 . 4))
+ ((1 . a) (2 . b) (3 . c))
+ nil ((1 . alpha) (2 . beta))]
+ (stack-core-filter-data [((1 . 2) (2 . 3) (3 . 4))
+ ((1 . a) (2 . b) (3 . c) (5 . seven))
+ ((should-not-go))
+ ((1 . alpha) (2 . beta))]
+ '(1 2 3)))))