### ----------------------------------------------------
### -- Elucid8::Build
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/100-SiteData-plugin.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use File::Directory::Tree;
use RakuDoc::To::HTML;

plan *;

my $html-instance = RakuDoc::To::HTML.new;
my $rdp := $html-instance.rdp;
my %d := $rdp.templates.data;
my $ast;
my @triples;
my %processed;
my %data;

lives-ok {
    require Elucid8::Plugin::HTML::SiteData;
    Elucid8::Plugin::HTML::SiteData.new.enable( $rdp );
}, 'SiteData plugin enables';
isa-ok %d<SiteData>, Associative, 'SiteData plugin config available';
my %lf := %d<SiteData>;

like $rdp.templates<heading>.source, / 'SiteData plugin' /, 'heading template installed';

$ast = q:to/SNIPPET/.AST;
    =begin rakudoc
    =TITLE First
    =SUBTITLE The first file
    
    =head1 First file first head
    
    Some text
    
    =head1 sub mover
    
    A routine in First
    
    =end rakudoc
    SNIPPET
# process AST but dump return value
sink $html-instance.render($ast, :!finalise );

$ast = q:to/SNIPPET/.AST;
    =begin rakudoc
    =TITLE Second
    =SUBTITLE Second file about class
    
    =head1 method mover
    
    This is in Class something.
    
    =head1 infix soft
    
    A soft infix syntax
    
    =end rakudoc
    SNIPPET

sink $html-instance.render($ast, :!finalise );
#for ^2 -> $p {
#    my $name = "Synthetic_$p";
#    with $pp {
#        .pod-file.name = $name;
#        .pod-file.path = "doc/sythn/p_$p\.rakudoc";
#        .process-pod( $=pod[$p] );
#        .file-wrap(:filename($name), :dir<html>, :ext<html> );
#        %processed{ $name } = .emit-and-renew-processed-state;
#    }
#}
#is +%processed.keys, 2, 'two files in processed';
#$pp.add-data('secondaries', %( :!hash-urls ) );
#lives-ok { @triples = &secondaries($pp,%processed, %(:no-status,) ) }, 'gen-secondaries lives';
#is @triples.elems,2, 'some secondaries generated';
#
#$ast = q:to/SNIPPET/.AST;
#    =begin rakudoc
#    =TITLE Difficult Heads
#    =SUBTITLE complex pod in headers
#
#    =head1 infix X<C«and»|Operators,and>
#
#    Header with Indexing in title
#
#    =head1 infix C«...»
#    X<|Infix operators,...>X<|Infix operators,...^>X<|Infix operators,^...>X<|Infix operators,^...^>
#    X<|Infix operators,…>X<|Infix operators,…^>X<|Infix operators,^…>X<|Infix operators,^…^>
#
#    header with zero indexing afterwards
#
#    =head2 method proc
#
#    header with just name
#
#    =end rakudoc
#    SNIPPET
#
#%processed = Empty;
#$pp .= new;
#$pp.templates( 't/test-temps.rakuon' );
#$pp.modify-templates( %config<template-raku> );
#$pp.add-data('secondaries', %( :!hash-urls ) );
#&namespace-check( $pp, {} );
#%data = $pp.get-data('heading');
#my $name = 'Complex_headers';
#with $pp {
#    .pod-file.name = $name;
#    .pod-file.path = "doc/sythn/p_3\.rakudoc";
#    .process-pod( $=pod[2] );
#    .file-wrap(:filename($name), :dir<html>, :ext<html> );
#    %processed{ $name } = .emit-and-renew-processed-state;
#}
#
#@triples = &secondaries($pp,%processed, %(:no-status,) );
## heading with proc is eaten by ...
#my @expected = <routine/and.html routine/....html>;
#is @triples.elems,@expected.elems, 'correct no secondaries generated';
#is @triples[0][0], any(@expected), 'got 1 right file';
#is @triples[1][0], any(@expected), 'got 2 right file';
#
#$ast = q:to/SNIPPET/.AST;
#    =begin rakudoc
#    =TITLE Syntax file Heads
#    =SUBTITLE headers that should generate C<syntax/file> files.
#
#    =head1 X<Classes|Syntax,class>
#
#    Classes are declared using the C<class> keyword, typically followed by a
#    name.
#
#
#    =head1 X<C<self>|Syntax,self>
#
#    Inside a method, the term C<self> is available and bound to the invocant
#
#    =head1 X<Multi-dispatch|Syntax,multi>
#
#    Raku allows for writing several routines with the same name but different
#    signatures.
#
#    =end rakudoc
#    SNIPPET
#
#%processed = Empty;
#$pp .= new;
#$pp.templates( 't/test-temps.rakuon' );
#$pp.modify-templates( %config<template-raku> );
#$pp.add-data('secondaries', %( :!hash-urls ) );
#&namespace-check( $pp, {} );
#%data = $pp.get-data('heading');
#$name = 'Syntax_headers';
#with $pp {
#    .pod-file.name = $name;
#    .pod-file.path = "doc/sythn/p_4\.rakudoc";
#    .process-pod( $=pod[3] );
#    .file-wrap(:filename($name), :dir<html>, :ext<html> );
#    %processed{ $name } = .emit-and-renew-processed-state;
#}
#
#@triples = &secondaries($pp,%processed, %(:no-status,) );
#@expected = <syntax/self.html syntax/class.html syntax/multi.html>;
#is @triples.elems,@expected.elems, 'correct syntax secondaries generated';
#is @triples[0][0], any(@expected), 'got 1 syntax file';
#is @triples[1][0], any(@expected), 'got 2 syntax file';
#is @triples[2][0], any(@expected), 'got 3 syntax file';
#
#%processed = Empty;
#$pp .= new;
#$pp.templates( 't/test-temps.rakuon' );
#$pp.modify-templates( %config<template-raku> );
#&namespace-check( $pp, {} );
#%data = $pp.get-data('heading');
#$name = 'Complex_headers_hashed';
#with $pp {
#    .pod-file.name = $name;
#    .pod-file.path = "doc/sythn/p_3\.rakudoc";
#    .process-pod( $=pod[2] );
#    .file-wrap(:filename($name), :dir<html>, :ext<html> );
#    %processed{ $name } = .emit-and-renew-processed-state;
#}
#
## generate hashed files
#@triples = &secondaries($pp,%processed, %(:no-status,) );
#@expected = <routine/and routine/...>.map( { 'hashed/' ~ nqp::sha1($_ ) ~ '.html' } ) ;
#@expected.push: 'assets/prettyurls';
#is @triples.elems,@expected.elems, 'correct no of hashed secondaries generated';
#is @triples[0][0], any(@expected), 'got 1 right file';
#is @triples[1][0], any(@expected), 'got 2 right file';
#is @triples[2][0], any(@expected), 'got 3 right file';
#
#&cleanup($pp, %(), %() );
#is 'html/routine'.IO.dir( test => *.ends-with('html') ), (), 'routine directory emptied';
#is 'html/syntax'.IO.dir( test => *.ends-with('html') ), (), 'syntax directory emptied';
#is 'html/hashed'.IO.dir( test => *.ends-with('html') ), (), 'syntax directory emptied';

done-testing;


