gauche.test の件

shiro さんからコメント頂いた。ありがとうございます。曰く、

testのnameについてはどっかで書いたような気がしてたんですが、今見たらマニュアルには書いてませんでしたね。基本、後から照合できるなら何でも良いかと思います。

マクロなんだからテストすべき式をそのまま表示したらどうか、という意見もあるのですが、gauche.testではtest*をだらだら並べる形式よりも、「組み合わせを総当たりするような手続きを書いて漏れなくテストする」という方向を推奨したいという考えがあります。例えば ext/charconv/test.scm など。そうした場合、test*の引数そのものを表示してもほとんど意味がないので。

今回の例なら手軽には
(define (test-rember a lat expect)
(test* (format "rember ~s ~s" a lat) expect (rember a lat)))
などとするのが良いかもしれません。

とのこと。
ちなみに Gauche-0.9 の ext/charconv/test.scm では map-test という手続きが define されてたりしてますね。

(define (map-test tester file from-codes to-codes)
  (for-each (lambda (from)
              (for-each (lambda (to) (tester file from to)) to-codes))
            from-codes))

たしかに map 使うのはありかも。test-rember も使いたいスね。以下なソレをでっち上げてみました。

(test-start "chapter 3")
(test-section "rember")

(define (test-rember a lat expect)
  (test* (format "rember ~s ~s" a lat) expect (rember a lat)))
(define (map-test tester l)
  (for-each (lambda (l)
	       (tester (car l) (cadr l) (caddr l)))
	     l))

(map-test test-rember
	  '((mint (lamb chops and mint jelly) (lamb chops and jelly))
	    (mint (lamb chops and mint flavored mint jelly) (lamb chops and flavored mint jelly))
	    (toast (bacon lettuce and tomato) (bacon lettuce and tomato))
	    (cup (coffee cup tea cup and hick cup) (coffee tea cup and hick cup))
	    (bacon (bacon lettuce and tomato) (lettuce and tomato))
	    (and (bacon lettuce and tomato) (bacon lettuce tomato))
	    (sauce (soy sauce and tomato sauce) (soy and tomato sauce))))

実行してみたら以下。

Testing chapter 3 =============================================================
<rember>-----------------------------------------------------------------------
test rember mint (lamb chops and mint jelly), expects (lamb chops and jelly) ==> ok
test rember mint (lamb chops and mint flavored mint jelly), expects (lamb chops and flavored mint jelly) ==> ok
test rember toast (bacon lettuce and tomato), expects (bacon lettuce and tomato) ==> ok
test rember cup (coffee cup tea cup and hick cup), expects (coffee tea cup and hick cup) ==> ok
test rember bacon (bacon lettuce and tomato), expects (lettuce and tomato) ==> ok
test rember and (bacon lettuce and tomato), expects (bacon lettuce tomato) ==> ok
test rember sauce (soy sauce and tomato sauce), expects (soy and tomato sauce) ==> ok

なんか括弧が足んないw
test-rember をこうすりゃ良いのかな。

(define (test-rember a lat expect)
  (test* (format "(rember ~s ~s)" a lat) expect (rember a lat)))

ちょっとむふふ的アレですな。

別途

ext/charconv/test.scm の中身を見たり実行してみたりする方向で。