Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shave nst yak #8

Merged
merged 13 commits into from Oct 2, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions 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")))))))
13 changes: 7 additions & 6 deletions src/clcss.lisp
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions 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))


21 changes: 21 additions & 0 deletions 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)))

23 changes: 0 additions & 23 deletions tests/tests.lisp

This file was deleted.

41 changes: 41 additions & 0 deletions 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"))