#!/bin/bash -eu

TAGCOLL=./tagcoll
DATA="${srcdir:-.}/test-data/"
TESTFILE=tagcoll-test.tmp

echo -n "Checking normal copy... "

echo -n "plain, "
$TAGCOLL copy $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection $TESTFILE

echo -n "remove-unfaceted, "
$TAGCOLL copy --remove-unfaceted $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-faceted $TESTFILE

echo -n "remove-tags, "
$TAGCOLL copy --remove-tags="!color::*" $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-colorsonly $TESTFILE

echo -n "patch, "
$TAGCOLL copy --patch=$DATA/test-collection-diffed $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-colorsonly $TESTFILE

echo -n "items, "
$TAGCOLL copy --items $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-items $TESTFILE

echo "OK."


echo -n "Checking reverse... "

echo -n "plain, "
$TAGCOLL reverse $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-reversed $TESTFILE

echo -n "double, "
$TAGCOLL reverse $DATA/test-collection | $TAGCOLL reverse > $TESTFILE
diff -q $DATA/test-collection $TESTFILE

echo "OK."


echo -n "Checking grep... "

echo -n "plain, "
$TAGCOLL grep 'color::red' $DATA/test-collection > $TESTFILE
diff -q $DATA/test-collection-grepped $TESTFILE

echo "OK."


echo -n "Checking diff... "

echo -n "plain, "
$TAGCOLL diff $DATA/test-collection $DATA/test-collection-colorsonly > $TESTFILE
diff -q $DATA/test-collection-diffed $TESTFILE

echo "OK."

rm $TESTFILE
