Move vector code out of the way
This commit is contained in:
979
old/test/spec/ol/expr/expression.test.js
Normal file
979
old/test/spec/ol/expr/expression.test.js
Normal file
@@ -0,0 +1,979 @@
|
||||
goog.provide('ol.test.expression');
|
||||
|
||||
|
||||
describe('ol.expr.parse()', function() {
|
||||
|
||||
it('parses a subset of ECMAScript 5.1 expressions', function() {
|
||||
var expr = ol.expr.parse('foo');
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
});
|
||||
|
||||
describe('11.1 - primary expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.1
|
||||
|
||||
it('parses identifier expressions', function() {
|
||||
var expr = ol.expr.parse('foo');
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
expect(expr.evaluate({foo: 'bar'})).to.be('bar');
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' foo ');
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
expect(expr.evaluate({foo: 'bar'})).to.be('bar');
|
||||
});
|
||||
|
||||
it('throws on invalid identifier expressions', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('3foo');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('f');
|
||||
expect(token.index).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses string literal expressions', function() {
|
||||
var expr = ol.expr.parse('"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be('foo');
|
||||
});
|
||||
|
||||
it('throws on unterminated string', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('"foo');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses numeric literal expressions', function() {
|
||||
var expr = ol.expr.parse('.42e+2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('throws on invalid number', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('.42eX');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('X');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses boolean literal expressions', function() {
|
||||
var expr = ol.expr.parse('false');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('parses null literal expressions', function() {
|
||||
var expr = ol.expr.parse('null');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.2 - left-hand-side expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
|
||||
|
||||
it('parses member expressions with dot notation', function() {
|
||||
var expr = ol.expr.parse('foo.bar.baz');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
var scope = {foo: {bar: {baz: 42}}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' foo . bar . baz ');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
var scope = {foo: {bar: {baz: 42}}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('throws on invalid member expression', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('foo.4bar');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('b');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses call expressions with literal arguments', function() {
|
||||
var expr = ol.expr.parse('foo(42, "bar")');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
var scope = {
|
||||
foo: function(num, str) {
|
||||
expect(num).to.be(42);
|
||||
expect(str).to.be('bar');
|
||||
return str + num;
|
||||
}
|
||||
};
|
||||
expect(expr.evaluate(scope)).to.be('bar42');
|
||||
});
|
||||
|
||||
it('throws on calls with unterminated arguments', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('foo(42,)');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be(')');
|
||||
expect(token.index).to.be(7);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.3 - postfix expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.3
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
|
||||
describe('11.4 - unary operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.4
|
||||
|
||||
it('parses logical not operator', function() {
|
||||
var expr = ol.expr.parse('!foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: ''})).to.be(true);
|
||||
expect(expr.evaluate({foo: 'foo'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' ! foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false})).to.be(true);
|
||||
});
|
||||
|
||||
it('parses not preceeding call expression', function() {
|
||||
var lib = {
|
||||
foo: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('!foo()');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate(null, lib)).to.be(false);
|
||||
});
|
||||
|
||||
it('parses not in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(!bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: true}, lib)).to.be(false);
|
||||
expect(expr.evaluate({bar: false}, lib)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.5 - multiplicitave operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.5
|
||||
|
||||
it('parses * operator', function() {
|
||||
var expr = ol.expr.parse('foo*bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(200);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with *', function() {
|
||||
var expr = ol.expr.parse(' foo * bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15, bar: 2})).to.be(30);
|
||||
});
|
||||
|
||||
it('parses / operator', function() {
|
||||
var expr = ol.expr.parse('foo/12');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10})).to.be(10 / 12);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with /', function() {
|
||||
var expr = ol.expr.parse(' 4 / bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({bar: 3})).to.be(4 / 3);
|
||||
});
|
||||
|
||||
it('parses % operator', function() {
|
||||
var expr = ol.expr.parse('12%foo');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10})).to.be(2);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with %', function() {
|
||||
var expr = ol.expr.parse(' 4 %bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({bar: 3})).to.be(1);
|
||||
});
|
||||
|
||||
it('parses * in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(2 * bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: 3}, lib)).to.be(6);
|
||||
expect(expr.evaluate({bar: 4}, lib)).to.be(8);
|
||||
});
|
||||
|
||||
it('evaluates left to right for equal precedence', function() {
|
||||
var expr = ol.expr.parse('2 / 4 * 20 % 15');
|
||||
expect(expr.evaluate()).to.be(10);
|
||||
});
|
||||
|
||||
it('respects group precedence', function() {
|
||||
expect(ol.expr.parse('2 / 4 * (20 % 15)').evaluate()).to.be(2.5);
|
||||
expect(ol.expr.parse('2 / (4 * (20 % 15))').evaluate()).to.be(0.1);
|
||||
expect(ol.expr.parse('2 / ((4 * 20) % 15)').evaluate()).to.be(0.4);
|
||||
expect(ol.expr.parse('2 / (4 * 20) % 15').evaluate()).to.be(0.025);
|
||||
expect(ol.expr.parse('(2 / (4 * 20)) % 15').evaluate()).to.be(0.025);
|
||||
expect(ol.expr.parse('(2 / 4) * 20 % 15').evaluate()).to.be(10);
|
||||
expect(ol.expr.parse('((2 / 4) * 20) % 15').evaluate()).to.be(10);
|
||||
});
|
||||
|
||||
it('parses * in left side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo * 2 >bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 7})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 8})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses * in right side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo > 2 * bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 1})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 2})).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.6 - additive operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.6
|
||||
|
||||
it('parses + operator', function() {
|
||||
var expr = ol.expr.parse('foo+bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(30);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with +', function() {
|
||||
var expr = ol.expr.parse(' foo +10 ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15})).to.be(25);
|
||||
});
|
||||
|
||||
it('parses - operator', function() {
|
||||
var expr = ol.expr.parse('foo-bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(-10);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with -', function() {
|
||||
var expr = ol.expr.parse(' foo- 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15})).to.be(5);
|
||||
});
|
||||
|
||||
it('respects precedence', function() {
|
||||
expect(ol.expr.parse('2 + 4 * 20 - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('(2 + 4) * 20 - 15').evaluate()).to.be(105);
|
||||
expect(ol.expr.parse('((2 + 4) * 20) - 15').evaluate()).to.be(105);
|
||||
expect(ol.expr.parse('(2 + (4 * 20)) - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + (4 * 20) - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + ((4 * 20) - 15)').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + (4 * (20 - 15))').evaluate()).to.be(22);
|
||||
expect(ol.expr.parse('2 + 4 * (20 - 15)').evaluate()).to.be(22);
|
||||
});
|
||||
|
||||
it('parses + in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(2 + bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: 3}, lib)).to.be(5);
|
||||
expect(expr.evaluate({bar: 4}, lib)).to.be(6);
|
||||
});
|
||||
|
||||
it('parses + in left side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo+2>bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 5})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 6})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses + in right side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo >2 +bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 1})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 2})).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.7 - bitwise shift operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.7
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.8 - relational operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.8
|
||||
|
||||
it('parses < operator', function() {
|
||||
var expr = ol.expr.parse('foo<bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with <', function() {
|
||||
var expr = ol.expr.parse(' foo <10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(false);
|
||||
expect(expr.evaluate({foo: 5})).to.be(true);
|
||||
});
|
||||
|
||||
it('parses > operator', function() {
|
||||
var expr = ol.expr.parse('foo>bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with >', function() {
|
||||
var expr = ol.expr.parse(' foo> 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(true);
|
||||
expect(expr.evaluate({foo: 5})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses <= operator', function() {
|
||||
var expr = ol.expr.parse('foo<=bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 20, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with <=', function() {
|
||||
var expr = ol.expr.parse(' foo<= 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(false);
|
||||
expect(expr.evaluate({foo: 5})).to.be(true);
|
||||
expect(expr.evaluate({foo: 10})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with <=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' foo< = 10 ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses >= operator', function() {
|
||||
var expr = ol.expr.parse('foo>=bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 20, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with >=', function() {
|
||||
var expr = ol.expr.parse(' foo >=10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(true);
|
||||
expect(expr.evaluate({foo: 5})).to.be(false);
|
||||
expect(expr.evaluate({foo: 10})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with >=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 > =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.9 - equality operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.9
|
||||
|
||||
it('parses == operator', function() {
|
||||
var expr = ol.expr.parse('foo==42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with ==', function() {
|
||||
var expr = ol.expr.parse(' 42 ==foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ==', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 = =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses != operator', function() {
|
||||
var expr = ol.expr.parse('foo!=42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with !=', function() {
|
||||
var expr = ol.expr.parse(' 42 !=foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with !=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10! =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('!');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses === operator', function() {
|
||||
var expr = ol.expr.parse('42===foo');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with ===', function() {
|
||||
var expr = ol.expr.parse(' foo ===42 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ===', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 = == foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses !== operator', function() {
|
||||
var expr = ol.expr.parse('foo!==42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with !==', function() {
|
||||
var expr = ol.expr.parse(' 42 !== foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with !==', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 != = foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(7);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('11.10 - binary bitwise operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.10
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.11 - binary logical operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.11
|
||||
|
||||
it('parses && operator', function() {
|
||||
var expr = ol.expr.parse('foo&&bar');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes space as expected with &&', function() {
|
||||
var expr = ol.expr.parse(' foo && bar ');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with &&', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('true & & false');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('&');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses || operator', function() {
|
||||
var expr = ol.expr.parse('foo||bar');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes space as expected with ||', function() {
|
||||
var expr = ol.expr.parse(' foo || bar ');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ||', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('true | | false');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('|');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.12 - conditional operator', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.12
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.13 - assignment operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.13
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.14 - comma operator', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.14
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.lib', function() {
|
||||
|
||||
var parse = ol.expr.parse;
|
||||
var evaluate = ol.expr.evaluateFeature;
|
||||
|
||||
describe('concat()', function() {
|
||||
var feature = new ol.Feature({
|
||||
str: 'bar',
|
||||
num: 42,
|
||||
bool: false,
|
||||
nul: null
|
||||
});
|
||||
|
||||
it('concatenates strings', function() {
|
||||
expect(evaluate(parse('concat(str, "after")'), feature))
|
||||
.to.be('barafter');
|
||||
expect(evaluate(parse('concat("before", str)'), feature))
|
||||
.to.be('beforebar');
|
||||
expect(evaluate(parse('concat("a", str, "b")'), feature))
|
||||
.to.be('abarb');
|
||||
});
|
||||
|
||||
it('concatenates numbers as strings', function() {
|
||||
expect(evaluate(parse('concat(num, 0)'), feature))
|
||||
.to.be('420');
|
||||
expect(evaluate(parse('concat(0, num)'), feature))
|
||||
.to.be('042');
|
||||
expect(evaluate(parse('concat(42, 42)'), feature))
|
||||
.to.be('4242');
|
||||
expect(evaluate(parse('concat(str, num)'), feature))
|
||||
.to.be('bar42');
|
||||
});
|
||||
|
||||
it('concatenates booleans as strings', function() {
|
||||
expect(evaluate(parse('concat(bool, "foo")'), feature))
|
||||
.to.be('falsefoo');
|
||||
expect(evaluate(parse('concat(true, str)'), feature))
|
||||
.to.be('truebar');
|
||||
expect(evaluate(parse('concat(true, false)'), feature))
|
||||
.to.be('truefalse');
|
||||
});
|
||||
|
||||
it('concatenates nulls as strings', function() {
|
||||
expect(evaluate(parse('concat(nul, "foo")'), feature))
|
||||
.to.be('nullfoo');
|
||||
expect(evaluate(parse('concat(str, null)'), feature))
|
||||
.to.be('barnull');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('counter()', function() {
|
||||
|
||||
it('increases the counter with every call', function() {
|
||||
var counter = parse('counter()');
|
||||
var start = evaluate(counter);
|
||||
expect(evaluate(counter)).to.be(start + 1);
|
||||
expect(evaluate(counter)).to.be(start + 2);
|
||||
});
|
||||
|
||||
it('increases the counter, starting with a custom value', function() {
|
||||
var counterWithStart = parse('counter(1000)');
|
||||
var start = evaluate(counterWithStart);
|
||||
expect(start > 1000).to.be(true);
|
||||
expect(evaluate(counterWithStart)).to.be(start + 1);
|
||||
expect(evaluate(counterWithStart)).to.be(start + 2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('extent()', function() {
|
||||
|
||||
var nw = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[-180, 90], [0, 90], [0, 0], [-180, 0], [-180, 90]
|
||||
]])
|
||||
});
|
||||
|
||||
var se = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[180, -90], [0, -90], [0, 0], [180, 0], [180, -90]
|
||||
]])
|
||||
});
|
||||
|
||||
var north = parse('extent(-100, 40, 100, 60)');
|
||||
var south = parse('extent(-100, -60, 100, -40)');
|
||||
var east = parse('extent(80, -50, 100, 50)');
|
||||
var west = parse('extent(-100, -50, -80, 50)');
|
||||
|
||||
it('evaluates to true for features within given extent', function() {
|
||||
|
||||
expect(evaluate(north, nw)).to.be(true);
|
||||
expect(evaluate(south, nw)).to.be(false);
|
||||
expect(evaluate(east, nw)).to.be(false);
|
||||
expect(evaluate(west, nw)).to.be(true);
|
||||
|
||||
expect(evaluate(north, se)).to.be(false);
|
||||
expect(evaluate(south, se)).to.be(true);
|
||||
expect(evaluate(east, se)).to.be(true);
|
||||
expect(evaluate(west, se)).to.be(false);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('fid()', function() {
|
||||
|
||||
var one = new ol.Feature();
|
||||
one.setId('one');
|
||||
|
||||
var two = new ol.Feature();
|
||||
two.setId('two');
|
||||
|
||||
var three = new ol.Feature();
|
||||
three.setId('three');
|
||||
|
||||
var four = new ol.Feature();
|
||||
four.setId('four');
|
||||
|
||||
var odd = parse('fid("one", "three")');
|
||||
var even = parse('fid("two", "four")');
|
||||
var first = parse('fid("one")');
|
||||
var last = parse('fid("four")');
|
||||
var none = parse('fid("foo")');
|
||||
|
||||
it('evaluates to true if feature id matches', function() {
|
||||
expect(evaluate(odd, one)).to.be(true);
|
||||
expect(evaluate(odd, three)).to.be(true);
|
||||
expect(evaluate(even, two)).to.be(true);
|
||||
expect(evaluate(even, four)).to.be(true);
|
||||
expect(evaluate(first, one)).to.be(true);
|
||||
expect(evaluate(last, four)).to.be(true);
|
||||
});
|
||||
|
||||
it('evaluates to false if feature id doesn\'t match', function() {
|
||||
expect(evaluate(odd, two)).to.be(false);
|
||||
expect(evaluate(odd, four)).to.be(false);
|
||||
expect(evaluate(even, one)).to.be(false);
|
||||
expect(evaluate(even, three)).to.be(false);
|
||||
expect(evaluate(first, two)).to.be(false);
|
||||
expect(evaluate(first, three)).to.be(false);
|
||||
expect(evaluate(first, four)).to.be(false);
|
||||
expect(evaluate(last, one)).to.be(false);
|
||||
expect(evaluate(last, two)).to.be(false);
|
||||
expect(evaluate(last, three)).to.be(false);
|
||||
expect(evaluate(none, one)).to.be(false);
|
||||
expect(evaluate(none, two)).to.be(false);
|
||||
expect(evaluate(none, three)).to.be(false);
|
||||
expect(evaluate(none, four)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('geometryType()', function() {
|
||||
|
||||
var point = new ol.Feature({
|
||||
geom: new ol.geom.Point([0, 0])
|
||||
});
|
||||
|
||||
var line = new ol.Feature({
|
||||
geom: new ol.geom.LineString([[180, -90], [-180, 90]])
|
||||
});
|
||||
|
||||
var poly = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[180, -90], [0, -90], [0, 0], [180, 0], [180, -90]
|
||||
]])
|
||||
});
|
||||
|
||||
var isPoint = parse('geometryType("point")');
|
||||
var isLine = parse('geometryType("linestring")');
|
||||
var isPoly = parse('geometryType("polygon")');
|
||||
var pointOrPoly = parse('geometryType("point") || geometryType("polygon")');
|
||||
|
||||
it('distinguishes point features', function() {
|
||||
expect(evaluate(isPoint, point)).to.be(true);
|
||||
expect(evaluate(isPoint, line)).to.be(false);
|
||||
expect(evaluate(isPoint, poly)).to.be(false);
|
||||
});
|
||||
|
||||
it('distinguishes line features', function() {
|
||||
expect(evaluate(isLine, point)).to.be(false);
|
||||
expect(evaluate(isLine, line)).to.be(true);
|
||||
expect(evaluate(isLine, poly)).to.be(false);
|
||||
});
|
||||
|
||||
it('distinguishes polygon features', function() {
|
||||
expect(evaluate(isPoly, point)).to.be(false);
|
||||
expect(evaluate(isPoly, line)).to.be(false);
|
||||
expect(evaluate(isPoly, poly)).to.be(true);
|
||||
});
|
||||
|
||||
it('can be composed in a logical expression', function() {
|
||||
expect(evaluate(pointOrPoly, point)).to.be(true);
|
||||
expect(evaluate(pointOrPoly, line)).to.be(false);
|
||||
expect(evaluate(pointOrPoly, poly)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('like()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'bar'});
|
||||
var two = new ol.Feature({foo: 'baz'});
|
||||
var three = new ol.Feature({foo: 'foo'});
|
||||
|
||||
var like = parse('like(foo, "ba")');
|
||||
|
||||
it('First and second feature match, third does not', function() {
|
||||
expect(evaluate(like, one), true);
|
||||
expect(evaluate(like, two), true);
|
||||
expect(evaluate(like, three), false);
|
||||
});
|
||||
|
||||
var uclike = parse('like(foo, "BA")');
|
||||
it('Matchcase is true by default', function() {
|
||||
expect(evaluate(uclike, one), false);
|
||||
expect(evaluate(uclike, two), false);
|
||||
expect(evaluate(uclike, three), false);
|
||||
});
|
||||
|
||||
var ilike = parse('like(foo, "BA", "*", ".", "!", false)');
|
||||
it('Using matchcase false, first two features match again', function() {
|
||||
expect(evaluate(ilike, one), true);
|
||||
expect(evaluate(ilike, two), true);
|
||||
expect(evaluate(uclike, three), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ieq()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'Bar'});
|
||||
var two = new ol.Feature({bar: 'Foo'});
|
||||
|
||||
var ieq1 = parse('ieq(foo, "bar")');
|
||||
var ieq2 = parse('ieq("foo", bar)');
|
||||
|
||||
it('case-insensitive equality for an attribute', function() {
|
||||
expect(evaluate(ieq1, one), true);
|
||||
});
|
||||
|
||||
it('case-insensitive equality for an attribute as second argument',
|
||||
function() {
|
||||
expect(evaluate(ieq2, two), true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ineq()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'Bar'});
|
||||
var two = new ol.Feature({bar: 'Foo'});
|
||||
|
||||
var ieq1 = parse('ineq(foo, "bar")');
|
||||
var ieq2 = parse('ineq("foo", bar)');
|
||||
|
||||
it('case-insensitive non-equality for an attribute', function() {
|
||||
expect(evaluate(ieq1, one), false);
|
||||
});
|
||||
|
||||
it('case-insensitive non-equality for an attribute as second argument',
|
||||
function() {
|
||||
expect(evaluate(ieq2, two), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('renderIntent()', function() {
|
||||
|
||||
var feature = new ol.Feature();
|
||||
feature.setRenderIntent('foo');
|
||||
|
||||
var isFoo = parse('renderIntent("foo")');
|
||||
var isBar = parse('renderIntent("bar")');
|
||||
|
||||
it('True when renderIntent matches', function() {
|
||||
expect(evaluate(isFoo, feature), true);
|
||||
});
|
||||
|
||||
it('False when renderIntent does not match', function() {
|
||||
expect(evaluate(isBar, feature), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.register()', function() {
|
||||
|
||||
var spy;
|
||||
beforeEach(function() {
|
||||
spy = sinon.spy();
|
||||
});
|
||||
|
||||
it('registers custom functions in ol.expr.lib', function() {
|
||||
ol.expr.register('someFunc', spy);
|
||||
expect(ol.expr.lib.someFunc).to.be(spy);
|
||||
});
|
||||
|
||||
it('allows custom functions to be called', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(42)');
|
||||
expr.evaluate(null, ol.expr.lib);
|
||||
expect(spy.calledOnce);
|
||||
expect(spy.calledWithExactly(42));
|
||||
});
|
||||
|
||||
it('allows custom functions to be called with identifiers', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(foo, 42)');
|
||||
expr.evaluate({foo: 'bar'}, ol.expr.lib);
|
||||
expect(spy.calledOnce).to.be(true);
|
||||
expect(spy.calledWithExactly('bar', 42)).to.be(true);
|
||||
});
|
||||
|
||||
it('allows custom functions to be called with custom this obj', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(foo, 42)');
|
||||
var that = {};
|
||||
expr.evaluate({foo: 'bar'}, ol.expr.lib, that);
|
||||
expect(spy.calledOnce).to.be(true);
|
||||
expect(spy.calledWithExactly('bar', 42)).to.be(true);
|
||||
expect(spy.calledOn(that)).to.be(true);
|
||||
});
|
||||
|
||||
it('allows overriding existing ol.expr.lib functions', function() {
|
||||
var orig = ol.expr.lib.extent;
|
||||
expect(orig).not.to.be(spy);
|
||||
ol.expr.register('extent', spy);
|
||||
expect(ol.expr.lib.extent).to.be(spy);
|
||||
ol.expr.lib.extent = orig;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.TokenType');
|
||||
goog.require('ol.expr.UnexpectedToken');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
638
old/test/spec/ol/expr/expressions.test.js
Normal file
638
old/test/spec/ol/expr/expressions.test.js
Normal file
@@ -0,0 +1,638 @@
|
||||
goog.provide('ol.test.expression.Expression');
|
||||
|
||||
|
||||
describe('ol.expr.Call', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Literal(42)]);
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
var fns = {
|
||||
sqrt: function(value) {
|
||||
return Math.sqrt(value);
|
||||
},
|
||||
strConcat: function() {
|
||||
return Array.prototype.join.call(arguments, '');
|
||||
},
|
||||
discouraged: function() {
|
||||
return this.message;
|
||||
}
|
||||
};
|
||||
|
||||
it('calls method on scope with literal args', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Literal(42)]);
|
||||
expect(expr.evaluate(fns)).to.be(Math.sqrt(42));
|
||||
});
|
||||
|
||||
it('accepts a separate scope for functions', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Identifier('foo')]);
|
||||
expect(expr.evaluate({foo: 42}, fns)).to.be(Math.sqrt(42));
|
||||
});
|
||||
|
||||
it('accepts multiple expression arguments', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('strConcat'),
|
||||
[
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(' comes after '),
|
||||
new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(1))
|
||||
]);
|
||||
expect(expr.evaluate({foo: 42}, fns)).to.be('42 comes after 41');
|
||||
});
|
||||
|
||||
it('accepts optional this arg', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('discouraged'), []);
|
||||
|
||||
var thisArg = {
|
||||
message: 'avoid this'
|
||||
};
|
||||
|
||||
expect(expr.evaluate(fns, null, thisArg)).to.be('avoid this');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var callee = new ol.expr.Identifier('sqrt');
|
||||
var args = [new ol.expr.Literal(42)];
|
||||
var expr = new ol.expr.Call(callee, args);
|
||||
|
||||
describe('#getArgs()', function() {
|
||||
it('gets the callee expression', function() {
|
||||
expect(expr.getArgs()).to.be(args);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCallee()', function() {
|
||||
it('gets the callee expression', function() {
|
||||
expect(expr.getCallee()).to.be(callee);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Comparison', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('compares with ==', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with !=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
expect(expr.evaluate({foo: true})).to.be(true);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with ===', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.STRICT_EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with !==', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.STRICT_NEQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
expect(expr.evaluate({foo: true})).to.be(true);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with >', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: 43})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with <', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: 43})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with >=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: 43})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with <=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: 43})).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Comparison.isValidOp('<')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('==')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('!=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('===')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('!==')).to.be(true);
|
||||
|
||||
expect(ol.expr.Comparison.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('+')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('-')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('&&')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.ComparisonOp.LTE;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(42);
|
||||
var expr = new ol.expr.Comparison(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Identifier', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('returns a number from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr.evaluate({foo: 42})).to.be(42);
|
||||
});
|
||||
|
||||
it('returns a string from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr.evaluate({foo: 'chicken'})).to.be('chicken');
|
||||
});
|
||||
|
||||
it('returns a boolean from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('bar');
|
||||
expect(expr.evaluate({bar: false})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('returns a null from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('nada');
|
||||
expect(expr.evaluate({nada: null})).to.be(null);
|
||||
});
|
||||
|
||||
it('works for unicode identifiers', function() {
|
||||
var expr = new ol.expr.Identifier('\u03c0');
|
||||
expect(expr.evaluate({'\u03c0': Math.PI})).to.be(Math.PI);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getName()', function() {
|
||||
var expr = new ol.expr.Identifier('asdf');
|
||||
expect(expr.getName()).to.be('asdf');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Literal', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Literal(true);
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('works for numeric literal', function() {
|
||||
var expr = new ol.expr.Literal(42e-11);
|
||||
expect(expr.evaluate()).to.be(4.2e-10);
|
||||
});
|
||||
|
||||
it('works for string literal', function() {
|
||||
var expr = new ol.expr.Literal('asdf');
|
||||
expect(expr.evaluate()).to.be('asdf');
|
||||
});
|
||||
|
||||
it('works for boolean literal', function() {
|
||||
var expr = new ol.expr.Literal(true);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works for null literal', function() {
|
||||
var expr = new ol.expr.Literal(null);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getValue()', function() {
|
||||
var expr = new ol.expr.Literal('asdf');
|
||||
expect(expr.getValue()).to.be('asdf');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Logical', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('applies || to resolved identifiers', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('applies && to resolved identifiers', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Logical.isValidOp('||')).to.be(true);
|
||||
expect(ol.expr.Logical.isValidOp('&&')).to.be(true);
|
||||
|
||||
expect(ol.expr.Logical.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('+')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('<')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('|')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.LogicalOp.AND;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(false);
|
||||
var expr = new ol.expr.Logical(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Math', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal(40),
|
||||
new ol.expr.Literal(2));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('does + with numeric literal', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal(40),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('does + with string literal (note: subject to change)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal('foo'),
|
||||
new ol.expr.Literal('bar'));
|
||||
|
||||
expect(expr.evaluate()).to.be('foobar');
|
||||
});
|
||||
|
||||
it('does + with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: 40, bar: 2})).to.be(42);
|
||||
});
|
||||
|
||||
it('does - with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: 40})).to.be(38);
|
||||
});
|
||||
|
||||
it('casts to number with - (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: '40'})).to.be(38);
|
||||
});
|
||||
|
||||
it('does * with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MULTIPLY,
|
||||
new ol.expr.Literal(2),
|
||||
new ol.expr.Identifier('foo'));
|
||||
|
||||
expect(expr.evaluate({foo: 21})).to.be(42);
|
||||
});
|
||||
|
||||
it('casts to number with * (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MULTIPLY,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: '21'})).to.be(42);
|
||||
});
|
||||
|
||||
it('does % with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MOD,
|
||||
new ol.expr.Literal(97),
|
||||
new ol.expr.Identifier('foo'));
|
||||
|
||||
expect(expr.evaluate({foo: 55})).to.be(42);
|
||||
});
|
||||
|
||||
it('casts to number with % (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MOD,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(100));
|
||||
|
||||
expect(expr.evaluate({foo: '150'})).to.be(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Math.isValidOp('+')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('-')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('*')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('/')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('%')).to.be(true);
|
||||
|
||||
expect(ol.expr.Math.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('|')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('&')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('<')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('||')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('.')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.MathOp.MOD;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(20);
|
||||
var expr = new ol.expr.Math(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Member', function() {
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Member(
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('accesses an object property', function() {
|
||||
|
||||
var expr = new ol.expr.Member(
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
var scope = {foo: {bar: 42}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
});
|
||||
|
||||
var object = new ol.expr.Identifier('foo');
|
||||
var property = new ol.expr.Identifier('bar');
|
||||
var expr = new ol.expr.Member(object, property);
|
||||
|
||||
describe('#getObject()', function() {
|
||||
expect(expr.getObject()).to.be(object);
|
||||
});
|
||||
|
||||
describe('#getProperty()', function() {
|
||||
expect(expr.getProperty()).to.be(property);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Not', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Not(
|
||||
new ol.expr.Literal(true));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('returns the logical complement', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(true));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expr = new ol.expr.Not(new ol.expr.Literal(false));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('negates a truthy string', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal('asdf'));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('negates a falsy string', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(''));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('negates a truthy number', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(42));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('negates a falsy number', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(NaN));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getArgument()', function() {
|
||||
var argument = new ol.expr.Literal(true);
|
||||
var expr = new ol.expr.Not(argument);
|
||||
expect(expr.getArgument()).to.be(argument);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.MathOp');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
509
old/test/spec/ol/expr/lexer.test.js
Normal file
509
old/test/spec/ol/expr/lexer.test.js
Normal file
@@ -0,0 +1,509 @@
|
||||
goog.provide('ol.test.expression.Lexer');
|
||||
|
||||
describe('ol.expr.Lexer', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new lexer', function() {
|
||||
var lexer = new ol.expr.Lexer('foo');
|
||||
expect(lexer).to.be.a(ol.expr.Lexer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#next()', function() {
|
||||
|
||||
it('returns one token at a time', function() {
|
||||
var source = 'foo === "bar"';
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
|
||||
// scan first token
|
||||
var token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
// scan second token
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
expect(token.value).to.be('===');
|
||||
|
||||
// scan third token
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
expect(token.value).to.be('bar');
|
||||
|
||||
// scan again
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
|
||||
// and again
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#peek()', function() {
|
||||
|
||||
var lexer;
|
||||
beforeEach(function() {
|
||||
lexer = new ol.expr.Lexer('foo > 42 && bar == "chicken"');
|
||||
});
|
||||
|
||||
it('looks ahead without consuming token', function() {
|
||||
var token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
});
|
||||
|
||||
it('works after a couple scans', function() {
|
||||
var token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
expect(token.value).to.be('>');
|
||||
|
||||
token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
expect(token.value).to.be(42);
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
expect(token.value).to.be(42);
|
||||
});
|
||||
|
||||
it('returns the same thing when called multiple times', function() {
|
||||
var token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#scanIdentifier_()', function() {
|
||||
|
||||
function scan(source, part) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanIdentifier_(lexer.getCurrentCharCode_());
|
||||
if (!part) {
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for short identifiers', function() {
|
||||
var token = scan('a');
|
||||
expect(token.value).to.be('a');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for longer identifiers', function() {
|
||||
var token = scan('foo');
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for $ anywhere', function() {
|
||||
var token = scan('$foo$bar$');
|
||||
expect(token.value).to.be('$foo$bar$');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for _ anywhere', function() {
|
||||
var token = scan('_foo_bar_');
|
||||
expect(token.value).to.be('_foo_bar_');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for keywords', function() {
|
||||
var token = scan('delete');
|
||||
expect(token.value).to.be('delete');
|
||||
expect(token.type).to.be(ol.expr.TokenType.KEYWORD);
|
||||
});
|
||||
|
||||
it('works for null', function() {
|
||||
var token = scan('null');
|
||||
expect(token.value).to.be('null');
|
||||
expect(token.type).to.be(ol.expr.TokenType.NULL_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean true', function() {
|
||||
var token = scan('true');
|
||||
expect(token.value).to.be('true');
|
||||
expect(token.type).to.be(ol.expr.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean false', function() {
|
||||
var token = scan('false');
|
||||
expect(token.value).to.be('false');
|
||||
expect(token.type).to.be(ol.expr.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works with unicode escape sequences', function() {
|
||||
var token = scan('\u006f\u006c\u0033');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works with hex escape sequences', function() {
|
||||
var token = scan('\x6f\x6c\x33');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a number', function() {
|
||||
expect(function() {
|
||||
scan('4foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a punctuation char', function() {
|
||||
expect(function() {
|
||||
scan('!foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('only scans valid identifier part', function() {
|
||||
var token = scan('foo>bar', true);
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanNumericLiteral_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanNumericLiteral_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for integers', function() {
|
||||
var token = scan('123');
|
||||
expect(token.value).to.be(123);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus integer', function() {
|
||||
expect(function() {
|
||||
scan('123z');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('z');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('works for float', function() {
|
||||
var token = scan('123.456');
|
||||
expect(token.value).to.be(123.456);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus float', function() {
|
||||
expect(function() {
|
||||
scan('123.4x4');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('x');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with exponent', function() {
|
||||
var token = scan('1.234e5');
|
||||
expect(token.value).to.be(1.234e5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('works with explicit positive exponent', function() {
|
||||
var token = scan('1.234e+5');
|
||||
expect(token.value).to.be(1.234e5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('works with negative exponent', function() {
|
||||
var token = scan('1.234e-5');
|
||||
expect(token.value).to.be(1.234e-5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus float', function() {
|
||||
expect(function() {
|
||||
scan('1.234eo4');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('o');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with octals', function() {
|
||||
var token = scan('02322');
|
||||
expect(token.value).to.be(1234);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus octal', function() {
|
||||
// note that this is more strict than most es5 engines
|
||||
expect(function() {
|
||||
scan('02392');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('9');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with hex', function() {
|
||||
var token = scan('0x4d2');
|
||||
expect(token.value).to.be(1234);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus hex', function() {
|
||||
// note that this is more strict than most es5 engines
|
||||
expect(function() {
|
||||
scan('0x4G');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('G');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanPunctuator_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanPunctuator_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for dot', function() {
|
||||
var token = scan('.');
|
||||
expect(token.value).to.be('.');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for bang', function() {
|
||||
var token = scan('!');
|
||||
expect(token.value).to.be('!');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for double equal', function() {
|
||||
var token = scan('==');
|
||||
expect(token.value).to.be('==');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for triple equal', function() {
|
||||
var token = scan('===');
|
||||
expect(token.value).to.be('===');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for not double equal', function() {
|
||||
var token = scan('!=');
|
||||
expect(token.value).to.be('!=');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for not triple equal', function() {
|
||||
var token = scan('!==');
|
||||
expect(token.value).to.be('!==');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for logical or', function() {
|
||||
var token = scan('||');
|
||||
expect(token.value).to.be('||');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for logical and', function() {
|
||||
var token = scan('&&');
|
||||
expect(token.value).to.be('&&');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for plus', function() {
|
||||
var token = scan('+');
|
||||
expect(token.value).to.be('+');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for minus', function() {
|
||||
var token = scan('-');
|
||||
expect(token.value).to.be('-');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for star', function() {
|
||||
var token = scan('*');
|
||||
expect(token.value).to.be('*');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for slash', function() {
|
||||
var token = scan('/');
|
||||
expect(token.value).to.be('/');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for percent', function() {
|
||||
var token = scan('%');
|
||||
expect(token.value).to.be('%');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanStringLiteral_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanStringLiteral_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('parses double quoted string', function() {
|
||||
var token = scan('"my string"');
|
||||
expect(token.value).to.be('my string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with internal single quotes', function() {
|
||||
var token = scan('"my \'quoted\' string"');
|
||||
expect(token.value).to.be('my \'quoted\' string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with escaped double quotes', function() {
|
||||
var token = scan('"my \\"quoted\\" string"');
|
||||
expect(token.value).to.be('my "quoted" string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with escaped backslash', function() {
|
||||
var token = scan('"my \\\ string"');
|
||||
expect(token.value).to.be('my \ string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with unicode escape sequences', function() {
|
||||
var token = scan('"\u006f\u006c\u0033"');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with hex escape sequences', function() {
|
||||
var token = scan('"\x6f\x6c\x33"');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with tab', function() {
|
||||
var token = scan('"a\ttab"');
|
||||
expect(token.value).to.be('a\ttab');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('throws on unterminated double quote', function() {
|
||||
expect(function() {
|
||||
scan('"never \'ending\' string');
|
||||
}).to.throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(22);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses single quoted string', function() {
|
||||
var token = scan('\'my string\'');
|
||||
expect(token.value).to.be('my string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with internal double quotes', function() {
|
||||
var token = scan('\'my "quoted" string\'');
|
||||
expect(token.value).to.be('my "quoted" string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with escaped single quotes', function() {
|
||||
var token = scan('\'my \\\'quoted\\\' string\'');
|
||||
expect(token.value).to.be('my \'quoted\' string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with escaped backslash', function() {
|
||||
var token = scan('\'my \\\ string\'');
|
||||
expect(token.value).to.be('my \ string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with unicode escape sequences', function() {
|
||||
var token = scan('\'\u006f\u006c\u0033\'');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with hex escape sequences', function() {
|
||||
var token = scan('\'\x6f\x6c\x33\'');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with tab', function() {
|
||||
var token = scan('\'a\ttab\'');
|
||||
expect(token.value).to.be('a\ttab');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('throws on unterminated single quote', function() {
|
||||
expect(function() {
|
||||
scan('\'never "ending" string');
|
||||
}).to.throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(22);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.expr.Lexer');
|
||||
goog.require('ol.expr.TokenType');
|
||||
goog.require('ol.expr.UnexpectedToken');
|
||||
275
old/test/spec/ol/expr/parser.test.js
Normal file
275
old/test/spec/ol/expr/parser.test.js
Normal file
@@ -0,0 +1,275 @@
|
||||
goog.provide('ol.test.expression.Parser');
|
||||
|
||||
describe('ol.expr.Parser', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression parser', function() {
|
||||
var parser = new ol.expr.Parser();
|
||||
expect(parser).to.be.a(ol.expr.Parser);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#parseArguments_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseArguments_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses comma separated expressions in parens', function() {
|
||||
var args = parse('(1/3, "foo", true)');
|
||||
expect(args).length(3);
|
||||
|
||||
expect(args[0]).to.be.a(ol.expr.Math);
|
||||
expect(args[0].evaluate()).to.be(1 / 3);
|
||||
|
||||
expect(args[1]).to.be.a(ol.expr.Literal);
|
||||
expect(args[1].evaluate()).to.be('foo');
|
||||
|
||||
expect(args[2]).to.be.a(ol.expr.Literal);
|
||||
expect(args[2].evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('throws on invalid arg expression', function() {
|
||||
expect(function() {
|
||||
parse('(6e)');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('throws on unterminated args', function() {
|
||||
expect(function() {
|
||||
parse('("foo", 42, )');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseBinaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseBinaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('works with multiplicitave operators', function() {
|
||||
var expr = parse('4 * 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate()).to.be(40000);
|
||||
|
||||
expect(parse('10/3').evaluate()).to.be(10 / 3);
|
||||
});
|
||||
|
||||
it('works with additive operators', function() {
|
||||
var expr = parse('4 +1e4');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate()).to.be(10004);
|
||||
|
||||
expect(parse('10-3').evaluate()).to.be(7);
|
||||
});
|
||||
|
||||
it('works with relational operators', function() {
|
||||
var expr = parse('4 < 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
|
||||
expect(parse('10<3').evaluate()).to.be(false);
|
||||
expect(parse('10 <= "10"').evaluate()).to.be(true);
|
||||
expect(parse('10 > "10"').evaluate()).to.be(false);
|
||||
expect(parse('10 >= 9').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with equality operators', function() {
|
||||
var expr = parse('4 == 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expect(parse('10!=3').evaluate()).to.be(true);
|
||||
expect(parse('10 == "10"').evaluate()).to.be(true);
|
||||
expect(parse('10 === "10"').evaluate()).to.be(false);
|
||||
expect(parse('10 !== "10"').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with binary logical operators', function() {
|
||||
var expr = parse('true && false');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expect(parse('false||true').evaluate()).to.be(true);
|
||||
expect(parse('false || false').evaluate()).to.be(false);
|
||||
expect(parse('true &&true').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid binary expression', function() {
|
||||
expect(function() {
|
||||
parse('4 * / 2');
|
||||
}).throwException();
|
||||
|
||||
expect(function() {
|
||||
parse('4 < / 2');
|
||||
}).throwException();
|
||||
|
||||
expect(function() {
|
||||
parse('4 * && 2');
|
||||
}).throwException();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseGroupExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseGroupExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses grouped expressions', function() {
|
||||
var expr = parse('(3 * (foo + 2))');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 3})).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseLeftHandSideExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseLeftHandSideExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses member expressions', function() {
|
||||
var expr = parse('foo.bar.bam');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
});
|
||||
|
||||
it('throws on invalid member expression', function() {
|
||||
expect(function() {
|
||||
parse('foo.4');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('parses call expressions', function() {
|
||||
var expr = parse('foo(bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
var fns = {
|
||||
foo: function(arg) {
|
||||
expect(arguments).length(1);
|
||||
expect(arg).to.be('chicken');
|
||||
return 'got ' + arg;
|
||||
}
|
||||
};
|
||||
var scope = {
|
||||
bar: 'chicken'
|
||||
};
|
||||
expect(expr.evaluate(scope, fns)).to.be('got chicken');
|
||||
});
|
||||
|
||||
it('throws on invalid call expression', function() {
|
||||
expect(function() {
|
||||
parse('foo(*)');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#parsePrimaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parsePrimaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses string literal', function() {
|
||||
var expr = parse('"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be('foo');
|
||||
});
|
||||
|
||||
it('parses numeric literal', function() {
|
||||
var expr = parse('.42e2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('parses boolean literal', function() {
|
||||
var expr = parse('.42e2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('parses null literal', function() {
|
||||
var expr = parse('null');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseUnaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseUnaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses logical not', function() {
|
||||
var expr = parse('!foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('works with string literal', function() {
|
||||
var expr = parse('!"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('works with empty string', function() {
|
||||
var expr = parse('!""');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with null', function() {
|
||||
var expr = parse('!null');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.Lexer');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.Parser');
|
||||
goog.require('ol.expr.TokenType');
|
||||
269
old/test/spec/ol/feature.test.js
Normal file
269
old/test/spec/ol/feature.test.js
Normal file
@@ -0,0 +1,269 @@
|
||||
goog.provide('ol.test.Feature');
|
||||
|
||||
describe('ol.Feature', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new feature', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature).to.be.a(ol.Feature);
|
||||
});
|
||||
|
||||
it('takes attribute values', function() {
|
||||
var feature = new ol.Feature({
|
||||
foo: 'bar'
|
||||
});
|
||||
expect(feature.get('foo')).to.be('bar');
|
||||
});
|
||||
|
||||
it('can store the feature\'s commonly used id', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
});
|
||||
|
||||
it('will set the default geometry', function() {
|
||||
var feature = new ol.Feature({
|
||||
loc: new ol.geom.Point([10, 20]),
|
||||
foo: 'bar'
|
||||
});
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.Point);
|
||||
expect(feature.get('loc')).to.be(geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#get()', function() {
|
||||
|
||||
it('returns values set at construction', function() {
|
||||
var feature = new ol.Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
expect(feature.get('a')).to.be('first');
|
||||
expect(feature.get('b')).to.be('second');
|
||||
});
|
||||
|
||||
it('returns undefined for unset attributes', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature.get('a')).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns values set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('a', 'b');
|
||||
expect(feature.get('a')).to.be('b');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getAttributes()', function() {
|
||||
|
||||
it('returns an object with all attributes', function() {
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
var feature = new ol.Feature({
|
||||
foo: 'bar',
|
||||
ten: 10,
|
||||
loc: point
|
||||
});
|
||||
|
||||
var attributes = feature.getAttributes();
|
||||
|
||||
var keys = goog.object.getKeys(attributes);
|
||||
expect(keys.sort()).to.eql(['foo', 'loc', 'ten']);
|
||||
|
||||
expect(attributes.foo).to.be('bar');
|
||||
expect(attributes.loc).to.be(point);
|
||||
expect(attributes.ten).to.be(10);
|
||||
});
|
||||
|
||||
it('returns an object with all attributes except geometry', function() {
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
var feature = new ol.Feature({
|
||||
foo: 'bar',
|
||||
ten: 10,
|
||||
loc: point
|
||||
});
|
||||
|
||||
var attributes = feature.getAttributes(true);
|
||||
|
||||
var keys = goog.object.getKeys(attributes);
|
||||
expect(keys.sort()).to.eql(['foo', 'ten']);
|
||||
|
||||
expect(attributes.foo).to.be('bar');
|
||||
expect(attributes.ten).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getGeometry()', function() {
|
||||
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
|
||||
it('returns null for no geometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
expect(feature.getGeometry()).to.be(null);
|
||||
});
|
||||
|
||||
it('gets the geometry set at construction', function() {
|
||||
var feature = new ol.Feature({
|
||||
geom: point
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
|
||||
it('gets the first geometry set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
feature.set('bar', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#set()', function() {
|
||||
|
||||
it('sets values', function() {
|
||||
var feature = new ol.Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
});
|
||||
feature.set('a', 'new');
|
||||
expect(feature.get('a')).to.be('new');
|
||||
});
|
||||
|
||||
it('can be used to set the geometry', function() {
|
||||
var point = new ol.geom.Point([3, 4]);
|
||||
var feature = new ol.Feature({
|
||||
loc: new ol.geom.Point([1, 2])
|
||||
});
|
||||
feature.set('loc', point);
|
||||
expect(feature.get('loc')).to.be(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('can be used to set attributes with arbitrary names', function() {
|
||||
|
||||
var feature = new ol.Feature();
|
||||
|
||||
feature.set('toString', 'string');
|
||||
expect(feature.get('toString')).to.be('string');
|
||||
expect(typeof feature.toString).to.be('function');
|
||||
|
||||
feature.set('getGeometry', 'x');
|
||||
expect(feature.get('getGeometry')).to.be('x');
|
||||
|
||||
feature.set('geom', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
it('triggers a featurechange event', function(done) {
|
||||
var feature = new ol.Feature();
|
||||
goog.events.listen(feature, 'featurechange', function(evt) {
|
||||
expect(evt.target).to.be(feature);
|
||||
expect(evt.oldExtent).to.be(null);
|
||||
done();
|
||||
});
|
||||
feature.set('foo', 'bar');
|
||||
});
|
||||
|
||||
it('triggers a featurechange event with oldExtent', function(done) {
|
||||
var feature = new ol.Feature({
|
||||
geom: new ol.geom.Point([15, 30])
|
||||
});
|
||||
goog.events.listen(feature, 'featurechange', function(evt) {
|
||||
expect(evt.target).to.be(feature);
|
||||
expect(evt.oldExtent).to.eql([15, 30, 15, 30]);
|
||||
done();
|
||||
});
|
||||
feature.setGeometry(new ol.geom.Point([1, 2]));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
var point = new ol.geom.Point([15, 30]);
|
||||
|
||||
it('sets the default geometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.get(ol.Feature.DEFAULT_GEOMETRY)).to.be(point);
|
||||
});
|
||||
|
||||
it('replaces previous default geometry', function() {
|
||||
var feature = new ol.Feature({
|
||||
geom: point
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
var point2 = new ol.geom.Point([1, 2]);
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
|
||||
it('gets the first geometry set by set', function() {
|
||||
var feature = new ol.Feature();
|
||||
feature.set('foo', point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
feature.set('bar', new ol.geom.Point([1, 2]));
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('triggers a featurechange event', function(done) {
|
||||
var feature = new ol.Feature();
|
||||
goog.events.listen(feature, 'featurechange', function(evt) {
|
||||
expect(evt.target).to.be(feature);
|
||||
done();
|
||||
});
|
||||
feature.setGeometry('foo', point);
|
||||
});
|
||||
|
||||
it('triggers a featurechange event with old extent', function(done) {
|
||||
var first = new ol.geom.Point([10, 20]);
|
||||
var feature = new ol.Feature({geom: first});
|
||||
var second = new ol.geom.Point([20, 30]);
|
||||
goog.events.listen(feature, 'featurechange', function(evt) {
|
||||
expect(evt.target).to.be(feature);
|
||||
expect(evt.target.getGeometry()).to.be(second);
|
||||
expect(evt.oldExtent).to.eql(first.getBounds());
|
||||
done();
|
||||
});
|
||||
feature.setGeometry(second);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Point');
|
||||
52
old/test/spec/ol/geom/geometry.test.js
Normal file
52
old/test/spec/ol/geom/geometry.test.js
Normal file
@@ -0,0 +1,52 @@
|
||||
goog.provide('ol.test.geom.Geometry');
|
||||
|
||||
describe('ol.geom.Geometry', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new geometry', function() {
|
||||
var geom = new ol.geom.Geometry();
|
||||
expect(geom).to.be.a(ol.geom.Geometry);
|
||||
expect(geom).to.be.a(goog.events.EventTarget);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clone()', function() {
|
||||
it('clones a geometry', function() {
|
||||
var line = new ol.geom.LineString([[0, 0], [1, 1]]);
|
||||
var clone = line.clone();
|
||||
expect(clone.getCoordinates().length).to.be(2);
|
||||
expect(clone.getCoordinates()[0]).to.eql(line.getCoordinates()[0]);
|
||||
expect(clone.getCoordinates()[0]).to.not.be(line.getCoordinates()[0]);
|
||||
var coordinates = clone.getCoordinates();
|
||||
coordinates[0] = [2, 2];
|
||||
clone.setCoordinates(coordinates);
|
||||
expect(clone.getCoordinates()[0]).to.not.eql(line.getCoordinates()[0]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.GeometryEvent', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new event', function() {
|
||||
var point = new ol.geom.Point([1, 2]);
|
||||
var bounds = point.getBounds();
|
||||
var evt = new ol.geom.GeometryEvent('change', point, bounds);
|
||||
expect(evt).to.be.a(ol.geom.GeometryEvent);
|
||||
expect(evt).to.be.a(goog.events.Event);
|
||||
expect(evt.target).to.be(point);
|
||||
expect(evt.oldExtent).to.be(bounds);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.events.EventTarget');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryEvent');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.LineString');
|
||||
78
old/test/spec/ol/geom/geometrycollection.test.js
Normal file
78
old/test/spec/ol/geom/geometrycollection.test.js
Normal file
@@ -0,0 +1,78 @@
|
||||
goog.provide('ol.test.geom.GeometryCollection');
|
||||
|
||||
describe('ol.geom.GeometryCollection', function() {
|
||||
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
|
||||
it('creates a geometry collection from an array of geometries', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
expect(multi).to.be.a(ol.geom.GeometryCollection);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of geometries', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(3);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
expect(components[2]).to.be.a(ol.geom.Polygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#clone()', function() {
|
||||
|
||||
it('has a working clone method', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||
var clone = multi.clone();
|
||||
expect(clone).to.not.be(multi);
|
||||
var components = clone.getComponents();
|
||||
expect(components[0].getCoordinates()).to.eql([10, 20]);
|
||||
expect(components[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
expect(components[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 2]);
|
||||
var line = new ol.geom.LineString([[1, 20], [30, 40]]);
|
||||
var multi = new ol.geom.GeometryCollection([point, line]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(1);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(2);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
125
old/test/spec/ol/geom/linearring.test.js
Normal file
125
old/test/spec/ol/geom/linearring.test.js
Normal file
@@ -0,0 +1,125 @@
|
||||
goog.provide('ol.test.geom.LinearRing');
|
||||
|
||||
describe('ol.geom.LinearRing', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a ring from an array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('is an array', function() {
|
||||
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
|
||||
expect(ring.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#containsCoordinate()', function() {
|
||||
|
||||
it('knows when a point coordinate is inside a ring', function() {
|
||||
/**
|
||||
* The ring:
|
||||
* edge 3
|
||||
* (5, 10) __________ (15, 10)
|
||||
* / /
|
||||
* edge 4 / / edge 2
|
||||
* / /
|
||||
* (0, 0) /_________/ (10, 0)
|
||||
* edge 1
|
||||
*/
|
||||
var ring = new ol.geom.LinearRing(
|
||||
[[0, 0], [10, 0], [15, 10], [5, 10]]);
|
||||
|
||||
// contains: 1 (touches - not implemented), true (within), false (outside)
|
||||
var cases = [{
|
||||
point: [5, 5], contains: true
|
||||
}, {
|
||||
point: [20, 20], contains: false
|
||||
}, {
|
||||
point: [15, 15], contains: false
|
||||
}/*, {
|
||||
point: [0, 0], contains: 1 // lower left corner
|
||||
}, {
|
||||
point: [10, 0], contains: 1 // lower right corner
|
||||
}, {
|
||||
point: [15, 10], contains: 1 // upper right corner
|
||||
}, {
|
||||
point: [5, 10], contains: 1 // upper left corner
|
||||
}, {
|
||||
point: [5, 0], contains: 1 // on edge 1
|
||||
}*/, {
|
||||
point: [5, -0.1], contains: false // below edge 1
|
||||
}, {
|
||||
point: [5, 0.1], contains: true // above edge 1
|
||||
}/*, {
|
||||
point: [12.5, 5], contains: 1 // on edge 2
|
||||
}*/, {
|
||||
point: [12.4, 5], contains: true // left of edge 2
|
||||
}, {
|
||||
point: [12.6, 5], contains: false // right of edge 2
|
||||
}/*, {
|
||||
point: [10, 10], contains: 1 // on edge 3
|
||||
}*/, {
|
||||
point: [10, 9.9], contains: true // below edge 3
|
||||
}, {
|
||||
point: [10, 10.1], contains: false // above edge 3
|
||||
}/*, {
|
||||
point: [2.5, 5], contains: 1 // on edge 4
|
||||
}*/, {
|
||||
point: [2.4, 5], contains: false // left of edge 4
|
||||
}, {
|
||||
point: [2.6, 5], contains: true // right of edge 4
|
||||
}];
|
||||
|
||||
var c;
|
||||
for (var i = 0, ii = cases.length; i < ii; ++i) {
|
||||
c = cases[i];
|
||||
expect(ring.containsCoordinate(c.point)).to.be(c.contains);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.LinearRing.isClockwise()', function() {
|
||||
|
||||
var isClockwise = ol.geom.LinearRing.isClockwise;
|
||||
|
||||
it('returns true for clockwise coordinates', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for counter-clockwise coordinates', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true for mostly clockwise, self-intersecting ring', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [0, 1], [1.5, 1], [1.5, 1.5], [1, 1.5], [1, 0], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for mostly counter-clockwise, intersecting', function() {
|
||||
var coordinates = [
|
||||
[0, 0], [1, 0], [1, 1.5], [1.5, 1.5], [1.5, 1], [0, 1], [0, 0]
|
||||
];
|
||||
expect(isClockwise(coordinates)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.geom.LinearRing');
|
||||
102
old/test/spec/ol/geom/linestring.test.js
Normal file
102
old/test/spec/ol/geom/linestring.test.js
Normal file
@@ -0,0 +1,102 @@
|
||||
goog.provide('ol.test.geom.LineString');
|
||||
|
||||
describe('ol.geom.LineString', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a linestring from an array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line).to.be.a(ol.geom.LineString);
|
||||
expect(line).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
|
||||
var bounds = line.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setCoordinates()', function() {
|
||||
|
||||
it('updates the coordinates', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
expect(line.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||
});
|
||||
|
||||
it('invalidates bounds', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
expect(line.getBounds()).to.eql([30, 40, 50, 60]);
|
||||
});
|
||||
|
||||
it('triggers a change event', function(done) {
|
||||
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
expect(line.getBounds()).to.eql([10, 20, 30, 40]);
|
||||
goog.events.listen(line, 'change', function(evt) {
|
||||
expect(evt.target).to.equal(line);
|
||||
expect(evt.oldExtent).to.eql([10, 20, 30, 40]);
|
||||
expect(evt.target.getBounds()).to.eql([30, 40, 50, 60]);
|
||||
expect(evt.target.getCoordinates()).to.eql([[30, 40], [50, 60]]);
|
||||
done();
|
||||
});
|
||||
line.setCoordinates([[30, 40], [50, 60]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a linestring in place', function() {
|
||||
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
|
||||
line.transform(forward);
|
||||
expect(line.get(0, 0)).to.roughlyEqual(1113195, 1);
|
||||
expect(line.get(0, 1)).to.roughlyEqual(2273031, 1);
|
||||
expect(line.get(1, 0)).to.roughlyEqual(2226390, 1);
|
||||
expect(line.get(1, 1)).to.roughlyEqual(3503550, 1);
|
||||
expect(line.get(2, 0)).to.roughlyEqual(3339585, 1);
|
||||
expect(line.get(2, 1)).to.roughlyEqual(4865942, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a linestring in place', function() {
|
||||
var line = new ol.geom.LineString([
|
||||
[1113195, 2273031], [2226390, 3503550], [3339585, 4865942]
|
||||
]);
|
||||
line.transform(inverse);
|
||||
expect(line.get(0, 0)).to.roughlyEqual(10, 0.001);
|
||||
expect(line.get(0, 1)).to.roughlyEqual(20, 0.001);
|
||||
expect(line.get(1, 0)).to.roughlyEqual(20, 0.001);
|
||||
expect(line.get(1, 1)).to.roughlyEqual(30, 0.001);
|
||||
expect(line.get(2, 0)).to.roughlyEqual(30, 0.001);
|
||||
expect(line.get(2, 1)).to.roughlyEqual(40, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.proj');
|
||||
65
old/test/spec/ol/geom/multilinestring.test.js
Normal file
65
old/test/spec/ol/geom/multilinestring.test.js
Normal file
@@ -0,0 +1,65 @@
|
||||
goog.provide('ol.test.geom.MultiLineString');
|
||||
|
||||
describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiLineString);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of linestrings', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.LineString);
|
||||
expect(components[1]).to.be.a(ol.geom.LineString);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiLineString([
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(40);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var coordinates = [
|
||||
[[10, 20], [30, 40]],
|
||||
[[20, 30], [40, 50]]
|
||||
];
|
||||
var multi = new ol.geom.MultiLineString(coordinates);
|
||||
expect(multi.getCoordinates()).to.eql(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
86
old/test/spec/ol/geom/multipoint.test.js
Normal file
86
old/test/spec/ol/geom/multipoint.test.js
Normal file
@@ -0,0 +1,86 @@
|
||||
goog.provide('ol.test.geom.MultiPoint');
|
||||
|
||||
describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-point from an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiPoint);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of points', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(30);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(40);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
expect(multi.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a multi-point', function() {
|
||||
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
|
||||
multi.transform(forward);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(components[0].get(1)).to.roughlyEqual(2273031, 1);
|
||||
expect(components[1].get(0)).to.roughlyEqual(3339584, 1);
|
||||
expect(components[1].get(1)).to.roughlyEqual(4865942, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a multi-point', function() {
|
||||
var multi = new ol.geom.MultiPoint(
|
||||
[[1113195, 2273031], [3339584, 4865942]]);
|
||||
multi.transform(inverse);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components[0].get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(components[0].get(1)).to.roughlyEqual(20, 0.001);
|
||||
expect(components[1].get(0)).to.roughlyEqual(30, 0.001);
|
||||
expect(components[1].get(1)).to.roughlyEqual(40, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
122
old/test/spec/ol/geom/multipolygon.test.js
Normal file
122
old/test/spec/ol/geom/multipolygon.test.js
Normal file
@@ -0,0 +1,122 @@
|
||||
goog.provide('ol.test.geom.MultiPolygon');
|
||||
|
||||
describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
var outer1 = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1a = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner1b = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]],
|
||||
outer2 = [[10, 10], [20, 0], [20, 50], [10, 50], [10, 10]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a multi-linestring from an array', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
expect(multi).to.be.a(ol.geom.MultiPolygon);
|
||||
expect(multi).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
it('throws when given with insufficient dimensions', function() {
|
||||
expect(function() {
|
||||
var multi = new ol.geom.MultiPolygon([1]);
|
||||
multi = multi; // suppress gjslint warning about unused variable
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#components', function() {
|
||||
|
||||
it('is an array of polygons', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
|
||||
var components = multi.getComponents();
|
||||
expect(components.length).to.be(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Polygon);
|
||||
expect(components[1]).to.be.a(ol.geom.Polygon);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var multi = new ol.geom.MultiPolygon([
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]]);
|
||||
var bounds = multi.getBounds();
|
||||
expect(bounds[0]).to.be(0);
|
||||
expect(bounds[2]).to.be(20);
|
||||
expect(bounds[1]).to.be(0);
|
||||
expect(bounds[3]).to.be(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var coordinates = [
|
||||
[outer1, inner1a, inner1b],
|
||||
[outer2]
|
||||
];
|
||||
var multi = new ol.geom.MultiPolygon(coordinates);
|
||||
expect(multi.getCoordinates()).to.eql(coordinates);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('change event', function() {
|
||||
|
||||
var outer, inner;
|
||||
beforeEach(function() {
|
||||
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
});
|
||||
|
||||
it('is fired when outer ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
var bounds = multi.getBounds();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var outerOne = components[0].getRings()[0];
|
||||
var outerCoords = outerOne.getCoordinates();
|
||||
outerCoords[1][0] = 11;
|
||||
outerOne.setCoordinates(outerCoords);
|
||||
});
|
||||
|
||||
it('is fired when inner ring is modified', function(done) {
|
||||
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
|
||||
var components = multi.getComponents();
|
||||
var bounds = multi.getBounds();
|
||||
goog.events.listen(multi, 'change', function(evt) {
|
||||
expect(evt.target).to.be(multi);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var innerTwo = components[1].getRings()[1];
|
||||
var innerCoords = innerTwo.getCoordinates();
|
||||
innerCoords[1][0] = 3;
|
||||
innerTwo.setCoordinates(innerCoords);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Polygon');
|
||||
92
old/test/spec/ol/geom/point.test.js
Normal file
92
old/test/spec/ol/geom/point.test.js
Normal file
@@ -0,0 +1,92 @@
|
||||
goog.provide('ol.test.geom.Point');
|
||||
|
||||
describe('ol.geom.Point', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a point from an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point).to.be.a(ol.geom.Point);
|
||||
expect(point).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var bounds = point.getBounds();
|
||||
expect(bounds[0]).to.be(10);
|
||||
expect(bounds[2]).to.be(10);
|
||||
expect(bounds[1]).to.be(20);
|
||||
expect(bounds[3]).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.getCoordinates()).to.eql([10, 20]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setCoordinates()', function() {
|
||||
|
||||
it('updates the coordinates', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.setCoordinates([30, 40]);
|
||||
expect(point.getCoordinates()).to.eql([30, 40]);
|
||||
});
|
||||
|
||||
it('invalidates bounds', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.setCoordinates([30, 40]);
|
||||
expect(point.getBounds()).to.eql([30, 40, 30, 40]);
|
||||
});
|
||||
|
||||
it('triggers a change event', function(done) {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
expect(point.getBounds()).to.eql([10, 20, 10, 20]);
|
||||
goog.events.listen(point, 'change', function(evt) {
|
||||
expect(evt.target).to.equal(point);
|
||||
expect(evt.oldExtent).to.eql([10, 20, 10, 20]);
|
||||
expect(evt.target.getBounds()).to.eql([30, 40, 30, 40]);
|
||||
expect(evt.target.getCoordinates()).to.eql([30, 40]);
|
||||
done();
|
||||
});
|
||||
point.setCoordinates([30, 40]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
it('forward transforms a point in place', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
point.transform(forward);
|
||||
expect(point.get(0)).to.roughlyEqual(1113195, 1);
|
||||
expect(point.get(1)).to.roughlyEqual(2273031, 1);
|
||||
});
|
||||
|
||||
it('inverse transforms a point in place', function() {
|
||||
var point = new ol.geom.Point([1113195, 2273031]);
|
||||
point.transform(inverse);
|
||||
expect(point.get(0)).to.roughlyEqual(10, 0.001);
|
||||
expect(point.get(1)).to.roughlyEqual(20, 0.001);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
183
old/test/spec/ol/geom/polygon.test.js
Normal file
183
old/test/spec/ol/geom/polygon.test.js
Normal file
@@ -0,0 +1,183 @@
|
||||
goog.provide('ol.test.geom.Polygon');
|
||||
|
||||
describe('ol.geom.Polygon', function() {
|
||||
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a polygon from an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly).to.be.a(ol.geom.Polygon);
|
||||
expect(poly).to.be.a(ol.geom.Geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getRings()', function() {
|
||||
|
||||
it('returns an array of LinearRing', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var rings = poly.getRings();
|
||||
expect(rings.length).to.be(3);
|
||||
expect(rings[0]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[1]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[2]).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
var isClockwise = ol.geom.LinearRing.isClockwise;
|
||||
|
||||
it('forces exterior ring to be clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
expect(isClockwise(outer)).to.be(false);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer]);
|
||||
var ring = poly.getRings()[0];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(true);
|
||||
});
|
||||
|
||||
it('forces interior ring to be counter-clockwise', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
var inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
expect(isClockwise(inner)).to.be(true);
|
||||
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var ring = poly.getRings()[1];
|
||||
expect(isClockwise(ring.getCoordinates())).to.be(false);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#getBounds()', function() {
|
||||
|
||||
it('returns the bounding extent', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var bounds = poly.getBounds();
|
||||
expect(bounds[0]).to.be(0);
|
||||
expect(bounds[2]).to.be(10);
|
||||
expect(bounds[1]).to.be(0);
|
||||
expect(bounds[3]).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getCoordinates()', function() {
|
||||
|
||||
it('returns an array', function() {
|
||||
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
expect(poly.getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
|
||||
|
||||
var gg, sm;
|
||||
beforeEach(function() {
|
||||
gg = [
|
||||
[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]],
|
||||
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
[[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]]
|
||||
];
|
||||
|
||||
sm = [[
|
||||
[0, 0], [0, 1118890], [1113195, 1118890], [1113195, 0], [0, 0]
|
||||
], [
|
||||
[111319, 111325], [222639, 111325], [222639, 222684],
|
||||
[111319, 222684], [111319, 111325]
|
||||
], [
|
||||
[890556, 893464], [1001875, 893464], [1001875, 1006021],
|
||||
[890556, 1006021], [890556, 893464]
|
||||
]];
|
||||
|
||||
});
|
||||
|
||||
it('forward transforms a polygon in place', function() {
|
||||
|
||||
var poly = new ol.geom.Polygon(gg);
|
||||
poly.transform(forward);
|
||||
var coordinates = poly.getCoordinates();
|
||||
var ring;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var ring = coordinates[i];
|
||||
for (var j = 0, jj = ring.length; j < jj; ++j) {
|
||||
expect(ring[j][0]).to.roughlyEqual(sm[i][j][0], 1);
|
||||
expect(ring[j][1]).to.roughlyEqual(sm[i][j][1], 1);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
it('inverse transforms a polygon in place', function() {
|
||||
|
||||
var poly = new ol.geom.Polygon(sm);
|
||||
poly.transform(inverse);
|
||||
var coordinates = poly.getCoordinates();
|
||||
var ring;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
var ring = coordinates[i];
|
||||
for (var j = 0, jj = ring.length; j < jj; ++j) {
|
||||
expect(ring[j][0]).to.roughlyEqual(gg[i][j][0], 0.001);
|
||||
expect(ring[j][1]).to.roughlyEqual(gg[i][j][1], 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('change event', function() {
|
||||
|
||||
var outer, inner;
|
||||
beforeEach(function() {
|
||||
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
|
||||
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
|
||||
});
|
||||
|
||||
it('is fired when outer ring is modified', function(done) {
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var rings = poly.getRings();
|
||||
var bounds = poly.getBounds();
|
||||
goog.events.listen(poly, 'change', function(evt) {
|
||||
expect(evt.target).to.be(poly);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var outerCoords = rings[0].getCoordinates();
|
||||
outerCoords[1][0] = 11;
|
||||
rings[0].setCoordinates(outerCoords);
|
||||
});
|
||||
|
||||
it('is fired when inner ring is modified', function(done) {
|
||||
var poly = new ol.geom.Polygon([outer, inner]);
|
||||
var rings = poly.getRings();
|
||||
var bounds = poly.getBounds();
|
||||
goog.events.listen(poly, 'change', function(evt) {
|
||||
expect(evt.target).to.be(poly);
|
||||
expect(evt.oldExtent).to.eql(bounds);
|
||||
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
|
||||
done();
|
||||
});
|
||||
|
||||
var innerCoords = rings[1].getCoordinates();
|
||||
innerCoords[1][0] = 3;
|
||||
rings[1].setCoordinates(innerCoords);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.proj');
|
||||
344
old/test/spec/ol/interaction/drawinteraction.test.js
Normal file
344
old/test/spec/ol/interaction/drawinteraction.test.js
Normal file
@@ -0,0 +1,344 @@
|
||||
goog.provide('ol.test.interaction.Draw');
|
||||
|
||||
describe('ol.interaction.Draw', function() {
|
||||
var target, map, vector;
|
||||
|
||||
var width = 360;
|
||||
var height = 180;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
var style = target.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '-1000px';
|
||||
style.top = '-1000px';
|
||||
style.width = width + 'px';
|
||||
style.height = height + 'px';
|
||||
document.body.appendChild(target);
|
||||
vector = new ol.layer.Vector({source: new ol.source.Vector({})});
|
||||
map = new ol.Map({
|
||||
target: target,
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
layers: [vector],
|
||||
view: new ol.View2D({
|
||||
projection: 'EPSG:4326',
|
||||
center: [0, 0],
|
||||
resolution: 1
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(map);
|
||||
document.body.removeChild(target);
|
||||
});
|
||||
|
||||
/**
|
||||
* Simulates a browser event on the map viewport. The client x/y location
|
||||
* will be adjusted as if the map were centered at 0,0.
|
||||
* @param {string} type Event type.
|
||||
* @param {number} x Horizontal offset from map center.
|
||||
* @param {number} y Vertical offset from map center.
|
||||
*/
|
||||
function simulateEvent(type, x, y) {
|
||||
var viewport = map.getViewport();
|
||||
// calculated in case body has top < 0 (test runner with small window)
|
||||
var position = goog.style.getClientPosition(viewport);
|
||||
var event = new goog.events.BrowserEvent({
|
||||
type: type,
|
||||
clientX: position.x + x + width / 2,
|
||||
clientY: position.y + y + height / 2
|
||||
});
|
||||
goog.events.fireListeners(viewport, type, false, event);
|
||||
}
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new interaction', function() {
|
||||
var draw = new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.POINT
|
||||
});
|
||||
expect(draw).to.be.a(ol.interaction.Draw);
|
||||
expect(draw).to.be.a(ol.interaction.Interaction);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing points', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.POINT
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws a point on click', function() {
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.Point);
|
||||
expect(geometry.getCoordinates()).to.eql([10, -20]);
|
||||
});
|
||||
|
||||
it('does not draw a point with a significant drag', function() {
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mousemove', 15, 20);
|
||||
simulateEvent('mouseup', 15, 20);
|
||||
simulateEvent('click', 15, 20);
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multipoints', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.MULTIPOINT
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws multipoint on click', function() {
|
||||
simulateEvent('mousemove', 30, 15);
|
||||
simulateEvent('mousedown', 30, 15);
|
||||
simulateEvent('mouseup', 30, 15);
|
||||
simulateEvent('click', 30, 15);
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.MultiPoint);
|
||||
expect(geometry.getCoordinates()).to.eql([[30, -15]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing linestrings', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.LINESTRING
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws linestring with clicks, finishing on last point', function() {
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// finish on second point
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.LineString);
|
||||
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
|
||||
});
|
||||
|
||||
it('does not add a point with a significant drag', function() {
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// drag map
|
||||
simulateEvent('mousemove', 15, 20);
|
||||
simulateEvent('mousedown', 15, 20);
|
||||
simulateEvent('mousemove', 20, 20);
|
||||
simulateEvent('mouseup', 20, 20);
|
||||
simulateEvent('click', 20, 20);
|
||||
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// finish on second point
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.LineString);
|
||||
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multi-linestrings', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.MULTILINESTRING
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws multi with clicks, finishing on last point', function() {
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// finish on second point
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.MultiLineString);
|
||||
expect(geometry.getCoordinates()).to.eql([[[10, -20], [30, -20]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing polygons', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.POLYGON
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws polygon with clicks, finishing on first point', function() {
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// third point
|
||||
simulateEvent('mousemove', 30, 10);
|
||||
simulateEvent('mousedown', 30, 10);
|
||||
simulateEvent('mouseup', 30, 10);
|
||||
simulateEvent('click', 30, 10);
|
||||
|
||||
// finish on first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.Polygon);
|
||||
|
||||
// note that order is forced clockwise (despite drawing counter-clockwise)
|
||||
expect(geometry.getCoordinates()).to.eql([
|
||||
[[10, -20], [30, -10], [30, -20], [10, -20]]
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('drawing multi-polygons', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
map.addInteraction(new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
type: ol.geom.GeometryType.MULTIPOLYGON
|
||||
}));
|
||||
});
|
||||
|
||||
it('draws multi with clicks, finishing on first point', function() {
|
||||
// first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
// second point
|
||||
simulateEvent('mousemove', 30, 20);
|
||||
simulateEvent('mousedown', 30, 20);
|
||||
simulateEvent('mouseup', 30, 20);
|
||||
simulateEvent('click', 30, 20);
|
||||
|
||||
// third point
|
||||
simulateEvent('mousemove', 30, 10);
|
||||
simulateEvent('mousedown', 30, 10);
|
||||
simulateEvent('mouseup', 30, 10);
|
||||
simulateEvent('click', 30, 10);
|
||||
|
||||
// finish on first point
|
||||
simulateEvent('mousemove', 10, 20);
|
||||
simulateEvent('mousedown', 10, 20);
|
||||
simulateEvent('mouseup', 10, 20);
|
||||
simulateEvent('click', 10, 20);
|
||||
|
||||
var features = vector.getFeatures();
|
||||
expect(features).to.have.length(1);
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.MultiPolygon);
|
||||
var coordinates = geometry.getCoordinates();
|
||||
expect(coordinates).to.have.length(1);
|
||||
|
||||
// note that order is forced clockwise (despite drawing counter-clockwise)
|
||||
expect(coordinates[0]).to.eql([
|
||||
[[10, -20], [30, -10], [30, -20], [10, -20]]
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.BrowserEvent');
|
||||
goog.require('goog.style');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.interaction.Draw');
|
||||
goog.require('ol.interaction.Interaction');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
81
old/test/spec/ol/interaction/selectinteraction.test.js
Normal file
81
old/test/spec/ol/interaction/selectinteraction.test.js
Normal file
@@ -0,0 +1,81 @@
|
||||
goog.provide('ol.test.interaction.Select');
|
||||
|
||||
describe('ol.interaction.Select', function() {
|
||||
var map, target, select, vector, features;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
target.style.width = '256px';
|
||||
target.style.height = '256px';
|
||||
document.body.appendChild(target);
|
||||
map = new ol.Map({
|
||||
target: target
|
||||
});
|
||||
features = ol.parser.GeoJSON.read(JSON.stringify({
|
||||
'type': 'FeatureCollection',
|
||||
'features': [{
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [-1, 1]
|
||||
}
|
||||
}, {
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Point',
|
||||
'coordinates': [1, -1]
|
||||
}
|
||||
}]
|
||||
}));
|
||||
vector = new ol.layer.Vector({source: new ol.source.Vector({})});
|
||||
vector.addFeatures(features);
|
||||
select = new ol.interaction.Select({
|
||||
layers: [vector]
|
||||
});
|
||||
map.getInteractions().push(select);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(select);
|
||||
goog.dispose(map);
|
||||
document.body.removeChild(target);
|
||||
select = null;
|
||||
map = null;
|
||||
target = null;
|
||||
});
|
||||
|
||||
describe('#select', function() {
|
||||
|
||||
var selectedFeaturesFilter = function(feature) {
|
||||
return feature.getRenderIntent() == 'selected';
|
||||
};
|
||||
|
||||
it('toggles selection of features', function() {
|
||||
select.select(map, [features], [vector]);
|
||||
expect(vector.getFeatures(selectedFeaturesFilter).length).to.be(2);
|
||||
select.select(map, [features], [vector]);
|
||||
expect(vector.getFeatures(selectedFeaturesFilter).length).to.be(0);
|
||||
});
|
||||
|
||||
it('can append features to an existing selection', function() {
|
||||
select.select(map, [[features[0]]], [vector], true);
|
||||
select.select(map, [[features[1]]], [vector]);
|
||||
expect(vector.getFeatures(selectedFeaturesFilter).length).to.be(2);
|
||||
});
|
||||
|
||||
it('can clear a selection before selecting new features', function() {
|
||||
select.select(map, [[features[0]]], [vector], true);
|
||||
select.select(map, [[features[1]]], [vector], true);
|
||||
expect(vector.getFeatures(selectedFeaturesFilter).length).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.interaction.Select');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
goog.require('ol.source.Vector');
|
||||
194
old/test/spec/ol/layer/vectorlayer.test.js
Normal file
194
old/test/spec/ol/layer/vectorlayer.test.js
Normal file
@@ -0,0 +1,194 @@
|
||||
goog.provide('ol.test.layer.Vector');
|
||||
|
||||
describe('ol.layer.Vector', function() {
|
||||
|
||||
describe('#addFeatures()', function() {
|
||||
|
||||
it('allows adding features', function() {
|
||||
var layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({})
|
||||
});
|
||||
layer.addFeatures([new ol.Feature(), new ol.Feature()]);
|
||||
expect(goog.object.getCount(layer.featureCache_.getFeaturesObject()))
|
||||
.to.eql(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.layer.FeatureCache#getFeaturesObject()', function() {
|
||||
|
||||
var layer, features;
|
||||
|
||||
beforeEach(function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.0, 48.0])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[17.0, 49.0], [17.1, 49.1]])
|
||||
})
|
||||
];
|
||||
layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({})
|
||||
});
|
||||
layer.addFeatures(features);
|
||||
});
|
||||
|
||||
it('returns the features in an object', function() {
|
||||
var featuresObject = layer.featureCache_.getFeaturesObject();
|
||||
expect(goog.object.getCount(featuresObject)).to.eql(features.length);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#groupFeaturesBySymbolizerLiteral()', function() {
|
||||
|
||||
var layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
projection: ol.proj.get('EPSG:4326')
|
||||
}),
|
||||
style: new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
width: 2,
|
||||
color: ol.expr.parse('colorProperty'),
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
});
|
||||
var features;
|
||||
|
||||
it('groups equal symbolizers', function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, -10], [10, 10]]),
|
||||
colorProperty: '#BADA55'
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, 10], [10, -10]]),
|
||||
colorProperty: '#013'
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[10, -10], [-10, -10]]),
|
||||
colorProperty: '#013'
|
||||
})
|
||||
];
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features, 1);
|
||||
expect(groups.length).to.be(2);
|
||||
expect(groups[0][0].length).to.be(1);
|
||||
expect(groups[0][1].color).to.be('#BADA55');
|
||||
expect(groups[1][0].length).to.be(2);
|
||||
expect(groups[1][1].color).to.be('#013');
|
||||
});
|
||||
|
||||
it('groups equal symbolizers also when defined on features', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: ol.expr.parse('colorProperty'),
|
||||
opacity: 1
|
||||
});
|
||||
var anotherSymbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var featureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, -10], [-10, 10]]),
|
||||
colorProperty: '#BADA55'
|
||||
});
|
||||
featureWithSymbolizers.setSymbolizers([symbolizer]);
|
||||
var anotherFeatureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, 10], [-10, -10]])
|
||||
});
|
||||
anotherFeatureWithSymbolizers.setSymbolizers([anotherSymbolizer]);
|
||||
features.push(featureWithSymbolizers, anotherFeatureWithSymbolizers);
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features, 1);
|
||||
expect(groups).to.have.length(3);
|
||||
expect(groups[2][0].length).to.be(2);
|
||||
expect(groups[2][1].width).to.be(3);
|
||||
|
||||
});
|
||||
|
||||
it('sorts groups by zIndex', function() {
|
||||
var symbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 1
|
||||
});
|
||||
var anotherSymbolizer = new ol.style.Stroke({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1
|
||||
});
|
||||
var featureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, -10], [-10, 10]])
|
||||
});
|
||||
featureWithSymbolizers.setSymbolizers([symbolizer]);
|
||||
var anotherFeatureWithSymbolizers = new ol.Feature({
|
||||
g: new ol.geom.LineString([[-10, 10], [-10, -10]])
|
||||
});
|
||||
anotherFeatureWithSymbolizers.setSymbolizers([anotherSymbolizer]);
|
||||
features = [featureWithSymbolizers, anotherFeatureWithSymbolizers];
|
||||
|
||||
var groups = layer.groupFeaturesBySymbolizerLiteral(features, 1);
|
||||
expect(groups).to.have.length(2);
|
||||
expect(groups[0][1].zIndex).to.be(0);
|
||||
expect(groups[1][1].zIndex).to.be(1);
|
||||
});
|
||||
|
||||
goog.dispose(layer);
|
||||
|
||||
});
|
||||
|
||||
describe('ol.layer.VectorEvent', function() {
|
||||
|
||||
var layer, features;
|
||||
|
||||
beforeEach(function() {
|
||||
features = [
|
||||
new ol.Feature({
|
||||
g: new ol.geom.Point([16.0, 48.0])
|
||||
}),
|
||||
new ol.Feature({
|
||||
g: new ol.geom.LineString([[17.0, 49.0], [17.1, 49.1]])
|
||||
})
|
||||
];
|
||||
layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({})
|
||||
});
|
||||
layer.addFeatures(features);
|
||||
});
|
||||
|
||||
it('dispatches events on feature change', function(done) {
|
||||
layer.on('featurechange', function(evt) {
|
||||
expect(evt.features[0]).to.be(features[0]);
|
||||
expect(evt.extents[0]).to.eql(features[0].getGeometry().getBounds());
|
||||
done();
|
||||
});
|
||||
features[0].set('foo', 'bar');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
494
old/test/spec/ol/parser/geojson.test.js
Normal file
494
old/test/spec/ol/parser/geojson.test.js
Normal file
@@ -0,0 +1,494 @@
|
||||
goog.provide('ol.test.parser.GeoJSON');
|
||||
|
||||
describe('ol.parser.GeoJSON', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
|
||||
var data = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [
|
||||
{
|
||||
'type': 'Feature',
|
||||
'properties': {
|
||||
'LINK_ID': 573730499,
|
||||
'RP_TYPE': 14,
|
||||
'RP_FUNC': 0,
|
||||
'DIRECTION': 2,
|
||||
'LOGKOD': '',
|
||||
'CHANGED': '',
|
||||
'USERID': '',
|
||||
'ST_NAME': '',
|
||||
'L_REFADDR': '',
|
||||
'L_NREFADDR': '',
|
||||
'R_REFADDR': '',
|
||||
'R_NREFADDR': '',
|
||||
'SPEED_CAT': '7',
|
||||
'ZIPCODE': '59330',
|
||||
'SHAPE_LEN': 46.3826
|
||||
},
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': [
|
||||
[1549497.66985, 6403707.96],
|
||||
[1549491.1, 6403710.1],
|
||||
[1549488.03995, 6403716.7504],
|
||||
[1549488.5401, 6403724.5504],
|
||||
[1549494.37985, 6403733.54],
|
||||
[1549499.6799, 6403738.0504],
|
||||
[1549506.22, 6403739.2504]
|
||||
]
|
||||
}
|
||||
}, {
|
||||
'type': 'Feature',
|
||||
'properties': {
|
||||
'LINK_ID': 30760556,
|
||||
'RP_TYPE': 12,
|
||||
'RP_FUNC': 1,
|
||||
'DIRECTION': 0,
|
||||
'LOGKOD': '',
|
||||
'CHANGED': '',
|
||||
'USERID': '',
|
||||
'ST_NAME': 'BRUNNSGATAN',
|
||||
'L_REFADDR': '24',
|
||||
'L_NREFADDR': '16',
|
||||
'R_REFADDR': '',
|
||||
'R_NREFADDR': '',
|
||||
'SPEED_CAT': '7',
|
||||
'ZIPCODE': '59330',
|
||||
'SHAPE_LEN': 70.3106
|
||||
},
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': [
|
||||
[1549754.2769, 6403854.8024],
|
||||
[1549728.45985, 6403920.2]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
describe('#write()', function() {
|
||||
|
||||
it('encodes point', function() {
|
||||
var point = new ol.geom.Point([10, 20]);
|
||||
var geojson = parser.write(point);
|
||||
expect(point.getCoordinates()).to.eql(
|
||||
parser.read(geojson).getCoordinates());
|
||||
});
|
||||
|
||||
it('encodes linestring', function() {
|
||||
var linestring = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||
var geojson = parser.write(linestring);
|
||||
expect(linestring.getCoordinates()).to.eql(
|
||||
parser.read(geojson).getCoordinates());
|
||||
});
|
||||
|
||||
it('encodes polygon', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||
var polygon = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||
var geojson = parser.write(polygon);
|
||||
expect(polygon.getCoordinates()).to.eql(
|
||||
parser.read(geojson).getCoordinates());
|
||||
});
|
||||
|
||||
it('encodes geometry collection', function() {
|
||||
var collection = new ol.geom.GeometryCollection([
|
||||
new ol.geom.Point([10, 20]),
|
||||
new ol.geom.LineString([[30, 40], [50, 60]])
|
||||
]);
|
||||
var geojson = parser.write(collection);
|
||||
var got = parser.read(geojson);
|
||||
var components = collection.getComponents();
|
||||
expect(components.length).to.equal(got.length);
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
expect(components[i].getCoordinates()).to.eql(got[i].getCoordinates());
|
||||
}
|
||||
});
|
||||
|
||||
it('encodes feature collection', function() {
|
||||
var str = JSON.stringify(data),
|
||||
array = parser.read(str);
|
||||
var geojson = parser.write(array);
|
||||
var result = parser.read(geojson);
|
||||
expect(array.length).to.equal(result.length);
|
||||
var got, exp, gotAttr, expAttr;
|
||||
for (var i = 0, ii = array.length; i < ii; ++i) {
|
||||
got = array[i];
|
||||
exp = result[i];
|
||||
expect(got.getGeometry().getCoordinates()).to.eql(
|
||||
exp.getGeometry().getCoordinates());
|
||||
gotAttr = got.getAttributes();
|
||||
delete gotAttr.geometry;
|
||||
expAttr = exp.getAttributes();
|
||||
delete expAttr.geometry;
|
||||
expect(gotAttr).to.eql(expAttr);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#read()', function() {
|
||||
|
||||
it('parses point', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'Point',
|
||||
coordinates: [10, 20]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).to.be.a(ol.geom.Point);
|
||||
expect(obj.getCoordinates()).to.eql([10, 20]);
|
||||
});
|
||||
|
||||
it('parses linestring', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'LineString',
|
||||
coordinates: [[10, 20], [30, 40]]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).to.be.a(ol.geom.LineString);
|
||||
expect(obj.getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||
});
|
||||
|
||||
it('parses polygon', function() {
|
||||
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]],
|
||||
str = JSON.stringify({
|
||||
type: 'Polygon',
|
||||
coordinates: [outer, inner1, inner2]
|
||||
});
|
||||
|
||||
var obj = parser.read(str);
|
||||
expect(obj).to.be.a(ol.geom.Polygon);
|
||||
var rings = obj.getRings();
|
||||
expect(rings.length).to.be(3);
|
||||
expect(rings[0]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[1]).to.be.a(ol.geom.LinearRing);
|
||||
expect(rings[2]).to.be.a(ol.geom.LinearRing);
|
||||
});
|
||||
|
||||
it('parses geometry collection', function() {
|
||||
var str = JSON.stringify({
|
||||
type: 'GeometryCollection',
|
||||
geometries: [
|
||||
{type: 'Point', coordinates: [10, 20]},
|
||||
{type: 'LineString', coordinates: [[30, 40], [50, 60]]}
|
||||
]
|
||||
});
|
||||
|
||||
var array = parser.read(str);
|
||||
expect(array.length).to.be(2);
|
||||
expect(array[0]).to.be.a(ol.geom.Point);
|
||||
expect(array[1]).to.be.a(ol.geom.LineString);
|
||||
});
|
||||
|
||||
it('parses feature collection', function() {
|
||||
var str = JSON.stringify(data),
|
||||
array = parser.read(str);
|
||||
|
||||
expect(array.length).to.be(2);
|
||||
|
||||
var first = array[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('LINK_ID')).to.be(573730499);
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).to.be.a(ol.geom.LineString);
|
||||
|
||||
var second = array[1];
|
||||
expect(second).to.be.a(ol.Feature);
|
||||
expect(second.get('ST_NAME')).to.be('BRUNNSGATAN');
|
||||
var secondGeom = second.getGeometry();
|
||||
expect(secondGeom).to.be.a(ol.geom.LineString);
|
||||
});
|
||||
|
||||
it('parses countries.geojson', function(done) {
|
||||
afterLoadText('spec/ol/parser/geojson/countries.geojson', function(text) {
|
||||
var result = parser.read(text);
|
||||
expect(result.length).to.be(179);
|
||||
|
||||
var first = result[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('name')).to.be('Afghanistan');
|
||||
expect(first.getId()).to.be('AFG');
|
||||
var firstGeom = first.getGeometry();
|
||||
expect(firstGeom).to.be.a(ol.geom.Polygon);
|
||||
expect(ol.extent.equals(firstGeom.getBounds(),
|
||||
[60.52843, 29.318572, 75.158028, 38.486282]))
|
||||
.to.be(true);
|
||||
|
||||
var last = result[178];
|
||||
expect(last).to.be.a(ol.Feature);
|
||||
expect(last.get('name')).to.be('Zimbabwe');
|
||||
expect(last.getId()).to.be('ZWE');
|
||||
var lastGeom = last.getGeometry();
|
||||
expect(lastGeom).to.be.a(ol.geom.Polygon);
|
||||
expect(ol.extent.equals(lastGeom.getBounds(),
|
||||
[25.264226, -22.271612, 32.849861, -15.507787]))
|
||||
.to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseAsFeatureCollection_()', function() {
|
||||
|
||||
it('generates an array of features for FeatureCollection', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'FeatureCollection',
|
||||
features: [{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
foo: 'bar'
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
}
|
||||
}, {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
bam: 'baz'
|
||||
},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
}]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(2);
|
||||
|
||||
var first = features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('foo')).to.be('bar');
|
||||
expect(first.getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
var second = features[1];
|
||||
expect(second).to.be.a(ol.Feature);
|
||||
expect(second.get('bam')).to.be('baz');
|
||||
expect(second.getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('reads named crs from top-level object', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'FeatureCollection',
|
||||
crs: {
|
||||
type: 'name',
|
||||
properties: {
|
||||
name: 'EPSG:1234'
|
||||
}
|
||||
},
|
||||
features: [{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
foo: 'bar'
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
}
|
||||
}, {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
bam: 'baz'
|
||||
},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
}]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(2);
|
||||
|
||||
var first = features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('foo')).to.be('bar');
|
||||
expect(first.getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
var second = features[1];
|
||||
expect(second).to.be.a(ol.Feature);
|
||||
expect(second.get('bam')).to.be('baz');
|
||||
expect(second.getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:1234');
|
||||
});
|
||||
|
||||
it('accepts null crs', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'FeatureCollection',
|
||||
crs: null,
|
||||
features: [{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
foo: 'bar'
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
}
|
||||
}, {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
bam: 'baz'
|
||||
},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
}]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(2);
|
||||
|
||||
var first = features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('foo')).to.be('bar');
|
||||
expect(first.getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
var second = features[1];
|
||||
expect(second).to.be.a(ol.Feature);
|
||||
expect(second.get('bam')).to.be('baz');
|
||||
expect(second.getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('generates an array of features for Feature', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
bam: 'baz'
|
||||
},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
var first = features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('bam')).to.be('baz');
|
||||
expect(first.getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('generates an array of features for GeometryCollection', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'GeometryCollection',
|
||||
geometries: [{
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
}, {
|
||||
type: 'LineString',
|
||||
coordinates: [[3, 4], [5, 6]]
|
||||
}, {
|
||||
type: 'Polygon',
|
||||
coordinates: [[[7, 8], [9, 10], [11, 12], [7, 8]]]
|
||||
}]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(3);
|
||||
|
||||
expect(features[0].getGeometry()).to.be.a(ol.geom.Point);
|
||||
expect(features[1].getGeometry()).to.be.a(ol.geom.LineString);
|
||||
expect(features[2].getGeometry()).to.be.a(ol.geom.Polygon);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('generates an array of features for Point', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
expect(features[0].getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('generates an array of features for LineString', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'LineString',
|
||||
coordinates: [[3, 4], [5, 6]]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
expect(features[0].getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('generates an array of features for Polygon', function() {
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'Polygon',
|
||||
coordinates: [[[7, 8], [9, 10], [11, 12], [7, 8]]]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json);
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
expect(features[0].getGeometry()).to.be.a(ol.geom.Polygon);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
181
old/test/spec/ol/parser/geojson/countries.geojson
Normal file
181
old/test/spec/ol/parser/geojson/countries.geojson
Normal file
File diff suppressed because one or more lines are too long
130
old/test/spec/ol/parser/gpx.test.js
Normal file
130
old/test/spec/ol/parser/gpx.test.js
Normal file
@@ -0,0 +1,130 @@
|
||||
goog.provide('ol.test.parser.gpx');
|
||||
|
||||
describe('ol.parser.gpx', function() {
|
||||
|
||||
var parser = new ol.parser.GPX();
|
||||
|
||||
describe('Test GPX parser', function() {
|
||||
it('Read works correctly', function(done) {
|
||||
var url = 'spec/ol/parser/gpx/data.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
// waypoint feature
|
||||
var feature = obj.features[0];
|
||||
var geom = feature.getGeometry();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||
expect(geom.getCoordinates()).to.eql([-0.1853562259, 51.3697845627]);
|
||||
// route feature
|
||||
feature = obj.features[1];
|
||||
geom = feature.getGeometry();
|
||||
var attributes = feature.getAttributes();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINESTRING);
|
||||
expect(geom.getCoordinates()).to.eql([[-0.1829991904, 51.3761803674],
|
||||
[-0.1758887005, 51.3697894659], [-0.1833202965, 51.3639790884],
|
||||
[-0.1751119509, 51.3567607069]]);
|
||||
expect(attributes['name']).to.eql('Route8');
|
||||
expect(attributes['type']).to.eql('Route');
|
||||
// track feature
|
||||
feature = obj.features[2];
|
||||
geom = feature.getGeometry();
|
||||
attributes = feature.getAttributes();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINESTRING);
|
||||
expect(geom.getCoordinates()).to.eql([[-0.1721292044, 51.3768216433],
|
||||
[-0.1649230916, 51.370833767], [-0.1736741378, 51.3644368725],
|
||||
[-0.166259525, 51.3576354272]]);
|
||||
expect(attributes['name']).to.eql('Track');
|
||||
expect(attributes['type']).to.eql('Track');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Write works correctly for points', function() {
|
||||
var feature1 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature1.setGeometry(new ol.geom.Point([-111.04, 45.68]));
|
||||
var feature2 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature2.setGeometry(new ol.geom.Point([-112.04, 45.68]));
|
||||
var output = parser.write({features: [feature1, feature2]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/' +
|
||||
'GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/' +
|
||||
'XMLSchema-instance"><wpt lon="-111.04" lat="45.68"><name>foo' +
|
||||
'</name><desc>bar</desc></wpt><wpt lon="-112.04" lat="45.68">' +
|
||||
'<name>foo</name><desc>bar</desc></wpt></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for lines', function() {
|
||||
var feature1 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature1.setGeometry(new ol.geom.LineString([[-111.04, 45.68],
|
||||
[-112.04, 45.68]]));
|
||||
var feature2 = new ol.Feature({name: 'dude', description: 'truite'});
|
||||
feature2.setGeometry(new ol.geom.LineString([[1, 2], [3, 4]]));
|
||||
var output = parser.write({features: [feature1, feature2]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/' +
|
||||
'1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/' +
|
||||
'XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg>' +
|
||||
'<trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="' +
|
||||
'45.68"/></trkseg></trk><trk><name>dude</name><desc>truite</desc>' +
|
||||
'<trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg>' +
|
||||
'</trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for multilines', function() {
|
||||
var multi = new ol.geom.MultiLineString([[[-111.04, 45.68],
|
||||
[-112.04, 45.68]], [[1, 2], [3, 4]]]);
|
||||
var feature = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature.setGeometry(multi);
|
||||
var output = parser.write({features: [feature]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/' +
|
||||
'1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-' +
|
||||
'instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt' +
|
||||
' lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/>' +
|
||||
'</trkseg><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/>' +
|
||||
'</trkseg></trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for polygon', function() {
|
||||
var polygon = new ol.geom.Polygon([[[-111.04, 45.68],
|
||||
[-112.04, 45.68], [-111.04, 45.68]]]);
|
||||
var feature = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature.setGeometry(polygon);
|
||||
var output = parser.write({features: [feature]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1"' +
|
||||
' version="1.1" creator="OpenLayers" xsi:schemaLocation="http://' +
|
||||
'www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/' +
|
||||
'gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
'<trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04"' +
|
||||
' lat="45.68"/><trkpt lon="-112.04" lat="45.68"/><trkpt lon="' +
|
||||
'-111.04" lat="45.68"/></trkseg></trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for metadata', function() {
|
||||
var output = parser.write({features: [], metadata: {'name': 'foo',
|
||||
'desc': 'bar'}});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="http://' +
|
||||
'www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/' +
|
||||
'gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
'<metadata><name>foo</name><desc>bar</desc></metadata></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.GPX');
|
||||
1
old/test/spec/ol/parser/gpx/data.xml
Normal file
1
old/test/spec/ol/parser/gpx/data.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?><gpx version="1.1" creator="Memory-Map 5.1.3.715 http://www.memory-map.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"><wpt lat="51.3697845627" lon="-0.1853562259"><name>Mark</name><sym><![CDATA[Flag]]></sym><type><![CDATA[Marks]]></type></wpt><rte><name><![CDATA[Route8]]></name><type><![CDATA[Route]]></type><rtept lat="51.3761803674" lon="-0.1829991904"><name><![CDATA[WP0801]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3697894659" lon="-0.1758887005"><name><![CDATA[WP0802]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3639790884" lon="-0.1833202965"><name><![CDATA[WP0803]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3567607069" lon="-0.1751119509"><name><![CDATA[WP0804]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept></rte><trk><name><![CDATA[Track]]></name><type><![CDATA[Track]]></type><trkseg><trkpt lat="51.3768216433" lon="-0.1721292044"></trkpt><trkpt lat="51.3708337670" lon="-0.1649230916"></trkpt><trkpt lat="51.3644368725" lon="-0.1736741378"></trkpt><trkpt lat="51.3576354272" lon="-0.1662595250"></trkpt></trkseg></trk></gpx>
|
||||
378
old/test/spec/ol/parser/kml.test.js
Normal file
378
old/test/spec/ol/parser/kml.test.js
Normal file
@@ -0,0 +1,378 @@
|
||||
goog.provide('ol.test.parser.KML');
|
||||
|
||||
describe('ol.parser.KML', function() {
|
||||
|
||||
var parser = new ol.parser.KML();
|
||||
|
||||
describe('Test KML parser', function() {
|
||||
it('Polygon read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/polygon.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(obj.features.length).to.eql(1);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
expect(obj.features[0].getId()).to.eql('KML.Polygon');
|
||||
expect(geom instanceof ol.geom.Polygon).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Linestring read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/linestring.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(obj.features.length).to.eql(2);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
expect(geom instanceof ol.geom.LineString).to.be.ok();
|
||||
geom = obj.features[1].getGeometry();
|
||||
expect(geom instanceof ol.geom.LineString).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Point read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/point.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(obj.features.length).to.eql(1);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
expect(geom instanceof ol.geom.Point).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('NetworkLink read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/networklink.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 1});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(obj) {
|
||||
expect(obj.features.length).to.eql(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('NetworkLink read correctly [recursively]', function(done) {
|
||||
var url = 'spec/ol/parser/kml/networklink_depth.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 2});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(obj) {
|
||||
expect(obj.features.length).to.eql(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('NetworkLink maxDepth', function(done) {
|
||||
var url = 'spec/ol/parser/kml/networklink_depth.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({maxDepth: 1});
|
||||
// we need to supply a callback to get visited NetworkLinks
|
||||
p.read(xml, function(obj) {
|
||||
// since maxDepth is 1, we will not get to the second feature
|
||||
expect(obj.features.length).to.eql(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('Extended data read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/extended_data.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features[0].get('name')).to.eql('Extended data placemark');
|
||||
var description = 'Attached to the ground. Intelligently places ' +
|
||||
'itself \n at the height of the underlying terrain.';
|
||||
expect(obj.features[0].get('description')).to.eql(description);
|
||||
expect(obj.features[0].get('foo')).to.eql('bar');
|
||||
expect(obj.features[0].getId()).to.eql('foobarbaz');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Extended data read correctly [2]', function(done) {
|
||||
var url = 'spec/ol/parser/kml/extended_data2.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var feature = obj.features[0];
|
||||
expect(feature.get('TrailHeadName')).to.eql('Pi in the sky');
|
||||
expect(feature.get('TrailLength')).to.eql('3.14159');
|
||||
expect(feature.get('ElevationGain')).to.eql('10');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Multi geometry read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/multigeometry.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
var output = parser.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(geom instanceof ol.geom.MultiLineString).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Discrete multi geometry read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/kml/multigeometry_discrete.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
var components = geom.getComponents();
|
||||
expect(geom instanceof ol.geom.GeometryCollection).to.be.ok();
|
||||
expect(components.length).to.eql(2);
|
||||
expect(components[0] instanceof ol.geom.LineString).to.be.ok();
|
||||
expect(components[1] instanceof ol.geom.Point).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Test extract tracks', function(done) {
|
||||
var url = 'spec/ol/parser/kml/macnoise.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({extractStyles: true,
|
||||
trackAttributes: ['speed', 'num']});
|
||||
var obj = p.read(xml);
|
||||
expect(obj.features.length).to.be(170);
|
||||
var attr = obj.features[4].getAttributes();
|
||||
// standard track point attributes
|
||||
expect(attr.when).to.be.a(Date);
|
||||
expect(attr.when.getTime()).to.be(1272736815000);
|
||||
expect(attr.altitude).to.be(1006);
|
||||
expect(attr.heading).to.be(230);
|
||||
expect(attr.tilt).to.be(0);
|
||||
expect(attr.roll).to.be(0);
|
||||
expect(attr.name).to.be('B752');
|
||||
expect(attr.adflag).to.be('A');
|
||||
expect(attr.flightid).to.be('DAL2973');
|
||||
expect(attr.speed).to.be('166');
|
||||
expect(attr.num).to.be('50');
|
||||
var geom = obj.features[4].getGeometry();
|
||||
expect(geom.get(0)).to.be(-93.0753620391713);
|
||||
expect(geom.get(1)).to.be(44.9879724110872);
|
||||
expect(geom.get(2)).to.be(1006);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Test CDATA attributes', function() {
|
||||
var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document>' +
|
||||
'<Placemark><name><![CDATA[Pezinok]]> </name><description>' +
|
||||
'<![CDATA[Full of text.]]></description><styleUrl>#rel1.0' +
|
||||
'</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates>' +
|
||||
'</Point></Placemark></Document></kml>';
|
||||
var obj = parser.read(cdata);
|
||||
expect(obj.features[0].get('description')).to.eql('Full of text.');
|
||||
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
||||
});
|
||||
|
||||
it('handles line style (read / write)', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
||||
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
|
||||
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd"> ' +
|
||||
'<Document><Placemark><Style><LineStyle> <color>870000ff</color> ' +
|
||||
'<width>10</width> </LineStyle> </Style> <LineString> ' +
|
||||
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
|
||||
'</Placemark></Document></kml>';
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(kml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(kml)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
|
||||
var stroke = symbolizers[0];
|
||||
expect(stroke).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literal = stroke.createLiteral(ol.geom.GeometryType.LINESTRING);
|
||||
expect(literal).to.be.a(ol.style.LineLiteral);
|
||||
expect(literal.color).to.eql('#ff0000');
|
||||
expect(literal.opacity).to.eql(0.5294117647058824);
|
||||
expect(literal.width).to.eql(10);
|
||||
});
|
||||
|
||||
it('reads PolyStyle fill', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
|
||||
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
||||
'<color>870000ff</color></PolyStyle> </Style>' +
|
||||
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
||||
'5.001370157823406,49.26855713824488 8.214706453896161,' +
|
||||
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
|
||||
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
||||
'</outerBoundaryIs></Polygon></Placemark><Placemark> <Style> ' +
|
||||
'<PolyStyle><fill>0</fill><color>870000ff</color>' +
|
||||
'</PolyStyle> </Style>' +
|
||||
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
||||
'5.001370157823406,49.26855713824488 8.214706453896161,' +
|
||||
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
|
||||
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
||||
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(kml);
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(2);
|
||||
expect(symbolizers[0]).to.be.a(ol.style.Fill);
|
||||
expect(symbolizers[1]).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literals = ol.style.Style.createLiterals(
|
||||
symbolizers, ol.geom.GeometryType.POLYGON);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
var literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.strokeColor).to.be('#ff0000');
|
||||
|
||||
symbolizers = obj.features[1].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
expect(symbolizers[0]).to.be.a(ol.style.Stroke);
|
||||
|
||||
var literals = ol.style.Style.createLiterals(
|
||||
symbolizers, ol.geom.GeometryType.POLYGON);
|
||||
expect(literals).to.have.length(1);
|
||||
|
||||
literal = literals[0];
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be(undefined);
|
||||
});
|
||||
|
||||
it('writes PolyStyle fill and outline', function() {
|
||||
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
|
||||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
||||
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
|
||||
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd"> ' +
|
||||
'<Document><Placemark><Style><PolyStyle>' +
|
||||
'<fill>1</fill><outline>0</outline>' +
|
||||
'<color>870000ff</color></PolyStyle> </Style>' +
|
||||
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
||||
'5.001370157823406,49.26855713824488 8.214706453896161,' +
|
||||
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
|
||||
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
||||
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var output = p.write(p.read(kml));
|
||||
expect(goog.dom.xml.loadXml(kml)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
|
||||
it('handles iconStyle (read / write)', function(done) {
|
||||
var url = 'spec/ol/parser/kml/iconstyle.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
|
||||
var symbolizer = symbolizers[0];
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
|
||||
var url = 'http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
|
||||
expect(literal.url).to.eql(url);
|
||||
expect(literal.width).to.eql(32);
|
||||
expect(literal.height).to.eql(32);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles styleMap (read / write)', function(done) {
|
||||
var url = 'spec/ol/parser/kml/stylemap.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
|
||||
var symbolizers = obj.features[0].getSymbolizers();
|
||||
expect(symbolizers).to.have.length(1);
|
||||
|
||||
var symbolizer = symbolizers[0];
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
|
||||
var url = 'http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
|
||||
expect(literal.url).to.eql(url);
|
||||
expect(literal.width).to.eql(32);
|
||||
expect(literal.height).to.eql(32);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('parsing states.kml', function() {
|
||||
|
||||
var features;
|
||||
before(function(done) {
|
||||
afterLoadXml('spec/ol/parser/kml/states.kml', function(xml) {
|
||||
var parser = new ol.parser.KML();
|
||||
var obj;
|
||||
try {
|
||||
obj = parser.read(xml);
|
||||
} catch (err) {
|
||||
return done(err);
|
||||
}
|
||||
if (!obj.features) {
|
||||
return done(new Error('Failed to parse features from doc'));
|
||||
}
|
||||
features = obj.features;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('creates 50 features', function() {
|
||||
expect(features).to.have.length(50);
|
||||
});
|
||||
|
||||
it('creates features with heterogenous geometry collections', function() {
|
||||
// TODO: decide if we should instead create features with multiple geoms
|
||||
var feature = features[0];
|
||||
expect(feature).to.be.a(ol.Feature);
|
||||
var geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.GeometryCollection);
|
||||
});
|
||||
|
||||
it('parses Point and MultiPolygon for Alaska', function() {
|
||||
var alaska = goog.array.find(features, function(feature) {
|
||||
return feature.get('name') === 'Alaska';
|
||||
});
|
||||
expect(alaska).to.be.a(ol.Feature);
|
||||
var geometry = alaska.getGeometry();
|
||||
expect(geometry).to.be.a(ol.geom.GeometryCollection);
|
||||
var components = geometry.getComponents();
|
||||
expect(components).to.have.length(2);
|
||||
expect(components[0]).to.be.a(ol.geom.Point);
|
||||
expect(components[1]).to.be.a(ol.geom.MultiPolygon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom.xml');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.KML');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.IconLiteral');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
6
old/test/spec/ol/parser/kml/depth.kml
Normal file
6
old/test/spec/ol/parser/kml/depth.kml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
|
||||
</Document>
|
||||
</kml>
|
||||
16
old/test/spec/ol/parser/kml/extended_data.kml
Normal file
16
old/test/spec/ol/parser/kml/extended_data.kml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Placemark id="foobarbaz">
|
||||
<name>Extended data placemark</name>
|
||||
<description>Attached to the ground. Intelligently places itself
|
||||
at the height of the underlying terrain.</description>
|
||||
<ExtendedData>
|
||||
<Data name="foo">
|
||||
<value>bar</value>
|
||||
</Data>
|
||||
</ExtendedData>
|
||||
<Point>
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</kml>
|
||||
31
old/test/spec/ol/parser/kml/extended_data2.kml
Normal file
31
old/test/spec/ol/parser/kml/extended_data2.kml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://earth.google.com/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>Easy trail</name>
|
||||
<ExtendedData>
|
||||
<SchemaData schemaUrl="#TrailHeadTypeId">
|
||||
<SimpleData name="TrailHeadName">Pi in the sky</SimpleData>
|
||||
<SimpleData name="TrailLength">3.14159</SimpleData>
|
||||
<SimpleData name="ElevationGain">10</SimpleData>
|
||||
</SchemaData>
|
||||
</ExtendedData>
|
||||
<Point>
|
||||
<coordinates>-122.000,37.002</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
<Placemark>
|
||||
<name>Difficult trail</name>
|
||||
<ExtendedData>
|
||||
<SchemaData schemaUrl="#TrailHeadTypeId">
|
||||
<SimpleData name="TrailHeadName">Mount Everest</SimpleData>
|
||||
<SimpleData name="TrailLength">347.45</SimpleData>
|
||||
<SimpleData name="ElevationGain">10000</SimpleData>
|
||||
</SchemaData>
|
||||
</ExtendedData>
|
||||
<Point>
|
||||
<coordinates>-122.000,37.002</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
19
old/test/spec/ol/parser/kml/iconstyle.kml
Normal file
19
old/test/spec/ol/parser/kml/iconstyle.kml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Style id="pushpin">
|
||||
<IconStyle id="mystyle">
|
||||
<Icon>
|
||||
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
|
||||
</Icon>
|
||||
</IconStyle>
|
||||
</Style>
|
||||
<Placemark>
|
||||
<name>Pin on a mountaintop</name>
|
||||
<styleUrl>#pushpin</styleUrl>
|
||||
<Point>
|
||||
<coordinates>170.1435558771009,-43.60505741890396,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
23
old/test/spec/ol/parser/kml/linestring.kml
Normal file
23
old/test/spec/ol/parser/kml/linestring.kml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<name>LineString.kml</name>
|
||||
<open>1</open>
|
||||
<Placemark>
|
||||
<name>unextruded</name>
|
||||
<LineString>
|
||||
<coordinates>
|
||||
-122.364383,37.824664,0 -122.364152,37.824322,0
|
||||
</coordinates>
|
||||
</LineString>
|
||||
</Placemark>
|
||||
<Placemark>
|
||||
<name>extruded</name>
|
||||
<LineString>
|
||||
<coordinates>
|
||||
-122.364167,37.824787,50 -122.363917,37.824423,50
|
||||
</coordinates>
|
||||
</LineString>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
1039
old/test/spec/ol/parser/kml/macnoise.kml
Normal file
1039
old/test/spec/ol/parser/kml/macnoise.kml
Normal file
File diff suppressed because it is too large
Load Diff
26
old/test/spec/ol/parser/kml/multigeometry.kml
Normal file
26
old/test/spec/ol/parser/kml/multigeometry.kml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<name>Polygon.kml</name>
|
||||
<open>0</open>
|
||||
<Placemark>
|
||||
<name>SF Marina Harbor Master</name>
|
||||
<MultiGeometry>
|
||||
<LineString>
|
||||
<!-- north wall -->
|
||||
<coordinates>
|
||||
-122.4425587930444,37.80666418607323,0
|
||||
-122.4428379594768,37.80663578323093,0
|
||||
</coordinates>
|
||||
</LineString>
|
||||
<LineString>
|
||||
<!-- south wall -->
|
||||
<coordinates>
|
||||
-122.4425509770566,37.80662588061205,0
|
||||
-122.4428340530617,37.8065999493009,0
|
||||
</coordinates>
|
||||
</LineString>
|
||||
</MultiGeometry>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
25
old/test/spec/ol/parser/kml/multigeometry_discrete.kml
Normal file
25
old/test/spec/ol/parser/kml/multigeometry_discrete.kml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<name>Polygon.kml</name>
|
||||
<open>0</open>
|
||||
<Placemark>
|
||||
<name>SF Marina Harbor Master</name>
|
||||
<visibility>0</visibility>
|
||||
<MultiGeometry>
|
||||
<LineString>
|
||||
<!-- north wall -->
|
||||
<coordinates>
|
||||
-122.4425587930444,37.80666418607323,0
|
||||
-122.4428379594768,37.80663578323093,0
|
||||
</coordinates>
|
||||
</LineString>
|
||||
<Point>
|
||||
<coordinates>
|
||||
-122.4428340530617,37.8065999493009,0
|
||||
</coordinates>
|
||||
</Point>
|
||||
</MultiGeometry>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
15
old/test/spec/ol/parser/kml/networklink.kml
Normal file
15
old/test/spec/ol/parser/kml/networklink.kml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>Simple placemark</name>
|
||||
<description>Attached to the ground. Intelligently places itself
|
||||
at the height of the underlying terrain.</description>
|
||||
<Point>
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
<NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
|
||||
<NetworkLink><Link><href>spec/ol/parser/kml/point.kml</href></Link></NetworkLink>
|
||||
</Document>
|
||||
</kml>
|
||||
14
old/test/spec/ol/parser/kml/networklink_depth.kml
Normal file
14
old/test/spec/ol/parser/kml/networklink_depth.kml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>Simple placemark</name>
|
||||
<description>Attached to the ground. Intelligently places itself
|
||||
at the height of the underlying terrain.</description>
|
||||
<Point>
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
<NetworkLink><Link><href>spec/ol/parser/kml/depth.kml</href></Link></NetworkLink>
|
||||
</Document>
|
||||
</kml>
|
||||
13
old/test/spec/ol/parser/kml/point.kml
Normal file
13
old/test/spec/ol/parser/kml/point.kml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>Simple placemark</name>
|
||||
<description>Attached to the ground. Intelligently places itself
|
||||
at the height of the underlying terrain.</description>
|
||||
<Point>
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
21
old/test/spec/ol/parser/kml/polygon.kml
Normal file
21
old/test/spec/ol/parser/kml/polygon.kml
Normal file
@@ -0,0 +1,21 @@
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<name>Polygon.kml</name>
|
||||
<open>0</open>
|
||||
<Placemark id="KML.Polygon">
|
||||
<name>hollow box</name>
|
||||
<Polygon>
|
||||
<outerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-30,-20,0 -30,20,0 30,20,0 30,-20,0 -30,-20,0</coordinates>
|
||||
</LinearRing>
|
||||
</outerBoundaryIs>
|
||||
<innerBoundaryIs>
|
||||
<LinearRing>
|
||||
<coordinates>-15,-10,0 15,-10,0 15,10,0 -15,10,0 -15,-10,0</coordinates>
|
||||
</LinearRing>
|
||||
</innerBoundaryIs>
|
||||
</Polygon>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
4661
old/test/spec/ol/parser/kml/states.kml
Normal file
4661
old/test/spec/ol/parser/kml/states.kml
Normal file
File diff suppressed because one or more lines are too long
29
old/test/spec/ol/parser/kml/stylemap.kml
Normal file
29
old/test/spec/ol/parser/kml/stylemap.kml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
|
||||
<Document>
|
||||
<Style id="pushpin">
|
||||
<IconStyle id="mystyle">
|
||||
<Icon>
|
||||
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
|
||||
</Icon>
|
||||
</IconStyle>
|
||||
</Style>
|
||||
<StyleMap id="pushpinStyleMap">
|
||||
<Pair>
|
||||
<key>normal</key>
|
||||
<styleUrl>#pushpin</styleUrl>
|
||||
</Pair>
|
||||
<Pair>
|
||||
<key>highlight</key>
|
||||
<styleUrl>#pushpin</styleUrl>
|
||||
</Pair>
|
||||
</StyleMap>
|
||||
<Placemark>
|
||||
<name>Pin on a mountaintop</name>
|
||||
<styleUrl>#pushpinStyleMap</styleUrl>
|
||||
<Point>
|
||||
<coordinates>170.1435558771009,-43.60505741890396,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
74
old/test/spec/ol/parser/ogc/exceptionreport.test.js
Normal file
74
old/test/spec/ol/parser/ogc/exceptionreport.test.js
Normal file
@@ -0,0 +1,74 @@
|
||||
goog.provide('ol.test.parser.ogc.ExceptionReport');
|
||||
|
||||
|
||||
describe('ol.parser.ogc.exceptionreport', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.ExceptionReport();
|
||||
|
||||
describe('test read exception', function() {
|
||||
|
||||
it('OCG WMS 1.3.0 exceptions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var exceptions = parser.read(xml).exceptionReport.exceptions;
|
||||
expect(exceptions.length).to.be(4);
|
||||
var str = 'Plain text message about an error.';
|
||||
expect(goog.string.trim(exceptions[0].text)).to.be(str);
|
||||
expect(exceptions[1].code).to.be('InvalidUpdateSequence');
|
||||
str = ' Another error message, this one with a service exception ' +
|
||||
'code supplied. ';
|
||||
expect(exceptions[1].text).to.be(str);
|
||||
str = 'Error in module <foo.c>, line 42A message that includes angle ' +
|
||||
'brackets in text must be enclosed in a Character Data Section as' +
|
||||
' in this example. All XML-like markup is ignored except for this' +
|
||||
' sequence of three closing characters:';
|
||||
expect(goog.string.trim(exceptions[2].text), str);
|
||||
str = '<Module>foo.c</Module> <Error>An error occurred</Error> ' +
|
||||
'<Explanation>Similarly, actual XML can be enclosed in a CDATA ' +
|
||||
'section. A generic parser will ignore that XML, but ' +
|
||||
'application-specific software may choose to process it.' +
|
||||
'</Explanation>';
|
||||
expect(goog.string.trim(exceptions[3].text), str);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test read exception OWSCommon 1.0.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_0_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.0.0');
|
||||
expect(report.language).to.eql('en');
|
||||
expect(exception.code).to.eql('InvalidParameterValue');
|
||||
expect(exception.locator).to.eql('foo');
|
||||
var msg = 'Update error: Error occured updating features';
|
||||
expect(exception.texts[0]).to.eql(msg);
|
||||
msg = 'Second exception line';
|
||||
expect(exception.texts[1]).to.eql(msg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test read exception OWSCommon 1.1.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_1_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.1.0');
|
||||
expect(report.language).to.eql('en');
|
||||
expect(exception.code).to.eql('InvalidParameterValue');
|
||||
expect(exception.locator).to.eql('foo');
|
||||
var msg = 'Update error: Error occured updating features';
|
||||
expect(exception.texts[0]).to.eql(msg);
|
||||
expect(exception.texts[1]).to.eql('Second exception line');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.parser.ogc.ExceptionReport');
|
||||
284
old/test/spec/ol/parser/ogc/filter_v1_0_0.test.js
Normal file
284
old/test/spec/ol/parser/ogc/filter_v1_0_0.test.js
Normal file
@@ -0,0 +1,284 @@
|
||||
goog.provide('ol.test.parser.ogc.Filter_v1_0_0');
|
||||
|
||||
describe('ol.parser.ogc.Filter_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.Filter_v1_0_0();
|
||||
|
||||
describe('reading and writing', function() {
|
||||
|
||||
it('handles intersects', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/intersects.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(
|
||||
ol.expr.functions.INTERSECTS);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles within', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/within.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(ol.expr.functions.WITHIN);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles contains', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/contains.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(
|
||||
ol.expr.functions.CONTAINS);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles between', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/between.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Logical);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.AND);
|
||||
expect(filter.getLeft()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.GTE);
|
||||
expect(filter.getLeft().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getLeft().getRight().getValue()).to.equal(0);
|
||||
expect(filter.getRight()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getRight().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.LTE);
|
||||
expect(filter.getRight().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getRight().getRight().getValue()).to.equal(100);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles between without literals', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/between2.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Logical);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.AND);
|
||||
expect(filter.getLeft()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.GTE);
|
||||
expect(filter.getLeft().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getLeft().getRight().getValue()).to.equal(0);
|
||||
expect(filter.getRight()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getRight().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.LTE);
|
||||
expect(filter.getRight().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getRight().getRight().getValue()).to.equal(100);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles null', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/null.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getName()).to.equal('prop');
|
||||
expect(filter.getRight().getValue()).to.equal(null);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/bbox.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.EXTENT),
|
||||
[new ol.expr.Literal(-180), new ol.expr.Literal(-90),
|
||||
new ol.expr.Literal(180), new ol.expr.Literal(90),
|
||||
new ol.expr.Literal('EPSG:4326'),
|
||||
new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX without geometry name', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/bbox_nogeom.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.EXTENT),
|
||||
[new ol.expr.Literal(-180), new ol.expr.Literal(-90),
|
||||
new ol.expr.Literal(180), new ol.expr.Literal(90),
|
||||
new ol.expr.Literal('EPSG:4326')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reads DWithin', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/dwithin.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Call);
|
||||
var callee = filter.getCallee();
|
||||
expect(callee).to.be.a(ol.expr.Identifier);
|
||||
var name = callee.getName();
|
||||
expect(name).to.equal(ol.expr.functions.DWITHIN);
|
||||
var args = filter.getArgs();
|
||||
expect(args.length).to.equal(5);
|
||||
var distance = args[1];
|
||||
expect(distance).to.be.a(ol.expr.Literal);
|
||||
expect(distance.getValue()).to.equal(1000);
|
||||
var units = args[2];
|
||||
expect(units).to.be.a(ol.expr.Literal);
|
||||
expect(units.getValue()).to.equal('m');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes DWithin', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/dwithin.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.DWITHIN),
|
||||
[new ol.expr.Literal(new ol.geom.Point([2488789, 289552])),
|
||||
new ol.expr.Literal(1000), new ol.expr.Literal('m'),
|
||||
new ol.expr.Literal(null), new ol.expr.Identifier('Geometry')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
filter = parser.read(xml);
|
||||
output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// the Filter Encoding spec doesn't allow for FID filters inside logical
|
||||
// filters however, to be liberal, we will write them without complaining
|
||||
describe('logical fid', function() {
|
||||
|
||||
it('writes logical [OR] with fid', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/logicalfeatureid.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('me'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!')]),
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.1'), new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes logical [AND] with fid',
|
||||
function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/' +
|
||||
'logicalfeatureidand.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('me'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!')]),
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.1'), new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes logical [NOT] with fid',
|
||||
function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/' +
|
||||
'logicalfeatureidnot.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Not(
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('_expression reader', function() {
|
||||
var evaluate = ol.expr.evaluateFeature;
|
||||
|
||||
it('handles combined propertyname and text', function() {
|
||||
var xml = '<ogc:UpperBoundary xmlns:ogc="' +
|
||||
'http://www.opengis.net/ogc">10</ogc:UpperBoundary>';
|
||||
var reader = parser.readers['http://www.opengis.net/ogc'][
|
||||
'_expression'];
|
||||
var expr = reader.call(parser, goog.dom.xml.loadXml(
|
||||
xml).documentElement);
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.getValue()).to.equal(10);
|
||||
xml = '<ogc:UpperBoundary xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'foo<ogc:PropertyName>x</ogc:PropertyName>bar</ogc:UpperBoundary>';
|
||||
expr = reader.call(parser, goog.dom.xml.loadXml(xml).documentElement);
|
||||
expect(evaluate(expr, new ol.Feature({x: 4}))).to.eql('foo4bar');
|
||||
});
|
||||
|
||||
it('handles combined propertyname and literal', function() {
|
||||
var reader = parser.readers['http://www.opengis.net/ogc'][
|
||||
'_expression'];
|
||||
var xml = '<ogc:UpperBoundary xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:Literal>bar</ogc:Literal>' +
|
||||
'<ogc:PropertyName>x</ogc:PropertyName>' +
|
||||
'<ogc:Literal>foo</ogc:Literal></ogc:UpperBoundary>';
|
||||
var expr = reader.call(parser, goog.dom.xml.loadXml(xml).documentElement);
|
||||
expect(evaluate(expr, new ol.Feature({x: 42}))).to.eql('bar42foo');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.ogc.Filter_v1_0_0');
|
||||
245
old/test/spec/ol/parser/ogc/filter_v1_1_0.test.js
Normal file
245
old/test/spec/ol/parser/ogc/filter_v1_1_0.test.js
Normal file
@@ -0,0 +1,245 @@
|
||||
goog.provide('ol.test.parser.ogc.Filter_v1_1_0');
|
||||
|
||||
describe('ol.parser.ogc.Filter_v1_1_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.Filter_v1_1_0();
|
||||
|
||||
describe('reading and writing', function() {
|
||||
|
||||
it('reads filter', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/test.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Logical).to.be(true);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.OR);
|
||||
var filters = [];
|
||||
parser.getSubfiltersForLogical_(filter, filters);
|
||||
expect(filters.length).to.equal(5);
|
||||
expect(filters[0]).to.eql(new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE, new ol.expr.Identifier('number'),
|
||||
new ol.expr.Literal(1064866676)),
|
||||
new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE, new ol.expr.Identifier('number'),
|
||||
new ol.expr.Literal(1065512599))));
|
||||
expect(filters[1]).to.eql(new ol.expr.Not(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE, new ol.expr.Identifier('FOO'),
|
||||
new ol.expr.Literal(5000))));
|
||||
expect(filters[2] instanceof ol.expr.Call).to.be(true);
|
||||
expect(filters[2].getCallee().getName()).to.equal(
|
||||
ol.expr.functions.LIKE);
|
||||
expect(filters[2].getArgs()).to.eql([new ol.expr.Identifier('cat'),
|
||||
new ol.expr.Literal('*dog.food!*good'), new ol.expr.Literal('*'),
|
||||
new ol.expr.Literal('.'), new ol.expr.Literal('!'),
|
||||
new ol.expr.Literal(null)]);
|
||||
expect(filters[3] instanceof ol.expr.Call).to.be(true);
|
||||
expect(filters[3].getCallee().getName()).to.equal(
|
||||
ol.expr.functions.IEQ);
|
||||
expect(filters[3].getArgs()).to.eql([new ol.expr.Identifier('cat'),
|
||||
new ol.expr.Literal('dog')]);
|
||||
expect(filters[4] instanceof ol.expr.Comparison).to.be(true);
|
||||
expect(filters[4].getOperator()).to.equal(ol.expr.ComparisonOp.EQ);
|
||||
expect(filters[4].getLeft().getName()).to.equal('cat');
|
||||
expect(filters[4].getRight().getValue()).to.equal('dog');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reads matchCase', function() {
|
||||
var cases = [{
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo>' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="1">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="true">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="0">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="0">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsNotEqualTo matchCase="true">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsNotEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsNotEqualTo matchCase="false">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsNotEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}];
|
||||
var filter, c;
|
||||
for (var i = 0; i < cases.length; ++i) {
|
||||
c = cases[i];
|
||||
filter = parser.read(c.str);
|
||||
var matchCase = (filter instanceof ol.expr.Call) ? false : true;
|
||||
expect(matchCase).to.equal(c.exp);
|
||||
}
|
||||
});
|
||||
|
||||
it('writes BBOX', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/bbox.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX without property name', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/bbox_nogeomname.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles intersects', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/intersects.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/function.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.INTERSECTS),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('querySingle'),
|
||||
[new ol.expr.Literal('sf:restricted'),
|
||||
new ol.expr.Literal('the_geom'),
|
||||
new ol.expr.Literal('cat=3')]), new ol.expr.Literal(null),
|
||||
new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes custom functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/customfunction.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.INEQ),
|
||||
[new ol.expr.Identifier('FOO'), new ol.expr.Call(
|
||||
new ol.expr.Identifier('customFunction'),
|
||||
[new ol.expr.Literal('param1'), new ol.expr.Literal('param2')])]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes nested functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/nestedfunction.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.DWITHIN),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('collectGeometries'),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('queryCollection'),
|
||||
[new ol.expr.Literal('sf:roads'),
|
||||
new ol.expr.Literal('the_geom'),
|
||||
new ol.expr.Literal('INCLUDE')])]), new ol.expr.Literal(200),
|
||||
new ol.expr.Literal('meters'),
|
||||
new ol.expr.Literal(null), new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes matchCase on like', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/likematchcase.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('*me*'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!'), new ol.expr.Literal(false)]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes sortBy on like', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/sortby.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var writer = parser.writers['http://www.opengis.net/ogc']['SortBy'];
|
||||
var output = writer.call(parser, [{
|
||||
'property': new ol.expr.Identifier('Title'),
|
||||
'order': new ol.expr.Literal('ASC')
|
||||
},{
|
||||
'property': new ol.expr.Identifier('Relevance'),
|
||||
'order': new ol.expr.Literal('DESC')
|
||||
}]);
|
||||
expect(output).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.parser.ogc.Filter_v1_1_0');
|
||||
342
old/test/spec/ol/parser/ogc/gml_v2.test.js
Normal file
342
old/test/spec/ol/parser/ogc/gml_v2.test.js
Normal file
@@ -0,0 +1,342 @@
|
||||
goog.provide('ol.test.parser.gml_v2');
|
||||
|
||||
describe('ol.parser.gml_v2', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.GML_v2();
|
||||
|
||||
describe('Test GML v2 parser', function() {
|
||||
it('Point read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/point-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('point');
|
||||
expect(obj.geometry.coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Point read / written correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
parser.applyWriteOptions(obj);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('point');
|
||||
expect(obj.geometry.coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPoint read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipoint-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([1, 2]);
|
||||
expect(obj.geometry.parts[1].coordinates).to.eql([2, 3]);
|
||||
expect(obj.geometry.parts[2].coordinates).to.eql([3, 4]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPoint read / written correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([1, 2]);
|
||||
expect(obj.geometry.parts[1].coordinates).to.eql([2, 3]);
|
||||
expect(obj.geometry.parts[2].coordinates).to.eql([3, 4]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('LineString read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linestring-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates.length).to.eql(2);
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('LineString read / written correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates.length).to.eql(2);
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiLineString read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multilinestring-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([[1, 2], [2, 3]]);
|
||||
expect(obj.geometry.parts[1].coordinates).to.eql([[3, 4], [4, 5]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiLineString read / written correctly from coords', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([[1, 2], [2, 3]]);
|
||||
expect(obj.geometry.parts[1].coordinates).to.eql([[3, 4], [4, 5]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Polygon read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/polygon-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
expect(obj.geometry.coordinates.length).to.eql(3);
|
||||
expect(obj.geometry.coordinates[0].length).to.eql(4);
|
||||
expect(obj.geometry.coordinates[0]).to.eql([[1, 2], [3, 4],
|
||||
[5, 6], [1, 2]]);
|
||||
expect(obj.geometry.coordinates[1]).to.eql([[2, 3], [4, 5],
|
||||
[6, 7], [2, 3]]);
|
||||
expect(obj.geometry.coordinates[2]).to.eql([[3, 4], [5, 6],
|
||||
[7, 8], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Polygon read / written correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPolygon read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipolygon-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPolygon read / written from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('GeometryCollection r / w correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/' +
|
||||
'geometrycollection-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v2({featureNS: 'http://foo'});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('geometrycollection');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
expect(obj.geometry.parts[1].type).to.eql('linestring');
|
||||
expect(obj.geometry.parts[2].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Box read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/box-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.bounds).to.eql([1, 2, 3, 4]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Box read correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/box-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.bounds).to.eql([1, 2, 3, 4]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('LinearRing read correctly from coord', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linearring-coord.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('linearring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6],
|
||||
[1, 2]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('LinearRing read / written correctly from coordinates', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linearring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6],
|
||||
[1, 2]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('FeatureCollection read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/topp-states.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var schemaLoc = 'http://www.openplans.org/topp ' +
|
||||
'http://demo.opengeo.org/geoserver/wfs?service=WFS&version=' +
|
||||
'1.0.0&request=DescribeFeatureType&typeName=topp:states ' +
|
||||
'http://www.opengis.net/wfs http://demo.opengeo.org/' +
|
||||
'geoserver/schemas/wfs/1.0.0/WFS-basic.xsd';
|
||||
var p = new ol.parser.ogc.GML_v2({
|
||||
featureType: 'states',
|
||||
featureNS: 'http://www.openplans.org/topp',
|
||||
schemaLocation: schemaLoc});
|
||||
// overwrite the axis orientation of the projection, since WFS 1.0.0
|
||||
// always uses enu
|
||||
var obj = p.read(xml, {axisOrientation: 'enu'});
|
||||
var output = p.write(obj, {axisOrientation: 'enu'});
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
var feature = obj.features[0];
|
||||
expect(feature.getGeometry() instanceof
|
||||
ol.geom.MultiPolygon).to.be.ok();
|
||||
var attributes = feature.getAttributes();
|
||||
expect(feature.getId()).to.eql('states.1');
|
||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Auto configure works correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/topp-states.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v2();
|
||||
var obj = p.read(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
expect(obj.features[0].getGeometry() instanceof
|
||||
ol.geom.MultiPolygon).to.be.ok();
|
||||
expect(p.featureType).to.eql('states');
|
||||
expect(p.featureNS).to.eql('http://www.openplans.org/topp');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Test multiple typeNames', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/multipletypenames.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
// we should not go through autoConfig so specify featureNS
|
||||
var p = new ol.parser.ogc.GML_v2({
|
||||
featureNS: 'http://mapserver.gis.umn.edu/mapserver',
|
||||
featureType: ['LKUNSTWERK', 'PKUNSTWERK', 'VKUNSTWERK']});
|
||||
var obj = p.read(xml);
|
||||
var features = obj.features;
|
||||
expect(features.length).to.eql(3);
|
||||
expect(features[0].getGeometry() instanceof
|
||||
ol.geom.MultiPolygon).to.be.ok();
|
||||
expect(features[1].getGeometry() instanceof
|
||||
ol.geom.MultiLineString).to.be.ok();
|
||||
expect(features[2].getGeometry() instanceof
|
||||
ol.geom.MultiPoint).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Test no geometry', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/nogeom.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(2);
|
||||
var feature = obj.features[0];
|
||||
expect(feature.getGeometry() === null).to.be.ok();
|
||||
// TODO test bounds on feature
|
||||
// see https://github.com/openlayers/ol3/issues/566
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Test boundedBy', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v2/boundedBy.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
parser.read(xml);
|
||||
// TODO test bounds on feature
|
||||
// see https://github.com/openlayers/ol3/issues/566
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
|
||||
goog.require('ol.parser.ogc.GML_v2');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.EPSG4326');
|
||||
383
old/test/spec/ol/parser/ogc/gml_v3.test.js
Normal file
383
old/test/spec/ol/parser/ogc/gml_v3.test.js
Normal file
@@ -0,0 +1,383 @@
|
||||
goog.provide('ol.test.parser.gml_v3');
|
||||
|
||||
describe('ol.parser.gml_v3', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.GML_v3();
|
||||
|
||||
describe('Test GML v3 parser', function() {
|
||||
it('Envelope read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/envelope.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.bounds).to.eql([1, 2, 3, 4]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('LinearRing read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/linearring.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linearring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6],
|
||||
[1, 2]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Linestring read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/linestring.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Linestring 3D read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/linestring3d.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
// no write test since simple features only does 2D
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2, 3], [4, 5, 6]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Curve read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/curve.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('linestring');
|
||||
expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiLineString plural read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multilinestring-plural.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
// no write test for plural, we only write singular
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiLineString singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({multiCurve: false});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiCurve singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([[1, 2], [2, 3]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiCurve curve read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({curve: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multilinestring');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('linestring');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([[1, 2], [2, 3]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPoint plural read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipoint-plural.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPoint singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipoint');
|
||||
expect(obj.geometry.parts.length).to.eql(3);
|
||||
expect(obj.geometry.parts[0].type).to.eql('point');
|
||||
expect(obj.geometry.parts[0].coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPolygon plural read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipolygon-plural.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiPolygon singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({multiSurface: false});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiSurface plural read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multisurface-plural.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiSurface singular read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('MultiSurface surface read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj);
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('multipolygon');
|
||||
expect(obj.geometry.parts.length).to.eql(2);
|
||||
expect(obj.geometry.parts[0].type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Point read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/point.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('point');
|
||||
expect(obj.geometry.coordinates).to.eql([1, 2]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Polygon read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/polygon.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = parser.createGeometry({geometry: obj.geometry});
|
||||
parser.applyWriteOptions(obj);
|
||||
var node = parser.featureNSWiters_['_geometry'].apply(parser,
|
||||
[geom]).firstChild;
|
||||
delete parser.srsName;
|
||||
delete parser.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Surface read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/surface.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.GML_v3({surface: true});
|
||||
var obj = p.read(xml);
|
||||
var geom = p.createGeometry({geometry: obj.geometry});
|
||||
p.applyWriteOptions(obj, {srsName: 'foo'});
|
||||
var node = p.featureNSWiters_['_geometry'].apply(p,
|
||||
[geom]).firstChild;
|
||||
delete p.srsName;
|
||||
delete p.axisOrientation;
|
||||
expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml);
|
||||
expect(obj.geometry.type).to.eql('polygon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('FeatureCollection from GML read / written correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/topp-states-gml.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var schemaLoc = 'http://www.openplans.org/topp ' +
|
||||
'http://demo.opengeo.org/geoserver/wfs?service=WFS&version=' +
|
||||
'1.1.0&request=DescribeFeatureType&typeName=topp:states ' +
|
||||
'http://www.opengis.net/gml ' +
|
||||
'http://schemas.opengis.net/gml/3.2.1/gml.xsd';
|
||||
var p = new ol.parser.ogc.GML_v3({schemaLocation: schemaLoc});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
expect(p.geometryName).to.eql('the_geom');
|
||||
expect(obj.features.length).to.eql(10);
|
||||
var feature = obj.features[0];
|
||||
expect(feature.getGeometry() instanceof
|
||||
ol.geom.MultiPolygon).to.be.ok();
|
||||
var attributes = feature.getAttributes();
|
||||
expect(feature.getId()).to.eql('states.1');
|
||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('FeatureCollection from WFS read correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/topp-states-wfs.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
var feature = obj.features[0];
|
||||
expect(feature.getGeometry() instanceof
|
||||
ol.geom.MultiPolygon).to.be.ok();
|
||||
var attributes = feature.getAttributes();
|
||||
expect(feature.getId()).to.eql('states.1');
|
||||
expect(attributes['STATE_NAME']).to.eql('Illinois');
|
||||
expect(attributes['STATE_FIPS']).to.eql('17');
|
||||
expect(attributes['SUB_REGION']).to.eql('E N Cen');
|
||||
expect(attributes['STATE_ABBR']).to.eql('IL');
|
||||
expect(attributes['LAND_KM']).to.eql('143986.61');
|
||||
expect(ol.proj.get(obj.metadata.projection) instanceof ol.proj.EPSG4326)
|
||||
.to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Read autoConfig', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/topp-states-wfs.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
parser.read(xml);
|
||||
expect(parser.featureType).to.eql('states');
|
||||
expect(parser.featureNS).to.eql('http://www.openplans.org/topp');
|
||||
expect(parser.autoConfig === true).to.be.ok();
|
||||
parser.autoConfig = false;
|
||||
parser.read(xml);
|
||||
expect(parser.autoConfig === false).to.be.ok();
|
||||
parser.autoConfig = true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Empty attribute', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/empty-attribute.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(1);
|
||||
var attr = obj.features[0].getAttributes();
|
||||
expect(attr['name']).to.eql('Aflu');
|
||||
expect(attr['foo']).to.eql(undefined);
|
||||
expect(attr['empty']).to.eql('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Repeated name', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/gml_v3/repeated-name.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(1);
|
||||
var atts = obj.features[0].getAttributes();
|
||||
expect(atts['zoning']).to.eql('I-L');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.parser.ogc.GML_v3');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.EPSG4326');
|
||||
25
old/test/spec/ol/parser/ogc/versioned.test.js
Normal file
25
old/test/spec/ol/parser/ogc/versioned.test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
goog.provide('ol.test.parser.ogc.Versioned');
|
||||
|
||||
describe('ol.parser.ogc.versioned', function() {
|
||||
|
||||
describe('test constructor', function() {
|
||||
var parser = new ol.parser.ogc.Versioned({version: '1.0.0'});
|
||||
it('new OpenLayers.Format.XML.VersionedOGC returns object', function() {
|
||||
expect(parser instanceof ol.parser.ogc.Versioned).to.be.ok();
|
||||
});
|
||||
it('constructor sets version correctly', function() {
|
||||
expect(parser.version).to.eql('1.0.0');
|
||||
});
|
||||
it('defaultVersion should be null if not specified', function() {
|
||||
expect(parser.defaultVersion).to.be(null);
|
||||
});
|
||||
it('format has a read function', function() {
|
||||
expect(typeof(parser.read)).to.eql('function');
|
||||
});
|
||||
it('format has a write function', function() {
|
||||
expect(typeof(parser.write)).to.eql('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
45
old/test/spec/ol/parser/ogc/wmscapabilities.test.js
Normal file
45
old/test/spec/ol/parser/ogc/wmscapabilities.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
goog.provide('ol.test.parser.ogc.WMSCapabilities');
|
||||
|
||||
describe('test WMSCapabilities', function() {
|
||||
describe('test getVersion', function() {
|
||||
var snippet = '<WMS_Capabilities version="1.3.0" ' +
|
||||
'xmlns="http://www.opengis.net/wms"><Service></Service>' +
|
||||
'</WMS_Capabilities>';
|
||||
var snippet2 = '<WMS_Capabilities xmlns="http://www.opengis.net/wms">' +
|
||||
'<Service></Service></WMS_Capabilities>';
|
||||
it('Version taken from document', function() {
|
||||
var parser = new ol.parser.ogc.WMSCapabilities();
|
||||
var data = parser.read(snippet);
|
||||
expect(data.version).to.eql('1.3.0');
|
||||
});
|
||||
it('Version taken from parser takes preference', function() {
|
||||
var parser = new ol.parser.ogc.WMSCapabilities({version: '1.1.0'});
|
||||
var data = parser.read(snippet);
|
||||
expect(data.version).to.eql('1.1.0');
|
||||
});
|
||||
it('If nothing else is set, defaultVersion should be returned', function() {
|
||||
var parser = new ol.parser.ogc.WMSCapabilities({defaultVersion: '1.1.1'});
|
||||
var data = parser.read(snippet2);
|
||||
expect(data.version).to.eql('1.1.1');
|
||||
});
|
||||
var parser = new ol.parser.ogc.WMSCapabilities({defaultVersion: '1.1.1'});
|
||||
it('Version from options returned', function() {
|
||||
var version = parser.getVersion(null, {version: '1.3.0'});
|
||||
expect(version).to.eql('1.3.0');
|
||||
});
|
||||
var msg = 'defaultVersion returned if no version specified in options ' +
|
||||
'and no version on the format';
|
||||
it(msg, function() {
|
||||
var version = parser.getVersion(null);
|
||||
expect(version).to.eql('1.1.1');
|
||||
});
|
||||
msg = 'version returned of the Format if no version specified in options';
|
||||
it(msg, function() {
|
||||
parser.version = '1.1.0';
|
||||
var version = parser.getVersion(null);
|
||||
expect(version).to.eql('1.1.0');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
37
old/test/spec/ol/parser/ogc/wmscapabilities_v1_0_0.test.js
Normal file
37
old/test/spec/ol/parser/ogc/wmscapabilities_v1_0_0.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
goog.provide('ol.test.parser.ogc.WMSCapabilities_v1_0_0');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.0.0.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_0_0 = true;
|
||||
|
||||
describe('ol.parser.ogc.wmscapabilities_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMSCapabilities();
|
||||
|
||||
describe('test read', function() {
|
||||
it('Test read', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_0_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj;
|
||||
obj = parser.read(xml);
|
||||
expect(obj.service.keywords.length).to.eql(2);
|
||||
expect(obj.service.keywords[0]['value']).to.eql('BGDI');
|
||||
expect(obj.service.href).to.eql('https://wms.geo.admin.ch/?');
|
||||
var url = 'https://wms.geo.admin.ch/?';
|
||||
var getmap = obj.capability.request.getmap;
|
||||
expect(getmap.get.href).to.eql(url);
|
||||
expect(getmap.post.href).to.eql(url);
|
||||
expect(getmap.formats.length).to.eql(4);
|
||||
expect(getmap.formats[0]).to.eql('GIF');
|
||||
expect(obj.capability.layers[64].keywords.length).to.eql(2);
|
||||
expect(obj.capability.layers[64].keywords[0].value).to.eql('Geometer');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
259
old/test/spec/ol/parser/ogc/wmscapabilities_v1_1_1.test.js
Normal file
259
old/test/spec/ol/parser/ogc/wmscapabilities_v1_1_1.test.js
Normal file
@@ -0,0 +1,259 @@
|
||||
goog.provide('ol.test.parser.ogc.WMSCapabilities_v1_1_1');
|
||||
|
||||
describe('ol.parser.ogc.wmscapabilities_v1_1_1', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMSCapabilities();
|
||||
|
||||
describe('test read exception', function() {
|
||||
it('Error reported correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/' +
|
||||
'exceptionsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(!!obj.error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test read', function() {
|
||||
it('Test read', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, capability, getmap, describelayer, getfeatureinfo, layer;
|
||||
obj = parser.read(xml);
|
||||
capability = obj.capability;
|
||||
getmap = capability.request.getmap;
|
||||
describelayer = capability.request.describelayer;
|
||||
getfeatureinfo = capability.request.getfeatureinfo;
|
||||
layer = capability.layers[2];
|
||||
expect(capability).to.be.ok();
|
||||
expect(getmap.formats.length).to.eql(28);
|
||||
var get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
|
||||
expect(getmap.get.href).to.eql(get);
|
||||
expect(getmap.post).to.be(undefined);
|
||||
get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
|
||||
expect(describelayer.get.href).to.eql(get);
|
||||
expect(describelayer.post).to.be(undefined);
|
||||
get = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
|
||||
expect(getfeatureinfo.get.href).to.eql(get);
|
||||
var post = 'http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&';
|
||||
expect(getfeatureinfo.post.href).to.eql(post);
|
||||
expect(capability.layers).to.be.ok();
|
||||
expect(capability.layers.length).to.eql(22);
|
||||
var infoFormats =
|
||||
['text/plain', 'text/html', 'application/vnd.ogc.gml'];
|
||||
expect(layer.infoFormats).to.eql(infoFormats);
|
||||
expect(layer.name).to.eql('tiger:tiger_roads');
|
||||
expect(layer.prefix).to.eql('tiger');
|
||||
expect(layer.title).to.eql('Manhattan (NY) roads');
|
||||
var abstr = 'Highly simplified road layout of Manhattan in New York..';
|
||||
expect(layer['abstract']).to.eql(abstr);
|
||||
var bbox = [
|
||||
-74.08769307536667, 40.660618924633326,
|
||||
-73.84653192463333, 40.90178007536667
|
||||
];
|
||||
expect(layer.llbbox).to.eql(bbox);
|
||||
expect(layer.styles.length).to.eql(1);
|
||||
expect(layer.styles[0].name).to.eql('tiger_roads');
|
||||
var legend = 'http://publicus.opengeo.org:80/geoserver/wms/' +
|
||||
'GetLegendGraphic?VERSION=1.0.0&FORMAT=image/png&WIDTH=20&' +
|
||||
'HEIGHT=20&LAYER=tiger:tiger_roads';
|
||||
expect(layer.styles[0].legend.href).to.eql(legend);
|
||||
expect(layer.styles[0].legend.format).to.eql('image/png');
|
||||
expect(layer.queryable).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test layers', function() {
|
||||
it('Test layers', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, capability, layers = {}, rootlayer, identifiers, authorities;
|
||||
var featurelist;
|
||||
obj = parser.read(xml);
|
||||
capability = obj.capability;
|
||||
for (var i = 0, len = capability.layers.length; i < len; i++) {
|
||||
if ('name' in capability.layers[i]) {
|
||||
layers[capability.layers[i].name] = capability.layers[i];
|
||||
}
|
||||
}
|
||||
rootlayer = capability.layers[capability.layers.length - 1];
|
||||
identifiers = layers['ROADS_RIVERS'].identifiers;
|
||||
authorities = layers['ROADS_RIVERS'].authorityURLs;
|
||||
featurelist = layers['ROADS_RIVERS'].featureListURL;
|
||||
expect(rootlayer.srs).to.eql({'EPSG:4326': true});
|
||||
var srs = {'EPSG:4326': true, 'EPSG:26986': true};
|
||||
expect(layers['ROADS_RIVERS'].srs).to.eql(srs);
|
||||
expect(layers['Temperature'].srs).to.eql({'EPSG:4326': true});
|
||||
var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986'];
|
||||
expect(bbox.bbox).to.eql([189000, 834000, 285000, 962000]);
|
||||
expect(bbox.res).to.eql({x: 1, y: 1});
|
||||
bbox = layers['ROADS_RIVERS'].bbox['EPSG:4326'];
|
||||
expect(bbox.bbox).to.eql([-71.63, 41.75, -70.78, 42.90]);
|
||||
expect(bbox.res).to.eql({x: 0.01, y: 0.01});
|
||||
bbox = layers['ROADS_1M'].bbox['EPSG:26986'];
|
||||
expect(bbox.bbox).to.eql([189000, 834000, 285000, 962000]);
|
||||
expect(bbox.res).to.eql({x: 1, y: 1});
|
||||
expect(identifiers).to.be.ok();
|
||||
expect('DIF_ID' in identifiers).to.be.ok();
|
||||
expect(identifiers['DIF_ID']).to.eql('123456');
|
||||
expect('DIF_ID' in authorities).to.be.ok();
|
||||
var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html';
|
||||
expect(authorities['DIF_ID']).to.eql(url);
|
||||
expect(featurelist).to.be.ok();
|
||||
expect(featurelist.format).to.eql('application/vnd.ogc.se_xml');
|
||||
url = 'http://www.university.edu/data/roads_rivers.gml';
|
||||
expect(featurelist.href).to.eql(url);
|
||||
expect(layers['Pressure'].queryable).to.be.ok();
|
||||
expect(layers['ozone_image'].queryable).to.not.be();
|
||||
expect(layers['population'].cascaded).to.eql(1);
|
||||
expect(layers['ozone_image'].fixedWidth).to.eql(512);
|
||||
expect(layers['ozone_image'].fixedHeight).to.eql(256);
|
||||
expect(layers['ozone_image'].opaque).to.be.ok();
|
||||
expect(layers['ozone_image'].noSubsets).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test dimensions', function() {
|
||||
it('Test dimensions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, capability, layers = {}, time, elevation;
|
||||
obj = parser.read(xml);
|
||||
capability = obj.capability;
|
||||
for (var i = 0, len = capability.layers.length; i < len; i++) {
|
||||
if ('name' in capability.layers[i]) {
|
||||
layers[capability.layers[i].name] = capability.layers[i];
|
||||
}
|
||||
}
|
||||
time = layers['Clouds'].dimensions.time;
|
||||
elevation = layers['Pressure'].dimensions.elevation;
|
||||
expect(time['default']).to.eql('2000-08-22');
|
||||
expect(time.values.length).to.eql(1);
|
||||
expect(time.values[0]).to.eql('1999-01-01/2000-08-22/P1D');
|
||||
expect(elevation.units).to.eql('EPSG:5030');
|
||||
expect(elevation['default']).to.eql('0');
|
||||
expect(elevation.nearestVal).to.be.ok();
|
||||
expect(elevation.multipleVal).to.not.be();
|
||||
expect(elevation.values).to.eql(
|
||||
['0', '1000', '3000', '5000', '10000']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test contact info', function() {
|
||||
it('Test contact info', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, service, contactinfo, personPrimary, addr;
|
||||
obj = parser.read(xml);
|
||||
service = obj.service;
|
||||
contactinfo = service.contactInformation;
|
||||
personPrimary = contactinfo.personPrimary;
|
||||
addr = contactinfo.contactAddress;
|
||||
expect(contactinfo).to.be.ok();
|
||||
expect(personPrimary).to.be.ok();
|
||||
expect(personPrimary.person).to.eql('Jeff deLaBeaujardiere');
|
||||
expect(personPrimary.organization).to.eql('NASA');
|
||||
expect(contactinfo.position).to.eql('Computer Scientist');
|
||||
expect(addr).to.be.ok();
|
||||
expect(addr.type).to.eql('postal');
|
||||
var address = 'NASA Goddard Space Flight Center, Code 933';
|
||||
expect(addr.address).to.eql(address);
|
||||
expect(addr.city).to.eql('Greenbelt');
|
||||
expect(addr.stateOrProvince).to.eql('MD');
|
||||
expect(addr.postcode).to.eql('20771');
|
||||
expect(addr.country).to.eql('USA');
|
||||
expect(contactinfo.phone).to.eql('+1 301 286-1569');
|
||||
expect(contactinfo.fax).to.eql('+1 301 286-1777');
|
||||
expect(contactinfo.email).to.eql('delabeau@iniki.gsfc.nasa.gov');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test fees and constraints', function() {
|
||||
it('Test fees and constraints', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, service;
|
||||
obj = parser.read(xml);
|
||||
service = obj.service;
|
||||
expect('fees' in service).to.not.be();
|
||||
expect('accessConstraints' in service).to.not.be();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test requests', function() {
|
||||
it('Test requests', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/gssample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, request, exception, userSymbols;
|
||||
obj = parser.read(xml);
|
||||
request = obj.capability.request;
|
||||
exception = obj.capability.exception;
|
||||
userSymbols = obj.capability.userSymbols;
|
||||
expect(request).to.be.ok();
|
||||
expect('getmap' in request).to.be.ok();
|
||||
expect('getfeatureinfo' in request).to.be.ok();
|
||||
var formats = ['text/plain', 'text/html', 'application/vnd.ogc.gml'];
|
||||
expect(request.getfeatureinfo.formats).to.eql(formats);
|
||||
expect('describelayer' in request).to.be.ok();
|
||||
expect('getlegendgraphic' in request).to.be.ok();
|
||||
expect(exception).to.be.ok();
|
||||
expect(exception.formats).to.eql(['application/vnd.ogc.se_xml']);
|
||||
expect(userSymbols).to.be.ok();
|
||||
expect(userSymbols.supportSLD).to.be.ok();
|
||||
expect(userSymbols.userLayer).to.be.ok();
|
||||
expect(userSymbols.userStyle).to.be.ok();
|
||||
expect(userSymbols.remoteWFS).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test ogc', function() {
|
||||
it('Test ogc', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1/ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, capability, attribution, keywords, metadataURLs;
|
||||
obj = parser.read(xml);
|
||||
capability = obj.capability;
|
||||
attribution = capability.layers[2].attribution;
|
||||
keywords = capability.layers[0].keywords;
|
||||
metadataURLs = capability.layers[0].metadataURLs;
|
||||
expect(attribution.title).to.eql('State College University');
|
||||
expect(attribution.href).to.eql('http://www.university.edu/');
|
||||
var url = 'http://www.university.edu/icons/logo.gif';
|
||||
expect(attribution.logo.href).to.eql(url);
|
||||
expect(attribution.logo.format).to.eql('image/gif');
|
||||
expect(attribution.logo.width).to.eql('100');
|
||||
expect(attribution.logo.height).to.eql('100');
|
||||
expect(keywords.length).to.eql(3);
|
||||
expect(keywords[0].value).to.eql('road');
|
||||
expect(metadataURLs.length).to.eql(2);
|
||||
expect(metadataURLs[0].type).to.eql('FGDC');
|
||||
expect(metadataURLs[0].format).to.eql('text/plain');
|
||||
var href = 'http://www.university.edu/metadata/roads.txt';
|
||||
expect(metadataURLs[0].href).to.eql(href);
|
||||
expect(Math.round(capability.layers[0].minScale)).to.eql(250000);
|
||||
expect(Math.round(capability.layers[0].maxScale)).to.eql(1000);
|
||||
expect(capability.layers[1].minScale).to.be(undefined);
|
||||
expect(capability.layers[1].maxScale).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
@@ -0,0 +1,60 @@
|
||||
goog.provide('ol.test.parser.ogc.WMSCapabilities_v1_1_1_WMSC');
|
||||
|
||||
describe('ol.parser.ogc.wmscapabilities_v1_1_1_wmsc', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMSCapabilities({
|
||||
profile: 'WMSC',
|
||||
allowFallback: true
|
||||
});
|
||||
|
||||
describe('test read', function() {
|
||||
it('Test read', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/wmsc.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, tilesets, tileset;
|
||||
obj = parser.read(xml);
|
||||
tilesets = obj.capability.vendorSpecific.tileSets;
|
||||
tileset = tilesets[0];
|
||||
expect(tilesets.length).to.eql(2);
|
||||
var bbox = [
|
||||
-13697515.466796875, 5165920.118906248,
|
||||
-13619243.94984375, 5244191.635859374
|
||||
];
|
||||
expect(tileset.bbox['EPSG:900913'].bbox).to.eql(bbox);
|
||||
expect(tileset.format).to.eql('image/png');
|
||||
expect(tileset.height).to.eql(256);
|
||||
expect(tileset.width).to.eql(256);
|
||||
expect(tileset.layers).to.eql('medford:hydro');
|
||||
expect(tileset.srs['EPSG:900913']).to.be.ok();
|
||||
var resolutions = [156543.03390625, 78271.516953125, 39135.7584765625,
|
||||
19567.87923828125, 9783.939619140625, 4891.9698095703125,
|
||||
2445.9849047851562, 1222.9924523925781, 611.4962261962891,
|
||||
305.74811309814453, 152.87405654907226, 76.43702827453613,
|
||||
38.218514137268066, 19.109257068634033, 9.554628534317017,
|
||||
4.777314267158508, 2.388657133579254, 1.194328566789627,
|
||||
0.5971642833948135, 0.29858214169740677, 0.14929107084870338,
|
||||
0.07464553542435169, 0.037322767712175846, 0.018661383856087923,
|
||||
0.009330691928043961, 0.004665345964021981];
|
||||
expect(tileset.resolutions).to.eql(resolutions);
|
||||
expect(tileset.styles).to.eql('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test fallback', function() {
|
||||
it('Test fallback', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_1_1_WMSC/' +
|
||||
'fallback.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj;
|
||||
obj = parser.read(xml);
|
||||
expect(obj.capability.layers.length).to.eql(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
141
old/test/spec/ol/parser/ogc/wmscapabilities_v1_3_0.test.js
Normal file
141
old/test/spec/ol/parser/ogc/wmscapabilities_v1_3_0.test.js
Normal file
@@ -0,0 +1,141 @@
|
||||
goog.provide('ol.test.parser.ogc.WMSCapabilities_v1_3_0');
|
||||
|
||||
describe('ol.parser.ogc.wmscapabilities_v1_3_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMSCapabilities();
|
||||
|
||||
describe('test read exception', function() {
|
||||
it('Error reported correctly', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/' +
|
||||
'exceptionsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var result;
|
||||
result = parser.read(xml);
|
||||
expect(!!result.error).to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test read', function() {
|
||||
it('Test read', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmscapabilities_v1_3_0/ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj, capability, layers = {}, rootlayer, identifiers, authorities;
|
||||
var featurelist, time, elevation, service, contactinfo, personPrimary,
|
||||
addr, request, exception, attribution, keywords, metadataURLs;
|
||||
obj = parser.read(xml);
|
||||
capability = obj.capability;
|
||||
for (var i = 0, len = capability.layers.length; i < len; i++) {
|
||||
if ('name' in capability.layers[i]) {
|
||||
layers[capability.layers[i].name] = capability.layers[i];
|
||||
}
|
||||
}
|
||||
rootlayer = capability.layers[capability.layers.length - 1];
|
||||
identifiers = layers['ROADS_RIVERS'].identifiers;
|
||||
authorities = layers['ROADS_RIVERS'].authorityURLs;
|
||||
featurelist = layers['ROADS_RIVERS'].featureListURL;
|
||||
time = layers['Clouds'].dimensions.time;
|
||||
elevation = layers['Pressure'].dimensions.elevation;
|
||||
service = obj.service;
|
||||
contactinfo = service.contactInformation;
|
||||
personPrimary = contactinfo.personPrimary;
|
||||
addr = contactinfo.contactAddress;
|
||||
request = obj.capability.request;
|
||||
exception = obj.capability.exception;
|
||||
attribution = capability.layers[2].attribution;
|
||||
keywords = capability.layers[0].keywords;
|
||||
metadataURLs = capability.layers[0].metadataURLs;
|
||||
expect(rootlayer.srs).to.eql({'CRS:84': true});
|
||||
var srs = {'CRS:84': true, 'EPSG:26986': true};
|
||||
expect(layers['ROADS_RIVERS'].srs).to.eql(srs);
|
||||
expect(layers['Temperature'].srs).to.eql({'CRS:84': true});
|
||||
var infoFormats = ['text/xml', 'text/plain', 'text/html'];
|
||||
expect(layers['Temperature'].infoFormats).to.eql(infoFormats);
|
||||
var bbox = layers['ROADS_RIVERS'].bbox['EPSG:26986'];
|
||||
expect(bbox.bbox).to.eql([189000, 834000, 285000, 962000]);
|
||||
expect(bbox.res).to.eql({x: 1, y: 1});
|
||||
bbox = layers['ROADS_RIVERS'].bbox['CRS:84'];
|
||||
expect(bbox.bbox).to.eql([-71.63, 41.75, -70.78, 42.90]);
|
||||
expect(bbox.res).to.eql({x: 0.01, y: 0.01});
|
||||
bbox = layers['ROADS_1M'].bbox['EPSG:26986'];
|
||||
expect(bbox.bbox).to.eql([189000, 834000, 285000, 962000]);
|
||||
expect(bbox.res).to.eql({x: 1, y: 1});
|
||||
expect(identifiers).to.be.ok();
|
||||
expect('DIF_ID' in identifiers).to.be.ok();
|
||||
expect(identifiers['DIF_ID']).to.eql('123456');
|
||||
expect('DIF_ID' in authorities).to.be.ok();
|
||||
var url = 'http://gcmd.gsfc.nasa.gov/difguide/whatisadif.html';
|
||||
expect(authorities['DIF_ID']).to.eql(url);
|
||||
expect(featurelist).to.be.ok();
|
||||
expect(featurelist.format).to.eql('XML');
|
||||
url = 'http://www.university.edu/data/roads_rivers.gml';
|
||||
expect(featurelist.href).to.eql(url);
|
||||
expect(layers['Pressure'].queryable).to.be.ok();
|
||||
expect(layers['ozone_image'].queryable).to.not.be();
|
||||
expect(layers['population'].cascaded).to.eql(1);
|
||||
expect(layers['ozone_image'].fixedWidth).to.eql(512);
|
||||
expect(layers['ozone_image'].fixedHeight).to.eql(256);
|
||||
expect(layers['ozone_image'].opaque).to.be.ok();
|
||||
expect(layers['ozone_image'].noSubsets).to.be.ok();
|
||||
expect(time['default']).to.eql('2000-08-22');
|
||||
expect(time.values.length).to.eql(1);
|
||||
expect(time.values[0]).to.eql('1999-01-01/2000-08-22/P1D');
|
||||
expect(elevation.units).to.eql('CRS:88');
|
||||
expect(elevation['default']).to.eql('0');
|
||||
expect(elevation.nearestVal).to.be.ok();
|
||||
expect(elevation.multipleVal).to.not.be();
|
||||
expect(elevation.values).to.eql(
|
||||
['0', '1000', '3000', '5000', '10000']);
|
||||
expect(contactinfo).to.be.ok();
|
||||
expect(personPrimary).to.be.ok();
|
||||
expect(personPrimary.person).to.eql('Jeff Smith');
|
||||
expect(personPrimary.organization).to.eql('NASA');
|
||||
expect(contactinfo.position).to.eql('Computer Scientist');
|
||||
expect(addr).to.be.ok();
|
||||
expect(addr.type).to.eql('postal');
|
||||
expect(addr.address).to.eql('NASA Goddard Space Flight Center');
|
||||
expect(addr.city).to.eql('Greenbelt');
|
||||
expect(addr.stateOrProvince).to.eql('MD');
|
||||
expect(addr.postcode).to.eql('20771');
|
||||
expect(addr.country).to.eql('USA');
|
||||
expect(contactinfo.phone).to.eql('+1 301 555-1212');
|
||||
expect(contactinfo.email).to.eql('user@host.com');
|
||||
expect('fees' in service).to.not.be();
|
||||
expect('accessConstraints' in service).to.not.be();
|
||||
expect(request).to.be.ok();
|
||||
expect('getmap' in request).to.be.ok();
|
||||
expect('getfeatureinfo' in request).to.be.ok();
|
||||
var formats = ['text/xml', 'text/plain', 'text/html'];
|
||||
expect(request.getfeatureinfo.formats).to.eql(formats);
|
||||
expect(exception).to.be.ok();
|
||||
formats = ['XML', 'INIMAGE', 'BLANK'];
|
||||
expect(exception.formats).to.eql(formats);
|
||||
expect(attribution.title).to.eql('State College University');
|
||||
expect(attribution.href).to.eql('http://www.university.edu/');
|
||||
url = 'http://www.university.edu/icons/logo.gif';
|
||||
expect(attribution.logo.href).to.eql(url);
|
||||
expect(attribution.logo.format).to.eql('image/gif');
|
||||
expect(attribution.logo.width).to.eql('100');
|
||||
expect(attribution.logo.height).to.eql('100');
|
||||
expect(keywords.length).to.eql(3);
|
||||
expect(keywords[0].value).to.eql('road');
|
||||
expect(metadataURLs.length).to.eql(2);
|
||||
expect(metadataURLs[0].type).to.eql('FGDC:1998');
|
||||
expect(metadataURLs[0].format).to.eql('text/plain');
|
||||
url = 'http://www.university.edu/metadata/roads.txt';
|
||||
expect(metadataURLs[0].href).to.eql(url);
|
||||
var minScale = 250000;
|
||||
expect(capability.layers[0].minScale).to.eql(minScale.toPrecision(16));
|
||||
var maxScale = 1000;
|
||||
expect(capability.layers[0].maxScale).to.eql(maxScale.toPrecision(16));
|
||||
expect(obj.service.layerLimit).to.eql(16);
|
||||
expect(obj.service.maxHeight).to.eql(2048);
|
||||
expect(obj.service.maxWidth).to.eql(2048);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMSCapabilities');
|
||||
159
old/test/spec/ol/parser/ogc/wmtscapabilities_v1_0_0.test.js
Normal file
159
old/test/spec/ol/parser/ogc/wmtscapabilities_v1_0_0.test.js
Normal file
@@ -0,0 +1,159 @@
|
||||
goog.provide('ol.test.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
|
||||
describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||
|
||||
describe('test ows', function() {
|
||||
it('Test ows', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var serviceIdentification = obj.serviceIdentification;
|
||||
var serviceProvider = obj.serviceProvider;
|
||||
var operationsMetadata = obj.operationsMetadata;
|
||||
var contactInfo = serviceProvider.serviceContact.contactInfo;
|
||||
|
||||
expect(serviceIdentification.title).to.eql('Web Map Tile Service');
|
||||
expect(serviceIdentification.serviceTypeVersion).to.eql('1.0.0');
|
||||
expect(serviceIdentification.serviceType.value).to.eql('OGC WMTS');
|
||||
expect(serviceProvider.providerName).to.eql('MiraMon');
|
||||
var url = 'http://www.creaf.uab.es/miramon';
|
||||
expect(serviceProvider.providerSite).to.eql(url);
|
||||
var name = 'Joan Maso Pau';
|
||||
expect(serviceProvider.serviceContact.individualName).to.eql(name);
|
||||
var position = 'Senior Software Engineer';
|
||||
expect(serviceProvider.serviceContact.positionName).to.eql(position);
|
||||
expect(contactInfo.address.administrativeArea).to.eql('Barcelona');
|
||||
expect(contactInfo.address.city).to.eql('Bellaterra');
|
||||
expect(contactInfo.address.country).to.eql('Spain');
|
||||
expect(contactInfo.address.deliveryPoint).to.eql('Fac Ciencies UAB');
|
||||
var email = 'joan.maso@uab.es';
|
||||
expect(contactInfo.address.electronicMailAddress).to.eql(email);
|
||||
expect(contactInfo.address.postalCode).to.eql('08193');
|
||||
expect(contactInfo.phone.voice).to.eql('+34 93 581 1312');
|
||||
var dcp = operationsMetadata.GetCapabilities.dcp;
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
expect(dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetCapabilities.dcp;
|
||||
expect(dcp.http.get[0].constraints.GetEncoding.allowedValues).to.eql(
|
||||
{'KVP': true});
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
dcp = operationsMetadata.GetFeatureInfo.dcp;
|
||||
expect(dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetFeatureInfo.dcp;
|
||||
expect(dcp.http.get[0].constraints).to.be(undefined);
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
expect(operationsMetadata.GetTile.dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetTile.dcp;
|
||||
expect(dcp.http.get[0].constraints).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('test layers', function() {
|
||||
it('Test layers', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var contents = obj.contents;
|
||||
var layer = contents.layers[0];
|
||||
var wgs84Bbox = layer.bounds;
|
||||
var dimensions = layer.dimensions;
|
||||
|
||||
expect(contents.layers.length).to.eql(1);
|
||||
expect(layer['abstract']).to.eql('Coastline/shorelines (BA010)');
|
||||
expect(layer.identifier).to.eql('coastlines');
|
||||
expect(layer.title).to.eql('Coastlines');
|
||||
expect(layer.formats.length).to.eql(2);
|
||||
expect(layer.formats[0]).to.eql('image/png');
|
||||
expect(layer.formats[1]).to.eql('image/gif');
|
||||
expect(layer.styles.length).to.eql(2);
|
||||
expect(layer.styles[0].identifier).to.eql('DarkBlue');
|
||||
expect(layer.styles[0].isDefault).to.be.ok();
|
||||
expect(layer.styles[0].title).to.eql('Dark Blue');
|
||||
var url = 'http://www.miramon.uab.es/wmts/Coastlines/' +
|
||||
'coastlines_darkBlue.png';
|
||||
expect(layer.styles[0].legend.href).to.eql(url);
|
||||
expect(layer.styles[0].legend.format).to.eql('image/png');
|
||||
expect(layer.styles[1].identifier).to.eql('thickAndRed');
|
||||
expect(!layer.styles[1].isDefault).to.be.ok();
|
||||
expect(layer.styles[1].title).to.eql('Thick And Red');
|
||||
expect(layer.styles[1].legend).to.be(undefined);
|
||||
expect(layer.tileMatrixSetLinks.length).to.eql(1);
|
||||
expect(layer.tileMatrixSetLinks[0].tileMatrixSet).to.eql('BigWorld');
|
||||
expect(wgs84Bbox).to.be.an(Array);
|
||||
expect(wgs84Bbox[0]).to.eql(-180.0);
|
||||
expect(wgs84Bbox[1]).to.eql(180.0);
|
||||
expect(wgs84Bbox[2]).to.eql(-90.0);
|
||||
expect(wgs84Bbox[3]).to.eql(90.0);
|
||||
expect(layer.resourceUrls.hasOwnProperty('tile')).to.be.ok();
|
||||
var format = 'image/png';
|
||||
expect(layer.resourceUrls.tile.hasOwnProperty(format)).to.be.ok();
|
||||
expect(layer.resourceUrls.tile[format].length).to.eql(2);
|
||||
var tpl = 'http://a.example.com/wmts/coastlines/{TileMatrix}/' +
|
||||
'{TileRow}/{TileCol}.png';
|
||||
expect(layer.resourceUrls.tile[format][0]).to.eql(tpl);
|
||||
tpl = 'http://b.example.com/wmts/coastlines/{TileMatrix}/' +
|
||||
'{TileRow}/{TileCol}.png';
|
||||
expect(layer.resourceUrls.tile[format][1]).to.eql(tpl);
|
||||
expect(layer.resourceUrls.hasOwnProperty('FeatureInfo')).to.be.ok();
|
||||
format = 'application/gml+xml; version=3.1';
|
||||
expect(layer.resourceUrls.FeatureInfo.hasOwnProperty(format))
|
||||
.to.be.ok();
|
||||
expect(layer.resourceUrls.FeatureInfo[format].length).to.eql(1);
|
||||
tpl = 'http://www.example.com/wmts/coastlines/{TileMatrixSet}/' +
|
||||
'{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}.xml';
|
||||
expect(layer.resourceUrls.FeatureInfo[format][0]).to.eql(tpl);
|
||||
expect(dimensions.length).to.eql(1);
|
||||
expect(dimensions[0].title).to.eql('Time');
|
||||
expect(dimensions[0]['abstract']).to.eql('Monthly datasets');
|
||||
expect(dimensions[0].identifier).to.eql('TIME');
|
||||
expect(dimensions[0]['default']).to.eql('default');
|
||||
expect(dimensions[0].values.length).to.eql(3);
|
||||
expect(dimensions[0].values[0]).to.eql('2007-05');
|
||||
expect(dimensions[0].values[1]).to.eql('2007-06');
|
||||
expect(dimensions[0].values[1]).to.eql('2007-06');
|
||||
expect(dimensions[0].values[2]).to.eql('2007-07');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test tileMatrixSets', function() {
|
||||
it('Test tileMatrixSets', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var tileMatrixSets = obj.contents.tileMatrixSets;
|
||||
var bigWorld = tileMatrixSets['BigWorld'];
|
||||
|
||||
expect(bigWorld).to.not.be(undefined);
|
||||
expect(bigWorld.identifier).to.eql('BigWorld');
|
||||
expect(bigWorld.matrixIds.length).to.eql(2);
|
||||
expect(bigWorld.matrixIds[0].identifier).to.eql('1e6');
|
||||
expect(bigWorld.matrixIds[0].matrixHeight).to.eql(50000);
|
||||
expect(bigWorld.matrixIds[0].matrixWidth).to.eql(60000);
|
||||
expect(bigWorld.matrixIds[0].scaleDenominator).to.eql(1000000);
|
||||
expect(bigWorld.matrixIds[0].tileWidth).to.eql(256);
|
||||
expect(bigWorld.matrixIds[0].tileHeight).to.eql(256);
|
||||
expect(bigWorld.matrixIds[0].topLeftCorner[0]).to.eql(-180);
|
||||
expect(bigWorld.matrixIds[0].topLeftCorner[1]).to.eql(84);
|
||||
expect(bigWorld.matrixIds[1].identifier).to.eql('2.5e6');
|
||||
expect(bigWorld.matrixIds[1].matrixHeight).to.eql(7000);
|
||||
expect(bigWorld.matrixIds[1].matrixWidth).to.eql(9000);
|
||||
expect(bigWorld.matrixIds[1].scaleDenominator).to.eql(2500000);
|
||||
expect(bigWorld.matrixIds[1].tileWidth).to.eql(256);
|
||||
expect(bigWorld.matrixIds[1].tileHeight).to.eql(256);
|
||||
expect(bigWorld.matrixIds[1].topLeftCorner[0]).to.eql(-180);
|
||||
expect(bigWorld.matrixIds[1].topLeftCorner[1]).to.eql(84);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ows:ExceptionReport language="en" version="1.0.0"
|
||||
xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows">
|
||||
<ows:Exception locator="foo" exceptionCode="InvalidParameterValue">
|
||||
<ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>
|
||||
<ows:ExceptionText>Second exception line</ows:ExceptionText>
|
||||
</ows:Exception>
|
||||
</ows:ExceptionReport>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ows:ExceptionReport xml:lang="en" version="1.1.0"
|
||||
xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1">
|
||||
<ows:Exception locator="foo" exceptionCode="InvalidParameterValue">
|
||||
<ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>
|
||||
<ows:ExceptionText>Second exception line</ows:ExceptionText>
|
||||
</ows:Exception>
|
||||
</ows:ExceptionReport>
|
||||
16
old/test/spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml
Normal file
16
old/test/spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.opengis.net/ogc
|
||||
http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
|
||||
<ServiceException> Plain text message about an error. </ServiceException>
|
||||
<ServiceException code="InvalidUpdateSequence"> Another error message, this one with a service exception code supplied. </ServiceException>
|
||||
<ServiceException>
|
||||
<![CDATA[ Error in module <foo.c>, line 42
|
||||
A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:' +
|
||||
]]>
|
||||
</ServiceException>
|
||||
<ServiceException>
|
||||
<![CDATA[ <Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation> ]]>
|
||||
</ServiceException>
|
||||
</ServiceExceptionReport>
|
||||
23
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0.xml
Normal file
23
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
8
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/bbox.xml
Normal file
8
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/bbox.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,7 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
11
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/between.xml
Normal file
11
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/between.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>0</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>100</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,7 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>0</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>100</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/contains.xml
Normal file
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/contains.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Contains>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Contains>
|
||||
</Filter>
|
||||
@@ -0,0 +1,9 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<DWithin>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552</gml:coordinates>
|
||||
</gml:Point>
|
||||
<Distance units="m">1000</Distance>
|
||||
</DWithin>
|
||||
</Filter>
|
||||
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/intersects.xml
Normal file
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/intersects.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Intersects>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Intersects>
|
||||
</Filter>
|
||||
@@ -0,0 +1,10 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>me</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:FeatureId fid="foo.1"/>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,10 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:And>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>me</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:FeatureId fid="foo.1"/>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:And>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,5 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:Not>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:Not>
|
||||
</ogc:Filter>
|
||||
5
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/null.xml
Normal file
5
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/null.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:PropertyIsNull>
|
||||
<ogc:PropertyName>prop</ogc:PropertyName>
|
||||
</ogc:PropertyIsNull>
|
||||
</ogc:Filter>
|
||||
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/within.xml
Normal file
12
old/test/spec/ol/parser/ogc/xml/filter_v1_0_0/within.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Within>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Within>
|
||||
</Filter>
|
||||
9
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/bbox.xml
Normal file
9
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/bbox.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,8 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,11 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:And>
|
||||
<ogc:PropertyIsNotEqualTo matchCase="false">
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Function name="customFunction">
|
||||
<ogc:Literal>param1</ogc:Literal>
|
||||
<ogc:Literal>param2</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:PropertyIsNotEqualTo>
|
||||
</ogc:And>
|
||||
</ogc:Filter>
|
||||
10
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/function.xml
Normal file
10
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/function.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:Intersects>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<ogc:Function name="querySingle">
|
||||
<ogc:Literal>sf:restricted</ogc:Literal>
|
||||
<ogc:Literal>the_geom</ogc:Literal>
|
||||
<ogc:Literal>cat=3</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:Intersects>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,9 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<Intersects>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</Intersects>
|
||||
</Filter>
|
||||
@@ -0,0 +1,6 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!" matchCase="false">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>*me*</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
</ogc:Filter>
|
||||
@@ -0,0 +1,13 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:DWithin>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<ogc:Function name="collectGeometries">
|
||||
<ogc:Function name="queryCollection">
|
||||
<ogc:Literal>sf:roads</ogc:Literal>
|
||||
<ogc:Literal>the_geom</ogc:Literal>
|
||||
<ogc:Literal>INCLUDE</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:Function>
|
||||
<ogc:Distance units="meters">200</ogc:Distance>
|
||||
</ogc:DWithin>
|
||||
</ogc:Filter>
|
||||
10
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/sortby.xml
Normal file
10
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/sortby.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<ogc:SortBy xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:SortProperty>
|
||||
<ogc:PropertyName>Title</ogc:PropertyName>
|
||||
<ogc:SortOrder>ASC</ogc:SortOrder>
|
||||
</ogc:SortProperty>
|
||||
<ogc:SortProperty>
|
||||
<ogc:PropertyName>Relevance</ogc:PropertyName>
|
||||
<ogc:SortOrder>DESC</ogc:SortOrder>
|
||||
</ogc:SortProperty>
|
||||
</ogc:SortBy>
|
||||
31
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/test.xml
Normal file
31
old/test/spec/ol/parser/ogc/xml/filter_v1_1_0/test.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
<ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>dog</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyIsEqualTo matchCase="false">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>dog</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
1
old/test/spec/ol/parser/ogc/xml/gml_v2/boundedBy.xml
Normal file
1
old/test/spec/ol/parser/ogc/xml/gml_v2/boundedBy.xml
Normal file
File diff suppressed because one or more lines are too long
10
old/test/spec/ol/parser/ogc/xml/gml_v2/box-coord.xml
Normal file
10
old/test/spec/ol/parser/ogc/xml/gml_v2/box-coord.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Box>
|
||||
@@ -0,0 +1,3 @@
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:Box>
|
||||
@@ -0,0 +1,31 @@
|
||||
<gml:GeometryCollection xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:geometryMember>
|
||||
<gml:Point srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:geometryMember>
|
||||
<gml:geometryMember>
|
||||
<gml:LineString srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:geometryMember>
|
||||
<gml:geometryMember>
|
||||
<gml:Polygon srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:geometryMember>
|
||||
</gml:GeometryCollection>
|
||||
18
old/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coord.xml
Normal file
18
old/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coord.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
@@ -0,0 +1,3 @@
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
10
old/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coord.xml
Normal file
10
old/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coord.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
@@ -0,0 +1,3 @@
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:LineString>
|
||||
@@ -0,0 +1,26 @@
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
@@ -0,0 +1,12 @@
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 2,3</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 4,5</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
@@ -0,0 +1 @@
|
||||
<?xml version='1.0' encoding="ISO-8859-1" ?><wfs:FeatureCollection xmlns:rws="http://mapserver.gis.umn.edu/mapserver" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://mapserver.gis.umn.edu/mapserver http://intranet.rijkswaterstaat.nl/services/geoservices/kerngisnat_utre?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=VKUNSTWERK,LKUNSTWERK,PKUNSTWERK&OUTPUTFORMAT=XMLSCHEMA"> <gml:boundedBy> <gml:Box srsName="EPSG:28992"> <gml:coordinates>134503.789000,455332.337000 135149.909000,455893.926000</gml:coordinates> </gml:Box> </gml:boundedBy> <gml:featureMember> <rws:VKUNSTWERK fid="VKUNSTWERK.16"> <gml:boundedBy> <gml:Box srsName="EPSG:28992"> <gml:coordinates>134949.571000,455438.845000 134978.799000,455471.762000</gml:coordinates> </gml:Box> </gml:boundedBy> <rws:geometry> <gml:MultiPolygon srsName="EPSG:28992"> <gml:polygonMember> <gml:Polygon> <gml:outerBoundaryIs> <gml:LinearRing> <gml:coordinates>134974.191000,455471.587000 134973.974000,455471.762000 134973.558000,455471.248000 134973.579000,455471.230000 134963.143000,455458.768000 134962.787000,455458.653000 134960.514000,455456.003000 134960.440000,455455.539000 134950.207000,455443.320000 134950.158000,455443.360000 134949.571000,455442.638000 134949.810000,455442.462000 134951.417000,455441.223000 134951.435000,455441.209000 134954.158000,455439.108000 134954.507000,455438.845000 134955.000000,455439.420000 134954.954000,455439.458000 134965.046000,455451.520000 134965.568000,455451.606000 134968.159000,455454.642000 134968.120000,455455.195000 134978.294000,455467.355000 134978.330000,455467.326000 134978.799000,455467.881000 134978.598000,455468.042000 134975.885000,455470.224000 134974.191000,455471.587000 </gml:coordinates> </gml:LinearRing> </gml:outerBoundaryIs> <gml:innerBoundaryIs> <gml:LinearRing> <gml:coordinates>134960.590000,455455.163000 134963.589000,455458.755000 134973.756000,455470.929000 134973.836000,455471.019000 134974.216000,455471.445000 134975.807000,455470.163000 134978.485000,455468.005000 134978.077000,455467.534000 134978.015000,455467.462000 134967.969000,455455.479000 134964.782000,455451.678000 134954.705000,455439.660000 134954.622000,455439.561000 134954.271000,455439.152000 134951.498000,455441.284000 134949.973000,455442.456000 134950.452000,455443.023000 134950.501000,455443.081000 134960.590000,455455.163000 </gml:coordinates> </gml:LinearRing> </gml:innerBoundaryIs> </gml:Polygon> </gml:polygonMember> </gml:MultiPolygon> </rws:geometry> <rws:OBJECTID>16</rws:OBJECTID> <rws:OBJECTSUBCATEGORIE>31</rws:OBJECTSUBCATEGORIE> </rws:VKUNSTWERK> </gml:featureMember> <gml:featureMember> <rws:LKUNSTWERK fid="LKUNSTWERK.14"> <gml:boundedBy> <gml:Box srsName="EPSG:28992"> <gml:coordinates>135080.966000,455332.337000 135149.909000,455390.384000</gml:coordinates> </gml:Box> </gml:boundedBy> <rws:geometry> <gml:MultiLineString srsName="EPSG:28992"> <gml:lineStringMember> <gml:LineString> <gml:coordinates>135080.966000,455390.384000 135096.654000,455377.009000 135109.082000,455366.755000 135122.769000,455355.276000 135141.565000,455339.633000 135149.909000,455332.337000 </gml:coordinates> </gml:LineString> </gml:lineStringMember> </gml:MultiLineString> </rws:geometry> <rws:OBJECTID>14</rws:OBJECTID> <rws:OBJECTSUBCATEGORIE>30</rws:OBJECTSUBCATEGORIE> </rws:LKUNSTWERK> </gml:featureMember> <gml:featureMember> <rws:PKUNSTWERK fid="PKUNSTWERK.29"> <gml:boundedBy> <gml:Box srsName="EPSG:28992"> <gml:coordinates>134832.017000,455596.187000 134832.017000,455596.187000</gml:coordinates> </gml:Box> </gml:boundedBy> <rws:geometry> <gml:MultiPoint srsName="EPSG:28992"> <gml:pointMember> <gml:Point> <gml:coordinates>134832.017000,455596.187000</gml:coordinates> </gml:Point> </gml:pointMember> </gml:MultiPoint> </rws:geometry> <rws:OBJECTID>29</rws:OBJECTID> <rws:OBJECTSUBCATEGORIE>30</rws:OBJECTSUBCATEGORIE> </rws:PKUNSTWERK> </gml:featureMember></wfs:FeatureCollection>
|
||||
26
old/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coord.xml
Normal file
26
old/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coord.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
@@ -0,0 +1,17 @@
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
@@ -0,0 +1,90 @@
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
@@ -0,0 +1,30 @@
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,2 3,4 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
1
old/test/spec/ol/parser/ogc/xml/gml_v2/nogeom.xml
Normal file
1
old/test/spec/ol/parser/ogc/xml/gml_v2/nogeom.xml
Normal file
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:loc="http://server.fr/geoserver/loc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://server.fr:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd http://server.fr/geoserver/loc http://server.fr:80/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=loc:DEPARTEMENT"><gml:boundedBy><gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#2154"><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">199373,6704170 337568,6885985</gml:coordinates></gml:Box></gml:boundedBy><gml:featureMember><loc:DEPARTEMENT fid="DEPARTEMENT.1"><gml:boundedBy><gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#2154"><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">209565,6785323 337568,6885985</gml:coordinates></gml:Box></gml:boundedBy><loc:NOM_DEPT>COTES-D'ARMOR</loc:NOM_DEPT></loc:DEPARTEMENT></gml:featureMember><gml:featureMember><loc:DEPARTEMENT fid="DEPARTEMENT.3"><gml:boundedBy><gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#2154"><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">199373,6704170 323518,6807542</gml:coordinates></gml:Box></gml:boundedBy><loc:NOM_DEPT>MORBIHAN</loc:NOM_DEPT></loc:DEPARTEMENT></gml:featureMember></wfs:FeatureCollection>
|
||||
6
old/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml
Normal file
6
old/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="FOO">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
@@ -0,0 +1,3 @@
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
62
old/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coord.xml
Normal file
62
old/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coord.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>6</gml:X>
|
||||
<gml:Y>7</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>7</gml:X>
|
||||
<gml:Y>8</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
@@ -0,0 +1,17 @@
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 5,2 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 2,5 4,5 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 3,6 5,6 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
1
old/test/spec/ol/parser/ogc/xml/gml_v2/topp-states.xml
Normal file
1
old/test/spec/ol/parser/ogc/xml/gml_v2/topp-states.xml
Normal file
File diff suppressed because one or more lines are too long
7
old/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml
Normal file
7
old/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<gml:Curve xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:segments>
|
||||
<gml:LineStringSegment>
|
||||
<gml:posList>1 2 3 4</gml:posList>
|
||||
</gml:LineStringSegment>
|
||||
</gml:segments>
|
||||
</gml:Curve>
|
||||
15
old/test/spec/ol/parser/ogc/xml/gml_v3/empty-attribute.xml
Normal file
15
old/test/spec/ol/parser/ogc/xml/gml_v3/empty-attribute.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<gml:featureMembers xmlns:gml="http://www.opengis.net/gml">
|
||||
<topp:gnis_pop gml:id="gnis_pop.148604" xmlns:topp="http://www.openplans.org/topp">
|
||||
<gml:name>Aflu</gml:name>
|
||||
<topp:the_geom>
|
||||
<gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
|
||||
<gml:pos>34.12 2.09</gml:pos>
|
||||
</gml:Point>
|
||||
</topp:the_geom>
|
||||
<topp:population>84683</topp:population>
|
||||
<topp:country>Algeria</topp:country>
|
||||
<topp:type>place</topp:type>
|
||||
<topp:name>Aflu</topp:name>
|
||||
<topp:empty></topp:empty>
|
||||
</topp:gnis_pop>
|
||||
</gml:featureMembers>
|
||||
4
old/test/spec/ol/parser/ogc/xml/gml_v3/envelope.xml
Normal file
4
old/test/spec/ol/parser/ogc/xml/gml_v3/envelope.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lowerCorner>1 2</gml:lowerCorner>
|
||||
<gml:upperCorner>3 4</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml
Normal file
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml
Normal file
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:posList>1 2 3 4</gml:posList>
|
||||
</gml:LineString>
|
||||
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linestring3d.xml
Normal file
3
old/test/spec/ol/parser/ogc/xml/gml_v3/linestring3d.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo" srsDimension="3">
|
||||
<gml:posList>1 2 3 4 5 6</gml:posList>
|
||||
</gml:LineString>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user