selector-test.ss
(module selector-test mzscheme
  
  (require (all-except (lib "list.ss" "srfi" "1") any)
           (lib "cut.ss" "srfi" "26"))
  
  (require (file "core.ss")
           (file "command.ss")
           (file "selector.ss")
           (file "test-base.ss"))
  
  ; Test suite -----------------------------------
  
  (define selector-tests
    (test-suite "selector.ss"
      
      #:before 
      (lambda ()
        (open/wait (lambda (request)
                     (send/suspend
                      (lambda (url)
                        `(html (head (title "Selector tests"))
                               (body (ul ([id "list1"])
                                         (li ([id "item1"]) "item1")
                                         (li ([id "item2"]) "item2"))
                                     (ul ([id "list2"])
                                         (li ([id "item3"]) "item3")
                                         (li ([id "item4"]) "item4"))
                                     (ul ([id "list3"])
                                         (li (a ([href "#"]) "link1"))
                                         (li (a ([href "#"]) (strong "link2")))
                                         (li (span "link3"))))))))))
        
      (test-case "node/document"
        (check-found (node/document)))
      
      (test-case "absolute node/id"
        (check-found (node/id "list1"))
        (check-found (node/id 'list2))
        (check-not-found (node/id "list4")))
      
      (test-case "absolute node/tag"
        (check-found (node/tag "ul"))
        (check-found (node/tag 'li))
        (check-not-found (node/tag "p")))
      
      (test-case "absolute node/xpath"
        (check-found (node/xpath "//li"))
        (check-found (node/xpath "//ul/descendant::li"))
        (check-not-found (node/xpath "//li/descendant::ul")))
      
      (test-case "relative node/id"
        (check-found (node/id (node/tag "ul") "item1"))
        (check-found (node/id (node/id "list1") "item1"))
        (check-not-found (node/id (node/id "list2") "item1")))
      
      (test-case "relative node/tag"
        (check-found (node/tag (node/tag "ul") "li"))
        (check-found (node/tag (node/id "list1") "li"))
        (check-not-found (node/tag (node/tag "ul") "p")))
      
      (test-case "relative node/xpath"
        (check-found (node/xpath (node/tag "ul") "descendant::text()[contains(., 'item1')]"))
        (check-found (node/xpath (node/id "list1") "descendant::text()[contains(., 'item1')]"))
        (check-not-found (node/xpath (node/id "list2") "descendant::text()[contains(., 'item1')]")))
      
      (test-case "node/link/text"
        (check-found (node/link/text "link1"))
        (check-found (node/link/text "link2"))
        (check-not-found (node/link/text "link3")))
      
      ))
      
  ; Provide statements ---------------------------
  
  (provide selector-tests)
  
  )