srfi-37.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;;; srfi-37.test --- Test suite for SRFI 37 -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This program is free software; you can redistribute it and/or modify
  6. ;;;; it under the terms of the GNU General Public License as published by
  7. ;;;; the Free Software Foundation; either version 2, or (at your option)
  8. ;;;; any later version.
  9. ;;;;
  10. ;;;; This program is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;;; GNU General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU General Public License
  16. ;;;; along with this software; see the file COPYING. If not, write to
  17. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. ;;;; Boston, MA 02110-1301 USA
  19. (define-module (test-srfi-37)
  20. #:use-module (test-suite lib)
  21. #:use-module (srfi srfi-37))
  22. (with-test-prefix "SRFI-37"
  23. (pass-if "empty calls with count-modified seeds"
  24. (equal? (list 21 42)
  25. (call-with-values
  26. (lambda ()
  27. (args-fold '("1" "3" "4") '()
  28. (lambda (opt name arg seed seed2)
  29. (values 1 2))
  30. (lambda (op seed seed2)
  31. (values (1+ seed) (+ 2 seed2)))
  32. 18 36))
  33. list)))
  34. (pass-if "short opt params"
  35. (let ((a-set #f) (b-set #f) (c-val #f) (d-val #f) (no-fail #t) (no-operands #t))
  36. (args-fold '("-abcdoit" "-ad" "whatev")
  37. (list (option '(#\a) #f #f (lambda (opt name arg)
  38. (set! a-set #t)
  39. (values)))
  40. (option '(#\b) #f #f (lambda (opt name arg)
  41. (set! b-set #t)
  42. (values)))
  43. (option '("cdoit" #\c) #f #t
  44. (lambda (opt name arg)
  45. (set! c-val arg)
  46. (values)))
  47. (option '(#\d) #f #t
  48. (lambda (opt name arg)
  49. (set! d-val arg)
  50. (values))))
  51. (lambda (opt name arg) (set! no-fail #f) (values))
  52. (lambda (oper) (set! no-operands #f) (values)))
  53. (equal? '(#t #t "doit" "whatev" #t #t)
  54. (list a-set b-set c-val d-val no-fail no-operands))))
  55. (pass-if "single unrecognized long-opt"
  56. (equal? "fake"
  57. (args-fold '("--fake" "-i2")
  58. (list (option '(#\i) #t #f
  59. (lambda (opt name arg k) k)))
  60. (lambda (opt name arg k) name)
  61. (lambda (operand k) #f)
  62. #f)))
  63. (pass-if "long req'd/optional"
  64. (equal? '(#f "bsquare" "apple")
  65. (args-fold '("--x=pple" "--y=square" "--y")
  66. (list (option '("x") #t #f
  67. (lambda (opt name arg k)
  68. (cons (string-append "a" arg) k)))
  69. (option '("y") #f #t
  70. (lambda (opt name arg k)
  71. (cons (if arg
  72. (string-append "b" arg)
  73. #f) k))))
  74. (lambda (opt name arg k) #f)
  75. (lambda (opt name arg k) #f)
  76. '())))
  77. ;; this matches behavior of getopt_long in libc 2.4
  78. (pass-if "short options absorb special markers in the next arg"
  79. (let ((arg-proc (lambda (opt name arg k)
  80. (acons name arg k))))
  81. (equal? '((#\y . "-z") (#\x . "--") (#\z . #f))
  82. (args-fold '("-zx" "--" "-y" "-z" "--")
  83. (list (option '(#\x) #f #t arg-proc)
  84. (option '(#\z) #f #f arg-proc)
  85. (option '(#\y) #t #f arg-proc))
  86. (lambda (opt name arg k) #f)
  87. (lambda (opt name arg k) #f)
  88. '()))))
  89. (pass-if "short options without arguments"
  90. ;; In Guile 1.8.4 and earlier, using short names of argument-less options
  91. ;; would lead to a stack overflow.
  92. (let ((arg-proc (lambda (opt name arg k)
  93. (acons name arg k))))
  94. (equal? '((#\x . #f))
  95. (args-fold '("-x")
  96. (list (option '(#\x) #f #f arg-proc))
  97. (lambda (opt name arg k) #f)
  98. (lambda (opt name arg k) #f)
  99. '()))))
  100. )