#lang scheme
(require "../main.rkt"
(except-in rackunit foldts))
(define (read-from-string str)
(ssax:xml->sxml (open-input-string str) `()))
(define (read-from-string/ns str ns)
(ssax:xml->sxml (open-input-string str) ns))
(check-equal? (read-from-string "<a />")
`(*TOP* (a)))
(check-equal? (read-from-string "<a xmlns=\"gooble\" />")
`(*TOP* (gooble:a)))
(check-equal? (read-from-string "<a xmlns=\"gooble\" ><b /></a>")
`(*TOP* (gooble:a (gooble:b))))
(check-equal? (read-from-string "<a xmlns:ns=\"gooble\" ><b /></a>")
`(*TOP* (a (b))))
(check-equal? (read-from-string "<ns:a xmlns:ns=\"gooble\" ><ns:b /></ns:a>")
`(*TOP* (gooble:a (gooble:b))))
(check-equal? (read-from-string "<ns:a xmlns:ns=\"gooble\" ><b /></ns:a>")
`(*TOP* (gooble:a (b))))
(check-equal? (read-from-string/ns "<ns:a xmlns:ns=\"gooble\" ><b /></ns:a>"
`((g . "gooble")))
`(*TOP* (@ (*NAMESPACES* (g "gooble")))
(g:a (b))))
(check-equal? (read-from-string "<a></a>")
`(*TOP* (a)))
(check-equal? (read-from-string "<a />")
`(*TOP* (a)))
(check-equal? (read-from-string "<a>
</a>")
`(*TOP* (a)))
(check-equal? (read-from-string "<a>
t
</a>")
`(*TOP* (a "\nt\n")))
(check-exn (lambda (exn) #t)
(lambda () (ssax:xml->sxml (open-input-string "") `())))
(check-equal? (srl:sxml->xml `(*TOP* (p))) "<p />")