Skip to content

Commit

Permalink
Rebase tests on new serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Apr 6, 2018
1 parent ca787ff commit 9a7af92
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 67 deletions.
16 changes: 16 additions & 0 deletions src/style-spec/expression/definitions/collator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ export class CollatorInstantiation {
return new Intl.Collator(this.locale ? this.locale : [])
.resolvedOptions().locale;
}

serialize() {
const serialized = ["collator"];
serialized.push(this.sensitivity === 'variant' || this.sensitivity === 'case');
serialized.push(this.sensitivity === 'variant' || this.sensitivity === 'accent');
if (this.locale) {
serialized.push(this.locale);
}
return serialized;
}
}

export class CollatorExpression implements Expression {
Expand Down Expand Up @@ -111,4 +121,10 @@ export class CollatorExpression implements Expression {
// possibleOutputs anyway, so we can get away with leaving this undefined for now.
return [undefined];
}

serialize() {
const serialized = ["collator"];
this.eachChild(child => { serialized.push(child.serialize()); });
return serialized;
}
}
5 changes: 3 additions & 2 deletions src/style-spec/expression/definitions/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Expression } from '../expression';
import type EvaluationContext from '../evaluation_context';
import type ParsingContext from '../parsing_context';
import type { Type } from '../types';
import type { Value } from '../values';

