quixote
Version:
CSS unit and integration testing
48 lines (38 loc) • 1.22 kB
JavaScript
// Copyright (c) 2017 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
;
var ensure = require("../util/ensure.js");
var PositionDescriptor = require("./position_descriptor.js");
var Position = require("../values/position.js");
var X_DIMENSION = "x";
var Y_DIMENSION = "y";
var Me = module.exports = function AbsolutePosition(dimension, value) {
ensure.signature(arguments, [ String, Number ]);
this.should = this.createShould();
switch(dimension) {
case X_DIMENSION:
PositionDescriptor.x(this);
this._value = Position.x(value);
break;
case Y_DIMENSION:
PositionDescriptor.y(this);
this._value = Position.y(value);
break;
default: ensure.unreachable("Unknown dimension: " + dimension);
}
this._dimension = dimension;
};
PositionDescriptor.extend(Me);
Me.x = function(value) {
ensure.signature(arguments, [ Number ]);
return new Me(X_DIMENSION, value);
};
Me.y = function(value) {
ensure.signature(arguments, [ Number ]);
return new Me(Y_DIMENSION, value);
};
Me.prototype.value = function() {
return this._value;
};
Me.prototype.toString = function() {
return this._value + " " + this._dimension + "-coordinate";
};