Skip to content

Loading…

Shave nst yak #8

Merged
merged 13 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 88 additions and 31 deletions.
  1. +7 −2 clcss-tests.asd
  2. +7 −6 src/clcss.lisp
  3. +12 −0 tests/groups.lisp
  4. +21 −0 tests/helpers.lisp
  5. +0 −23 tests/tests.lisp
  6. +41 −0 tests/tests/parse.lisp
View
9 clcss-tests.asd
@@ -1,8 +1,13 @@
;; -*- mode: Lisp; -*-
(asdf:defsystem #:clcss-tests
- :serial t
:depends-on (#:clcss
#:nst)
+
:components ((:module "tests"
:components ((:file "package")
- (:file "tests" :depends-on ("package"))))))
+
+ (:file "helpers" :depends-on ("package"))
+ (:file "groups" :depends-on ("package"))
+
+ (:module "tests" :depends-on ("helpers" "groups") :components
+ ((:file "parse")))))))
View
13 src/clcss.lisp
@@ -21,22 +21,23 @@
(defun transform-css-path (path)
(flet ((paren-syms (s)
"Replace all symbols as CSS sees them with (:word symbol) to separate compund statements"
- (ppcre:regex-replace-all "([\\w_-]+)" s
- "(:word \\1)"))
+ (ppcre:regex-replace-all "([\\w_-]+)" s
+ "(:word \\1)"))
(group-compound (s)
"Wrap groups of lists joined by a non-space into lists. e.g.:
(:word p)#(:word my-p) => (:compound (:word p)#(:word my-p))"
- (ppcre:regex-replace-all "(\\([^\\(]+?\\)[^\\w_-\\s]\\([^\\(]+?\\))+" s
+ (ppcre:regex-replace-all "(\\([^\\(]+?\\)[^\\w_\\s-]\\([^\\(]+?\\))+" s
"(:compound \\1)"))
+
(dot-to-bang (s)
"Convert . to ! for lazy parsing"
(ppcre:regex-replace-all "\\." s
"!")))
- (reduce #'(lambda (res proc) (funcall proc res))
- (list #'paren-syms #'group-compound #'dot-to-bang)
- :initial-value path)))
+ (reduce #'(lambda (res proc) (funcall proc res))
+ (list #'dot-to-bang #'paren-syms #'group-compound)
+ :initial-value path)))
(defun read-css (path)
View
12 tests/groups.lisp
@@ -0,0 +1,12 @@
+(in-package :clcss-tests)
+
+;; Groups
+(def-test-group parse-tests ()
+ (:documentation "Tests basics of CSS string parsing"))
+
+;; Root Group
+(def-test-group all-tests ()
+ (:documentation "Root of the test tree")
+ (:include-groups parse-tests))
+
+
View
21 tests/helpers.lisp
@@ -0,0 +1,21 @@
+(in-package :clcss-tests)
+
+;; Helpers
+(defgeneric is-word (form)
+ (:method ((form list))
+ (is-word (car form)))
+ (:method ((form symbol))
+ (equal form :word)))
+
+;; Criteria
+(def-criterion-alias (:is-word) '(:predicate is-word))
+
+(def-criterion-alias (:word value) `(:seq :is-word
+ (:equal ,value)))
+
+(def-criterion-alias (:id value) `(:seq (:equal :id)
+ (:word ,value)))
+
+(def-criterion-alias (:class value) `(:seq (:equal :class)
+ (:word ,value)))
+
View
23 tests/tests.lisp
@@ -1,23 +0,0 @@
-(in-package :clcss-tests)
-
-(defparameter *css-tests* `("h1" "div span" "div span p#poop" "ul#nav"
- "#my-id" ".my-class" "div#body" "div.my-class" ".indent p"))
-
-;; Suites
-(def-test-group parse-tests ()
- (:documentation "Tests basics of CSS string parsing"))
-
-;; Root
-(def-test-group all-tests ()
- (:documentation "Root of the test tree")
- (:include-groups parse-tests))
-
-
-;; Tests
-(def-test (can-parse-nothing-to-nothing :group parse-tests)
- (:not :true) (read-css ""))
-
-(def-test (can-parse-simple-element :group parse-tests)
- (:all (:apply caar (:equal :word))
- (:apply cadar (:equal :h1)))
- (read-css "h1"))
View
41 tests/tests/parse.lisp
@@ -0,0 +1,41 @@
+(in-package :clcss-tests)
+
+;; Old test data, using as reference
+;; TODO: Remove when cases are covered
+(defparameter *css-tests* `("h1" "div span" "div span p#poop" "ul#nav"
+ "#my-id" ".my-class" "div#body" "div.my-class" ".indent p"))
+
+;; Tests
+(def-test (can-parse-nothing-to-nothing :group parse-tests)
+ (:not :true)
+ (read-css ""))
+
+(def-test (can-parse-simple-element :group parse-tests)
+ (:seq (:word :h1))
+ (read-css "h1"))
+
+(def-test (can-parse-nested-elements :group parse-tests)
+ (:seq (:word :div)
+ (:word :span))
+ (read-css "div span"))
+
+(def-test (can-parse-compound-tag-with-id :group parse-tests)
+ (:seq (:seq (:equal :compound)
+ (:word :ul)
+ (:id :nav)))
+ (read-css "ul#nav"))
+
+(def-test (can-parse-just-id :group parse-tests)
+ (:seq (:id :my-id))
+ (read-css "#my-id"))
+
+(def-test (can-parse-just-class :group parse-tests)
+ (:seq (:class :my-class))
+ (read-css ".my-class"))
+
+(def-test (can-parse-tag-with-id-and-class :group parse-tests)
+ (:seq (:seq (:equal :compound)
+ (:word :div)
+ (:id :wrap)
+ (:class :main)))
+ (read-css "div#wrap.main"))
Something went wrong with that request. Please try again.