Skip to content

Commit

Permalink
hen-list-tubes-watched should return list instead of alist
Browse files Browse the repository at this point in the history
Updated test case to reflect new semantics.

git-svn-id: https://code.call-cc.org/svn/chicken-eggs/release/4/hen/trunk@23233 fca3e652-9b03-0410-8d7b-ac86a6ce46c4
  • Loading branch information
joseph.gay committed Mar 24, 2011
1 parent 83f9dad commit 74dd4ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions hen.scm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

(import scheme chicken)

(use chicken data-structures extras lambda+ list-utils miscmacros regex srfi-1 tcp6)
(use chicken data-structures extras lambda+ list-utils miscmacros regex srfi-1 srfi-13 tcp6)

(import-for-syntax chicken)

Expand Down Expand Up @@ -121,8 +121,8 @@
(define-hen-command command-2 (arg-2 ...) ...)
...)]))

(define (read-stats res tcp-in)
(if* (second-match "^OK (\\d+)$" res) (parse-yaml (read-string (string->number it) tcp-in))))
(define (read-stats res tcp-in #!optional (parser parse-yaml-alist))
(if* (second-match "^OK (\\d+)$" res) (parser (read-string (string->number it) tcp-in))))

(define-hen-command-list
[use (tube)]
Expand All @@ -142,7 +142,7 @@
[stats () (read-stats res tcp-in)]
[list-tubes () (read-stats res tcp-in)]
[list-tube-used ()]
[list-tubes-watched () (read-stats res tcp-in)]
[list-tubes-watched () (read-stats res tcp-in parse-yaml-list)]
[quit ()]
[pause-tube (tube delay)])

Expand Down
5 changes: 4 additions & 1 deletion hen.utils.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
#f))

;; this parses beanstalk's yaml, nothing generic intended
(define (parse-yaml yaml)
(define (parse-yaml-alist yaml)
(plist->alist (flatten (cdr (filter-map (lambda (s) (string-split s ": ")) (string-split yaml "\n"))))))

(define (parse-yaml-list yaml)
(cdr (map (cut string-drop <> 2) (string-split yaml "\n"))))
2 changes: 1 addition & 1 deletion tests/run.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(test-begin "all commands with dummy data")

(test "zero param commands"
'("OK 13" "OK 13" "OK 13" (("test" . "data")) "OK 13" (("test" . "data")) (("test" . "data")) "OK 13")
'("OK 13" "OK 13" "OK 13" (("test" . "data")) "OK 13" (("test" . "data")) ("st:data") "OK 13")
(map (lambda (p) (p #:tcp-in (open-input-string "OK 13\r\n---\ntest:data\r\n") #:tcp-out (open-output-string))) command-list-0))

(test "single param commands"
Expand Down

0 comments on commit 74dd4ff

Please sign in to comment.