### ----------------------------------------------------
### -- SQL::Builder
### -- Licenses: Artistic-2.0
### -- Authors: Adrian Kreher
### -- File: t/80-clone.rakutest
### ----------------------------------------------------
use Test;
use SQL::Builder;

my $sql = SQL::Builder.new;

subtest 'clone', {
    my $q = $sql.from('table').select('foo');
    my $q2 = $q.clone.select('bar');

    given $q.build {
        is .sql, 'SELECT "foo" FROM "table"';
    }

    given $q2.build {
        is .sql, 'SELECT "bar" FROM "table"';
    }

};

subtest 'clone with join', {
    my $q = $sql.from('table').select('foo').join('table2', :using<id>);
    my $q2 = $q.clone;
    $q2.join($q, :using<id>);

    given $q2.build {
        is .sql, '
            SELECT "foo" FROM "table"
            JOIN "table2" USING ("id")
            JOIN (SELECT "foo" FROM "table" JOIN "table2" USING ("id"))
            USING ("id")
        '.subst(:g, /\s+/, ' ').trim;
    }
};

done-testing;


