git-svn-id: http://svn.openlayers.org/trunk/openlayers@6645 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
100 lines
3.5 KiB
HTML
100 lines
3.5 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_Comparison_constructor(t) {
|
|
t.plan(3);
|
|
|
|
var options = {'foo': 'bar'};
|
|
var rule = new OpenLayers.Rule.Comparison(options);
|
|
t.ok(rule instanceof OpenLayers.Rule.Comparison,
|
|
"new OpenLayers.Rule.Comparison returns object" );
|
|
t.eq(rule.foo, "bar", "constructor sets options correctly");
|
|
t.eq(typeof rule.evaluate, "function", "rule has an evaluate function");
|
|
}
|
|
|
|
function test_Comparison_destroy(t) {
|
|
t.plan(1);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison();
|
|
rule.destroy();
|
|
t.eq(rule.symbolizer, null, "symbolizer hash nulled properly");
|
|
}
|
|
|
|
function test_Comparison_value2regex(t) {
|
|
t.plan(2);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison({
|
|
property: "foo",
|
|
value: "*b?r\\*\\?*",
|
|
type: OpenLayers.Rule.Comparison.LIKE});
|
|
rule.value2regex("*", "?", "\\");
|
|
t.eq(rule.value, ".*b.r\\*\\?.*", "Regular expression generated correctly.");
|
|
|
|
rule.value = "%b.r!%!.%";
|
|
rule.value2regex("%", ".", "!");
|
|
t.eq(rule.value, ".*b.r\\%\\..*", "Regular expression with different wildcard and escape chars generated correctly.");
|
|
}
|
|
|
|
function test_regex2value(t) {
|
|
t.plan(8);
|
|
|
|
function r2v(regex) {
|
|
return OpenLayers.Rule.Comparison.prototype.regex2value.call(
|
|
{value: regex}
|
|
);
|
|
}
|
|
|
|
t.eq(r2v("foo"), "foo", "doesn't change string without special chars");
|
|
t.eq(r2v("foo.*foo"), "foo*foo", "wildCard replaced");
|
|
t.eq(r2v("foo.foo"), "foo.foo", "singleChar replaced");
|
|
t.eq(r2v("foo\\\\foo"), "foo\\foo", "escape removed");
|
|
t.eq(r2v("foo!foo"), "foo!!foo", "escapes !");
|
|
t.eq(r2v("foo\\*foo"), "foo!*foo", "replaces escape on *");
|
|
t.eq(r2v("foo\\.foo"), "foo!.foo", "replaces escape on .");
|
|
t.eq(r2v("foo\\\\.foo"), "foo\\.foo", "unescapes only \\ before .");
|
|
|
|
}
|
|
|
|
function test_Comparison_evaluate(t) {
|
|
t.plan(5);
|
|
|
|
var rule = new OpenLayers.Rule.Comparison({
|
|
property: "area",
|
|
lowerBoundary: 1000,
|
|
upperBoundary: 4999,
|
|
type: OpenLayers.Rule.Comparison.BETWEEN});
|
|
|
|
var features = [
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 999}),
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 1000}),
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 4999}),
|
|
new OpenLayers.Feature.Vector(null, {
|
|
area: 5000})];
|
|
// PropertyIsBetween filter: lower and upper boundary are inclusive
|
|
var ruleResults = {
|
|
0: false,
|
|
1: true,
|
|
2: true,
|
|
3: false};
|
|
for (var i in ruleResults) {
|
|
var result = rule.evaluate(features[i]);
|
|
t.eq(result, ruleResults[i], "feature "+i+
|
|
" evaluates to "+result.toString()+" correctly.");
|
|
}
|
|
rule.context = {
|
|
area: 4998
|
|
}
|
|
var result = rule.evaluate();
|
|
t.eq(result, true, "evaluation against custom rule context works.");
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|