From dbe6b10b5fdd42cfcbe9cb181980954d2e535a57 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 13 Aug 2017 14:11:29 -0700 Subject: [PATCH] =?UTF-8?q?=E2=80=9Cleniency,=20always=20leniency=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- txexpr/base.rkt | 20 +++++++++----------- txexpr/tests.rkt | 2 ++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index 64a4a68..cf25b78 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -1,5 +1,5 @@ #lang racket/base -(require sugar/define racket/string racket/list xml) +(require sugar/define sugar/coerce racket/string racket/list xml) (provide cdata? cdata valid-char? xexpr->string xexpr?) ; from xml (provide empty) ; from racket/list @@ -65,7 +65,7 @@ (define+provide+safe (can-be-txexpr-attr-key? x) predicate/c - (or (symbol? x) (string? x))) + (symbolish? x)) (define+provide+safe (txexpr-attr-value? x) @@ -75,7 +75,7 @@ (define+provide+safe (can-be-txexpr-attr-value? x) predicate/c - (or (symbol? x) (string? x))) + (stringish? x)) (define-syntax-rule (define-plural plural-id pred) @@ -206,18 +206,16 @@ ;; helpers. we are getting a string or symbol (define+provide+safe (->txexpr-attr-key x) (can-be-txexpr-attr-key? . -> . txexpr-attr-key?) - (cond - [(symbol? x) x] - [(string? x) (string->symbol x)] - [else (raise-argument-error '->txexpr-attr-key "can-be-txexpr-attr-key?" x)])) + (unless (can-be-txexpr-attr-key? x) + (raise-argument-error '->txexpr-attr-key "can-be-txexpr-attr-key?" x)) + (->symbol x)) (define+provide+safe (->txexpr-attr-value x) (can-be-txexpr-attr-value? . -> . txexpr-attr-value?) - (cond - [(string? x) x] - [(symbol? x) (symbol->string x)] - [else (raise-argument-error '->txexpr-attr-value "can-be-txexpr-attr-value?" x)])) + (unless (can-be-txexpr-attr-value? x) + (raise-argument-error '->txexpr-attr-value "can-be-txexpr-attr-value?" x)) + (->string x)) (define identity (λ (x) x)) diff --git a/txexpr/tests.rkt b/txexpr/tests.rkt index 56fe103..bd3dfc8 100644 --- a/txexpr/tests.rkt +++ b/txexpr/tests.rkt @@ -121,9 +121,11 @@ (check-equal? (->txexpr-attr-key "foo") 'foo) (check-equal? (->txexpr-attr-key 'foo) 'foo) + (check-equal? (->txexpr-attr-key (string->path "foo")) 'foo) (check-equal? (->txexpr-attr-value "foo") "foo") (check-equal? (->txexpr-attr-value 'foo) "foo") + (check-equal? (->txexpr-attr-value (string->path "foo")) "foo") (check-equal? (attrs->hash '((foo "bar"))) '#hasheq((foo . "bar"))) (check-equal? (attrs->hash '((foo "bar") (foo "fraw"))) '#hasheq((foo . "bar")))