import Sequence from '../../dataTypes/Sequence';
import DoubleValue from '../../dataTypes/DoubleValue';
import Selector from '../../Selector';

/**
 * @extends {Selector}
 */
class Unary extends Selector {
	/**
	 * Positivese or negativise a value: +1 = 1, -1 = 0 - 1, -1 + 2 = 1, --1 = 1, etc
	 * @param  {string}    kind       Either + or -
	 * @param  {Selector}  valueExpr  The selector evaluating to the value to process
	 */
	constructor (kind, valueExpr) {
		super(valueExpr.specificity, Selector.RESULT_ORDERINGS.SORTED);
		this._valueExpr = valueExpr;

		this._kind = kind;
	}

	evaluate (dynamicContext) {
		var valueSequence = this._valueExpr.evaluate(dynamicContext);
		if (valueSequence.isEmpty()) {
			return Sequence.singleton(new DoubleValue(Number.NaN));
		}

		var value = valueSequence.value[0].atomize();
		if (value.instanceOfType('xs:integer') ||
			value.instanceOfType('xs:decimal') ||
			value.instanceOfType('xs:double') ||
			value.instanceOfType('xs:float')) {

			if (this._kind === '-') {
				// TODO: clone
				value.value = -value.value;
			}
			return Sequence.singleton(value);
		}

		return Sequence.singleton(new DoubleValue(Number.NaN));
	}
}

export default Unary;

@@ -54,47 +54,214 @@
 rt D
-oubleValue from '../../dataTypes/Double
+ecimalValue from '../../dataTypes/DecimalValue';%0Aimport DoubleValue from '../../dataTypes/DoubleValue';%0Aimport FloatValue from '../../dataTypes/FloatValue';%0Aimport IntegerValue from '../../dataTypes/Integer
 Valu
@@ -985,16 +985,45 @@
 mize();%0A
+%09%09if (this._kind === '+') %7B%0A%09
 %09%09if (va
@@ -1049,21 +1049,23 @@
 'xs:
-integer
+decimal
 ') %7C%7C%0A
+%09%09
 %09%09%09v
@@ -1089,28 +1089,29 @@
 pe('xs:d
-ecimal
+ouble
 ') %7C%7C%0A
+%09%09
 %09%09%09value
@@ -1130,28 +1130,29 @@
 ype('xs:
-double
+float
 ') %7C%7C%0A
+%09%09
 %09%09%09value
@@ -1175,86 +1175,425 @@
 'xs:
-float')) %7B%0A%0A%09%09%09if (this._kind === '-') %7B%0A%09%09%09%09// TODO: clone%0A%09%09%09%09value.value = 
+integer')) %7B%0A%09%09%09%09return valueSequence;%0A%09%09%09%7D%0A%0A%09%09%09return Sequence.singleton(new DoubleValue(Number.NaN));%0A%09%09%7D%0A%0A%09%09if (value.instanceOfType('xs:integer')) %7B%0A%09%09%09return Sequence.singleton(new IntegerValue(-value.value));%0A%09%09%7D%0A%09%09if (value.instanceOfType('xs:decimal')) %7B%0A%09%09%09return Sequence.singleton(new DecimalValue(-value.value));%0A%09%09%7D%0A%09%09if (value.instanceOfType('xs:double')) %7B%0A%09%09%09return Sequence.singleton(new DoubleValue(
 -val
@@ -1604,49 +1604,115 @@
 alue
+))
 ;%0A
-%09
 %09%09%7D%0A%09%09
-%09return Sequence.singleton(value
+if (value.instanceOfType('xs:float')) %7B%0A%09%09%09return Sequence.singleton(new FloatValue(-value.value)
 );%0A%09

Fix bug in Unary opartor