/****************************************************************************
 * Copyright (C) 2015-2016 EPAM Systems
 * 
 * This file is part of Indigo-Node binding.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.md  included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

/* declaration of modules  */
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var local = path.join.bind(path, __dirname);

var indigo = require("../indigo-node/indigo");

var checkHasMatchMol = function (indigo, m, q) {
	q.aromatize();
	m.checkBadValence();
	m.checkBadValence();
	var matcher = indigo.substructureMatcher(m);
	assert(matcher.match(q) != null);
	
	var m2 = indigo.unserialize(m.serialize());
	var matcher2 = indigo.substructureMatcher(m2)
	assert(matcher2.match(q) != null);
	q.optimize();
	assert(matcher.match(q) != null);
	assert(matcher2.match(q) != null)
};

var checkHasMatch = function (indigo, targetName, queryName) {
	console.log(targetName + " " + queryName);
	var q = indigo.loadQueryMoleculeFromFile(local("../indigo-node/"+queryName));
	var m = indigo.loadMoleculeFromFile(local("../indigo-node/"+targetName));
	checkHasMatchMol(indigo, m, q);
};

console.log("***** Substructure with either and bidirectional mode *****");
indigo.setOption("stereochemistry-bidirectional-mode", true);
checkHasMatch(indigo, "molecules/either1.mol", "molecules/either1.mol");
checkHasMatch(indigo, "molecules/either1.mol", "molecules/either2.mol");
checkHasMatch(indigo, "molecules/either1.mol", "molecules/either1_query.mol");



@@ -1918,9 +1918,260 @@
 mol%22);%0A%0A
+var mol = indigo.loadMolecule('C1C=CC=CC=1');%0Amol.aromatize();%0Avar q = indigo.loadQueryMolecule(%22C:C:C%22);%0Avar m = indigo.substructureMatcher(mol).match(q);%0Aif (m === null)%0A%09console.log(%22not matched%22);%0Aelse%0A%09console.log(m.highlightedTarget().smiles());
 %0A

add UT: highlightedTarget :loadMolecule :aromatize :loadQueryMolecule :substructureMatcher :highlightedTarget