Commits

David Krentzlin committed 10fae63

added test for match-string matcher

Comments (0)

Files changed (3)

missbehave-matchers.scm

   match-arguments
   make-call-matcher
   message-from-predicate-form
-  be close-to any-of none-of
+  be is close-to any-of none-of
   list-including
   have-type
   match-string
+  matches-string
   call
+  calls
   raise
   make-error-matcher
   )
    (sprintf "Expected ~A to be called with ~A, but was called with ~A" proc args arguments)))
 
 
+(define-syntax calls
+  (syntax-rules (once twice times time never with)
+    ((_ argument +more-arguments ...)
+     (call arguments +more-arguments ...))))
+
 (define-syntax call
   (syntax-rules (once twice times time never with)
     ((_ proc (with arg arg+ ...))
                (sprintf "Expected ~A not to match ~S" form what)
                (sprintf "Expected ~A to match ~S" form what)))))))
 
+(define matches-string match-string)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Be
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
             (for-each (cut printf "~A " <>) (cdr form)))))
       form))
 
+(define-syntax is
+  (syntax-rules (a an true false)
+    ((_ arguments +more-arguments ...)
+     (be arguments +more-arguments ...))))
+
 (define-syntax be
   (syntax-rules (a an true false)
     ((_ true)
              (list value more-values ...)))))))))
 
 
-
-
 (define-syntax have-type
   (lambda (form rename env)
     (let* ((type (cadr form))
          (lambda (exit)
            (handle-exceptions exn
                (begin
-                (signal exn)
+                 ;(signal exn)
                  (fail-current-example-with! (sprintf "Error: ~S~%~A"
                                                       ((condition-property-accessor 'exn 'message) exn)
                                                       (format-condition-properties exn '(message call-chain)))))
 (test-group "Expectations"
 
 
-
     (test "Minimal expecations"
           #t
           (example-failed?
       ;;    #f
         ;; (example-failed? (run-example (it "succeeds" (expect #t => #t)))))
     
-    (test "multiple tests per expectation"
-          #f
-          (example-failed?
-           (run-example
-            (it "should succeed"
-              (expect
-                  ((#f (be false))
-                    (#t (be true))
-                    (1  (be a number))))))))
+    ;; (test "multiple tests per expectation"
+    ;;       #f
+    ;;       (example-failed?
+    ;;        (run-example
+    ;;         (it "should succeed"
+    ;;           (expect
+    ;;               ((#f (be false))
+    ;;                 (#t (be true))
+    ;;                 (1  (be a number))))))))
     )
 
 
             (test-matcher "(be operator other)" (be > 0) 3 -1 "Expected -1 to be > 0")
             (test-matcher "(be a type)" (be a string) "test" (list) "Expected () to be a string"))
 
+(test-group "Is matchers"
+            (test-matcher "(is true)" (is true) #t #f "Expected #f to be #t")
+            (test-matcher "(is false)" (is false) #f #t "Expected #t to be #f")
+            (test-matcher "(is pred?)" (is null?) '() '(1) "Expected (1) to be null?")
+            (test-matcher "(is value)" (is "test") "test" "pie" "Expected \"pie\" to be \"test\"")
+            (test-matcher "(is operator other)" (is > 0) 3 -1 "Expected -1 to be > 0")
+            (test-matcher "(is a type)" (is a string) "test" (list) "Expected () to be a string"))
+
 (test-group "Be matcher helpers"
             (test-matcher "(be (close 1))" (be (close-to 1)) 1 2 "Expected 2 to be close to 1 ")
             (test-matcher "(be (close 1 delta: 0.1))" (be (close-to 1 delta: 0.1)) 0.9 2 "Expected 2 to be close to 1 delta: 0.1 ")
 
             (test-matcher "(be (list-including 1 2)" (be (list-including 1 2)) (list 1 2 3) (list) "Expected () to be list including 1 2 "))
 
-(test-group "Match-string")
+(test-group "Match-string"
+            (test-matcher "(match-string)" (match-string "test") '(: (+ any))'(: (+ digit)) "Expected (quote (: (+ digit))) to match \"test\""))
 
 (test-group "Have-matcher")