You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pollen/tests/test-ptree.rkt

69 lines
2.4 KiB
Racket

11 years ago
#lang racket/base
(require rackunit)
(require "../ptree.rkt" "../world.rkt")
11 years ago
(check-false (pnode? "foo-bar"))
(check-false (pnode? "Foo_Bar_0123"))
11 years ago
(check-true (pnode? 'foo-bar))
11 years ago
(check-false (pnode? "foo-bar.p"))
(check-false (pnode? "/Users/MB/foo-bar"))
11 years ago
(check-false (pnode? #f))
(check-false (pnode? ""))
(check-false (pnode? " "))
(check-true (ptree? '(foo)))
(check-true (ptree? '(foo (hee))))
11 years ago
(check-true (ptree? '(foo (hee (uncle foo)))))
(check-false (ptree? '(foo (hee hee (uncle foo)))))
11 years ago
11 years ago
(define test-ptree-main `(ptree-main foo bar (one (two three))))
11 years ago
(define test-ptree (ptree-root->ptree test-ptree-main))
11 years ago
(check-equal? (parent 'three test-ptree) 'two)
(check-equal? (parent "three" test-ptree) 'two)
11 years ago
(check-false (parent #f test-ptree))
(check-false (parent 'nonexistent-name test-ptree))
11 years ago
(check-equal? (children 'one test-ptree) '(two))
(check-equal? (children 'two test-ptree) '(three))
11 years ago
(check-false (children 'three test-ptree))
(check-false (children #f test-ptree))
(check-false (children 'fooburger test-ptree))
11 years ago
(check-equal? (siblings 'one test-ptree) '(foo bar one))
(check-equal? (siblings 'foo test-ptree) '(foo bar one))
(check-equal? (siblings 'two test-ptree) '(two))
11 years ago
(check-false (siblings #f test-ptree))
(check-false (siblings 'invalid-key test-ptree))
11 years ago
(check-equal? (previous* 'one test-ptree) '(foo bar))
(check-equal? (previous* 'three test-ptree) '(foo bar one two))
(check-false (previous* 'foo test-ptree))
11 years ago
11 years ago
(check-equal? (previous 'one test-ptree) 'bar)
(check-equal? (previous 'three test-ptree) 'two)
11 years ago
(check-false (previous 'foo test-ptree))
11 years ago
(check-equal? (next 'foo test-ptree) 'bar)
(check-equal? (next 'one test-ptree) 'two)
11 years ago
(check-false (next 'three test-ptree))
11 years ago
(check-equal? (ptree->list test-ptree) '(foo bar one two three))
11 years ago
11 years ago
(let ([sample-main `(world:pollen-tree-root-name foo bar (one (two three)))])
11 years ago
(check-equal? (ptree-root->ptree sample-main)
11 years ago
`(world:pollen-tree-root-name foo bar (one (two three)))))
11 years ago
(define files '("foo.html" "bar.html" "bar.html.p" "zap.html" "zap.xml"))
(check-equal? (pnode->url/paths 'foo.html files) "foo.html")
(check-equal? (pnode->url/paths 'bar.html files) "bar.html")
;; (check-equal? (name->url 'zap files) 'error) ;; todo: how to test error?
(check-false (pnode->url/paths 'hee files))
11 years ago
(set! test-ptree-main `(,world:ptree-root-node foo bar (one (two three))))
11 years ago
(check-equal? (ptree-root->ptree test-ptree-main)
11 years ago
`(,world:ptree-root-node foo bar (one (two three))))