private/tests/tests.ss
(module tests mzscheme
  (require (planet "test.ss" ("schematics" "schemeunit.plt" 1 1)))
  (require (planet "text-ui.ss" ("schematics" "schemeunit.plt" 1 1)))
  (require "../../pprint.ss")

  (define-syntax pprint
    (syntax-rules ()
      [(_ width e)
       (let ([s (open-output-string)])
         (parameterize ([current-page-width width]
                        [current-output-port s])
           (pretty-print e))
         (let ([result (get-output-string s)])
;           (printf "*** RESULT: ~v~n" result)
;           (printf "~a~n~n" result)
           result))]))

  (define (block header lines footer)
    (<$> (nest 4 (apply <$> header lines))
         footer))

  (define pretty-print-tests
    (make-test-suite
     "pretty-print tests"
     (make-test-case "softbreak breaks when it doesn't fit"
       (assert-equal? (pprint 10 (apply </> (map text '("david" "andrew" "herman"))))
                      "david\nandrew\nherman"))
     (make-test-case "hard break outside of group always breaks"
       (assert-equal? (pprint 100 (<$> (text "hello") (text "world")))
                      "hello\nworld"))
     (make-test-case "nest only affects future indentation inside scope"
       (assert-equal? (pprint 80 (<$> (nest 2 (<$> (text "hello") (text "world")))
                                      (text "!")))
                      "hello\n  world\n!"))
     (make-test-case "simple align example"
       (assert-equal? (pprint 80 (<+> (text "hi")
                                      (align (<$> (text "nice")
                                                  (text "world")))))
                      "hi nice\n   world"))
     (make-test-case "simple hang example"
       (assert-equal?
         (pprint 20 (hang 4 (fill-sep
                             (map text '("the" "hang" "combinator"
                                               "indents" "these"
                                               "words" "!")))))
         "the hang combinator\n    indents these\n    words !"))
     (make-test-case "simple indent example"
       (assert-equal? (pprint 20 (indent 4 (fill-sep (map text
                                                          '("the" "indent"
                                                            "combinator"
                                                            "indents" "these"
                                                            "words" "!")))))
                      "    the indent\n    combinator\n    indents these\n    words !"))
     (make-test-case "nesting affects future, not current indentation"
       (assert-equal? (pprint 80 (<$> (nest 4 (<$> (text "line 1")
                                                   (text "line 2")
                                                   (text "line 3")))
                                      (text "line 4")))
                      "line 1\n    line 2\n    line 3\nline 4"))
     ))

;  (pprint 80 (block (text "for (int i = 0; i < 10; i++) {")
;                    (list (text "print(i);")
;                          (text "print(\"hello\");")
;                          (block (text "if (i > 0) {")
;                                 (list (text "print(\"not first\");"))
;                                 (text "}"))
;                          (text "print(\"world\");"))
;                    (text "}")))

  (define all-tests
    (make-test-suite
     "all pprint.plt tests"
     pretty-print-tests
     ))

  (test/text-ui all-tests)


  (provide all-tests))