This repository has been archived by the owner on Feb 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
after a lot of work, added the parse function and test methods to Hound
- Loading branch information
joshua-choi
committed
Jan 14, 2010
1 parent
df1ad44
commit 1f33c2e
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns name.choi.joshua.fnparse.hound.test | ||
(:use name.choi.joshua.fnparse.hound clojure.test) | ||
(:require [clojure.contrib.str-utils2 :as str])) | ||
|
||
(defmethod assert-expr 'partial-match? | ||
[msg [_ input rule product consumed-tokens-num]] | ||
(let [input-count (count input)] | ||
`(letfn [(report-this# | ||
([kind# format-template# expected-arg# actual-arg# & other-args#] | ||
(report {:type kind#, :message ~msg, | ||
:expected (apply format format-template# | ||
expected-arg# other-args#), | ||
:actual (apply format format-template# | ||
actual-arg# other-args#)})) | ||
([kind#] (report {:type kind#, :message ~msg})))] | ||
(parse ~input ~rule | ||
(fn [actual-product# actual-remainder#] | ||
(let [actual-consumed-tokens-num# | ||
(- ~input-count (count actual-remainder#))] | ||
(if (not= actual-consumed-tokens-num# ~consumed-tokens-num) | ||
(report-this# :fail "%s tokens consumed" | ||
~consumed-tokens-num actual-consumed-tokens-num#) | ||
(if (not= actual-product# ~product) | ||
(report-this# :fail "a product of %s" | ||
~product actual-product#) | ||
(report-this# :pass))))) | ||
(fn [expectation#] | ||
(let [unexpected-token# (:unexpected-token expectation#)] | ||
(report-this# :fail "%s at position %s" | ||
(str/join " or " (:expected-rules expectation#)) | ||
(str "a token " unexpected-token# " (of the type " | ||
(pr-str (type unexpected-token#)) ")") | ||
(:position expectation#)))))))) | ||
|
||
(defmethod assert-expr 'full-match? | ||
[msg [_ input rule product]] | ||
(assert-expr msg | ||
(list 'partial-match? input rule product (count input)))) |