#!/usr/bin/env perl

# Copyright (c) 2014-2015 Christian Jaeger, copying@christianjaeger.ch
# This is free software. See the file COPYING.md that came bundled
# with this file.

use strict; use warnings; use warnings FATAL => 'uninitialized';

our ($mydir, $myname);
BEGIN {
    $0=~ /(.*?)([^\/]+)\z/s or die "?";
    ($mydir, $myname)=($1,$2);
}
use lib "$mydir/../../lib";

use Chj::TEST ":all";
use Chj::TEST
  use=> 'FP::Repl::Dependencies';
use PXML::XHTML ":all";
use PXML::Serialize "pxml_print_fragment_fast";
use FP::Lazy;
use FP::List;
use FP::Stream;
use FP::Array ":all"; # XXX inconsistency in export directives
use FP::PureArray;

TEST_STDOUT { pxml_print_fragment_fast
                ( A({href=>"hah"},
                    "Hello ",
                    I("World", B("!"))), *STDOUT{IO} ) }
  '<a href="hah">Hello <i>World<b>!</b></i></a>';

TEST { A({href=>"hah"},
         "Hello ",
         I("World", undef, B("!")),
         cons(" ", string_to_stream("You're great.")))->text }
  'Hello World! You\'re great.';

TEST { P(list)->string }
  '<p></p>';

TEST { P(list 1, 2, B(3))->string }
  '<p>12<b>3</b></p>';

TEST { P(stream 1, 2, lazy { B(3) })->string }
  '<p>12<b>3</b></p>';

TEST { P(array 1, 2, B(3))->string }
  '<p>12<b>3</b></p>';

TEST { P(purearray 1, 2, B(3))->string }
  '<p>12<b>3</b></p>';

TEST { P(cons "Hello", "World")->string }
  '<p>HelloWorld</p>';

TEST { P(cons I("Hello"), B(cons null, "World"))->string }
  '<p><i>Hello</i><b>World</b></p>';


use Chj::Backtrace;
use FP::Repl;

perhaps_run_tests(__PACKAGE__) or repl;

