“leniency, always leniency”

pull/5/head
Matthew Butterick 7 years ago
parent c364b40bac
commit dbe6b10b5f

@ -1,5 +1,5 @@
#lang racket/base #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 cdata? cdata valid-char? xexpr->string xexpr?) ; from xml
(provide empty) ; from racket/list (provide empty) ; from racket/list
@ -65,7 +65,7 @@
(define+provide+safe (can-be-txexpr-attr-key? x) (define+provide+safe (can-be-txexpr-attr-key? x)
predicate/c predicate/c
(or (symbol? x) (string? x))) (symbolish? x))
(define+provide+safe (txexpr-attr-value? x) (define+provide+safe (txexpr-attr-value? x)
@ -75,7 +75,7 @@
(define+provide+safe (can-be-txexpr-attr-value? x) (define+provide+safe (can-be-txexpr-attr-value? x)
predicate/c predicate/c
(or (symbol? x) (string? x))) (stringish? x))
(define-syntax-rule (define-plural plural-id pred) (define-syntax-rule (define-plural plural-id pred)
@ -206,18 +206,16 @@
;; helpers. we are getting a string or symbol ;; helpers. we are getting a string or symbol
(define+provide+safe (->txexpr-attr-key x) (define+provide+safe (->txexpr-attr-key x)
(can-be-txexpr-attr-key? . -> . txexpr-attr-key?) (can-be-txexpr-attr-key? . -> . txexpr-attr-key?)
(cond (unless (can-be-txexpr-attr-key? x)
[(symbol? x) x] (raise-argument-error '->txexpr-attr-key "can-be-txexpr-attr-key?" x))
[(string? x) (string->symbol x)] (->symbol x))
[else (raise-argument-error '->txexpr-attr-key "can-be-txexpr-attr-key?" x)]))
(define+provide+safe (->txexpr-attr-value x) (define+provide+safe (->txexpr-attr-value x)
(can-be-txexpr-attr-value? . -> . txexpr-attr-value?) (can-be-txexpr-attr-value? . -> . txexpr-attr-value?)
(cond (unless (can-be-txexpr-attr-value? x)
[(string? x) x] (raise-argument-error '->txexpr-attr-value "can-be-txexpr-attr-value?" x))
[(symbol? x) (symbol->string x)] (->string x))
[else (raise-argument-error '->txexpr-attr-value "can-be-txexpr-attr-value?" x)]))
(define identity (λ (x) x)) (define identity (λ (x) x))

@ -121,9 +121,11 @@
(check-equal? (->txexpr-attr-key "foo") 'foo) (check-equal? (->txexpr-attr-key "foo") 'foo)
(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 '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"))) '#hasheq((foo . "bar")))
(check-equal? (attrs->hash '((foo "bar") (foo "fraw"))) '#hasheq((foo . "bar"))) (check-equal? (attrs->hash '((foo "bar") (foo "fraw"))) '#hasheq((foo . "bar")))

Loading…
Cancel
Save