(util.ps) runlibfile

/test-case {                    % <str> test-case mark
    print (\n) print

    % (*) create a package dict to count the tests
    3 dict begin
    /.test-total-count 0 def
    /.test-failed-count 0 def
    /.test-current-object null def

    % (**) mark the beginning of test results on the stack
    mark
} def

/should {                       % <str> should
    /.test-current-object exch def
} def

/test-summary {	                % mark <any*> test-summary
    (\n) print
    (--------------------------------------------------\n) print
    .test-total-count 5 string cvs print ( tests, ) print
    .test-failed-count 5 string cvs print ( failed\n\n) print

    % (*) now we printed them, we don't need the counts any longer
    end

    % (**) release accumulated messages to stdout
    ] {
	dup type /stringtype eq {
	    print
	} {
	    ==only
	} ifelse
    } forall
} def

/assert-equal {                 % <str> <any> <any> assert-equal
    /expected exch def
    /actual exch def
    /spec exch def

    /.test-total-count inc
    expected actual eq {
        (.) print
    } {
        (F) print
        .test-current-object (\n)
        (  should ) spec (\n)
        (    expected: ) expected (\n)
        (    actual:   ) actual (\n)
        /.test-failed-count inc
    } ifelse
} bind def

(util.ps) runlibfile

/test-case {                    % <str> test-case mark
    print (\n) print

    % (*) create a package dict to count the tests
    3 dict begin
    /.test-total-count 0 def
    /.test-failed-count 0 def
    /.test-current-object null def

    % (**) mark the beginning of test results on the stack
    mark
} def

/should {                       % <str> should
    /.test-current-object exch def
} def

/test-summary {	                % mark <any*> test-summary
    (\n) print
    (--------------------------------------------------\n) print
    .test-total-count 5 string cvs print ( tests, ) print
    .test-failed-count 5 string cvs print ( failed\n\n) print

    % (*) now we printed them, we don't need the counts any longer
    end

    % (**) release accumulated messages to stdout
    ] {
	dup type /stringtype eq {
	    print
	} {
	    ==only
	} ifelse
    } forall
} def

/assert-equal {                 % <str> <any> <any> assert-equal
    /expected exch def
    /actual exch def
    /spec exch def

    expected actual eq {
        /.test-total-count inc
        (.) print
    } {
        (F) print
        .test-current-object (\n)
        (  should ) spec (\n)
        (    expected: ) expected (\n)
        (    actual:   ) actual (\n)
        /.test-total-count inc
        /.test-failed-count inc
    } ifelse
} bind def
