;;; x120 --- test ‘(... cookies) simple-parse-cookies’

;; Copyright (C) 2012 Thien-Thi Nguyen
;;
;; This file is part of Guile-WWW.
;;
;; Guile-WWW is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; Guile-WWW is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public
;; License along with Guile-WWW; see the file COPYING.  If not,
;; write to the Free Software Foundation, Inc., 51 Franklin Street,
;; Fifth Floor, Boston, MA  02110-1301  USA

(use-modules
 (www server-utils cookies))

(define (die s . args)
  (apply fse (string-append s "~%") args)
  (exit #f))

(define (try string sep good)
  (let ((real (simple-parse-cookies string sep)))
    (vfso "real: ~S~%" real)
    (or (equal? good real)
        (die "misparse: ~S" real))))

(define COOKIE "abc=def; z=z, ans=\"42\", abc=xyz")

(try COOKIE #f
     '(("abc" . "def; z=z")
       ("ans" . "\"42\"")
       ("abc" . "xyz")))

(try COOKIE #\;
     '(("abc" . "def")
       ("z" . "z, ans=\"42\", abc=xyz")))

(try "s_pers=%20s_getnr%3D1332412041588-Repeat%7C139548404158%3B%20s_nrgvo%3DRepeat%7C1395484041589%3B;
__utma=111872281.756735707.1329594934.1329594934.1332412041.2;
__utmz=111872281.1329594934.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
__utmv=111872281.|3=User=A=1^4=JoinedOn=0=1; __qseg=Q_D|Q_T;
__qca=P0-85920803-1329594940040;
csrftoken=3f48bed5bd44d9ae67c0f23ec1a3424c;
sessionid=e91499ddfb07f664f929ab3a79672015;
__utmb=111872281.2.10.1332412041; __utmc=111872281;
s_sess=%20s_cc%3Dtrue%3B%20s_sq%3D%3B%20s_sv_sid%3D1228563854531%3B;
br_fp=0a0510d64037f1db682cd5874d21b485c957f444"
     #\;
     '(("s_pers" . "%20s_getnr%3D1332412041588-Repeat%7C139548404158%3B%20s_nrgvo%3DRepeat%7C1395484041589%3B")
       ("__utma" . "111872281.756735707.1329594934.1329594934.1332412041.2")
       ("__utmz" . "111872281.1329594934.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)")
       ("__utmv" . "111872281.|3=User=A=1^4=JoinedOn=0=1")
       ("__qseg" . "Q_D|Q_T")
       ("__qca" . "P0-85920803-1329594940040")
       ("csrftoken" . "3f48bed5bd44d9ae67c0f23ec1a3424c")
       ("sessionid" . "e91499ddfb07f664f929ab3a79672015")
       ("__utmb" . "111872281.2.10.1332412041")
       ("__utmc" . "111872281")
       ("s_sess" . "%20s_cc%3Dtrue%3B%20s_sq%3D%3B%20s_sv_sid%3D1228563854531%3B")
       ("br_fp" . "0a0510d64037f1db682cd5874d21b485c957f444")))

(exit #t)

;;; x120 ends here