function isComparableType(type: Type) {
return type.kind === 'string' ||
Expand Down Expand Up @@ -93,7 +92,9 @@ function makeComparison(op: string, negate: boolean) {
}

serialize() {
return [op, this.lhs.serialize(), this.rhs.serialize()];
const serialized = [op];
this.eachChild(child => { serialized.push(child.serialize()); });
return serialized;
}
};
}
Expand Down
1 change: 1 addition & 0 deletions src/style-spec/expression/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ CompoundExpression.register(expressions, {
(ctx, args) => args.map(arg => arg.evaluate(ctx)).join('')
],
'resolved-locale': [
// Must be added to non-featureConstant list in parsing_context.js
StringType,
[CollatorType],
(ctx, [collator]) => collator.evaluate(ctx).resolvedLocale()
Expand Down
2 changes: 2 additions & 0 deletions src/style-spec/expression/definitions/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Literal implements Expression {
return ["literal", this.value];
} else if (this.value instanceof Color) {
return ["rgba"].concat(this.value.toArray());
} else if (this.type.kind === 'collator') {
return this.value.serialize();
} else {
assert(this.value === null ||
typeof this.value === 'string' ||
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/parsing_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ function isConstant(expression: Expression) {
}

return isFeatureConstant(expression) &&
isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density']);
isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density', 'resolved-locale', 'collator']);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"expression": ["case",
["==", ["resolved-locale", ["collator", true, false, "de"]], "de"],
["==", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", true, false, "de"]],
["case", ["==", ["get", "rhs"], "ue"], true, false]
"expression": [
"case",
["==", ["resolved-locale", ["collator", true, false, "de"]], "de"],
[
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", true, false, "de"]
],
["case", ["==", ["get", "rhs"], "ue"], true, false]
],
"inputs": [
[{}, {"properties": {"lhs": "ü", "rhs": "ue"}}],
[{}, {"properties": {"lhs": "ü", "rhs": "u"}}]
[{}, {"properties": {"lhs": "ü", "rhs": "ue"}}],
[{}, {"properties": {"lhs": "ü", "rhs": "u"}}]
],
"expected": {
"compiled": {
Expand All @@ -16,6 +22,16 @@
"type": "boolean"
},
"outputs": [true, false],
"serialized": "string"
"serialized": [
"case",
["==", ["resolved-locale", ["collator", true, false, "de"]], "de"],
[
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", true, false, "de"]
],
["case", ["==", ["get", "rhs"], "ue"], true, false]
]
}
}
20 changes: 15 additions & 5 deletions test/integration/expression-tests/collator/accent-lt-en/test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"expression": ["<", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", true, false, "en"]],
"expression": [
"<",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", true, false, "en"]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "ä", "rhs": "b"}}]
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "ä", "rhs": "b"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +18,11 @@
"type": "boolean"
},
"outputs": [false, true, true],
"serialized": "string"
"serialized": [
"<",
["string", ["get", "lhs"]],
["string", ["get", "rhs"]],
["collator", true, false, "en"]
]
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"expression": ["!", ["!=", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", true, false, "en"]]],
"expression": [
"!",
[
"!=",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", true, false, "en"]
]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +21,14 @@
"type": "boolean"
},
"outputs": [true, false, false],
"serialized": "string"
"serialized": [
"!",
[
"!=",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", true, false, "en"]
]
]
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"expression": ["==", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", false, false]],
"expression": [
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, false]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "a"}}],
[{}, {"properties": {"lhs": "A", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "a"}}]
[{}, {"properties": {"lhs": "a", "rhs": "a"}}],
[{}, {"properties": {"lhs": "A", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "a"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +18,11 @@
"type": "boolean"
},
"outputs": [true, true, false],
"serialized": "string"
"serialized": [
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, false]
]
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"expression": ["==", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", false, false, "en"]],
"expression": [
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, false, "en"]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +18,11 @@
"type": "boolean"
},
"outputs": [true, true, false],
"serialized": "string"
"serialized": [
"==",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, false, "en"]
]
}
}
20 changes: 15 additions & 5 deletions test/integration/expression-tests/collator/base-gt-en/test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"expression": [">", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", false, false, "en"]],
"expression": [
">",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, false, "en"]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +18,11 @@
"type": "boolean"
},
"outputs": [false, false, true],
"serialized": "string"
"serialized": [
">",
["string", ["get", "lhs"]],
["string", ["get", "rhs"]],
["collator", false, false, "en"]
]
}
}
22 changes: 16 additions & 6 deletions test/integration/expression-tests/collator/case-lteq-en/test.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"expression": ["<=", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", false, true, "en"]],
"expression": [
"<=",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, true, "en"]
],
"inputs": [
[{}, {"properties": {"lhs": "ä", "rhs": "a"}}],
[{}, {"properties": {"lhs": "A", "rhs": "a"}}],
[{}, {"properties": {"lhs": "a", "rhs": "a"}}],
[{}, {"properties": {"lhs": "ä", "rhs": "b"}}]
[{}, {"properties": {"lhs": "ä", "rhs": "a"}}],
[{}, {"properties": {"lhs": "A", "rhs": "a"}}],
[{}, {"properties": {"lhs": "a", "rhs": "a"}}],
[{}, {"properties": {"lhs": "ä", "rhs": "b"}}]
],
"expected": {
"compiled": {
Expand All @@ -14,6 +19,11 @@
"type": "boolean"
},
"outputs": [false, true, true, true],
"serialized": "string"
"serialized": [
"<=",
["string", ["get", "lhs"]],
["string", ["get", "rhs"]],
["collator", false, true, "en"]
]
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"expression": ["!", ["!=", ["string",["get", "lhs"]], ["get", "rhs"], ["collator", false, true, "en"]]],
"expression": [
"!",
[
"!=",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, true, "en"]
]
],
"inputs": [
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
[{}, {"properties": {"lhs": "a", "rhs": "ä"}}],
[{}, {"properties": {"lhs": "a", "rhs": "A"}}],
[{}, {"properties": {"lhs": "b", "rhs": "ä"}}]
],
"expected": {
"compiled": {
Expand All @@ -13,6 +21,14 @@
"type": "boolean"
},
"outputs": [false, true, false],
"serialized": "string"
"serialized": [
"!",
[
"!=",
["string", ["get", "lhs"]],
["get", "rhs"],
["collator", false, true, "en"]
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"compiled": {
"result": "error",
"errors": [
{
"error": "Expected string but found number instead.",
"key": "[1]"
}
{"key": "[1]", "error": "Expected string but found number instead."}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"compiled": {
"result": "error",
"errors": [
{
"error": "Cannot use collator to compare non-string types.",
"key": ""
}
{"key": "", "error": "Cannot use collator to compare non-string types."}
]
}
}
Expand Down
Loading

0 comments on commit 9a7af92

Please sign in to comment.