Implement Expressions (#9439)
Ports https://github.com/mapbox/mapbox-gl-js/pull/4777 (and its several follow-ups)
This commit is contained in:
4
test/fixtures/expression_equality/acos.a.json
vendored
Normal file
4
test/fixtures/expression_equality/acos.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"acos",
|
||||
0.5
|
||||
]
|
||||
4
test/fixtures/expression_equality/acos.b.json
vendored
Normal file
4
test/fixtures/expression_equality/acos.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"acos",
|
||||
1.5
|
||||
]
|
||||
17
test/fixtures/expression_equality/all.a.json
vendored
Normal file
17
test/fixtures/expression_equality/all.a.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
"all",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
]
|
||||
]
|
||||
]
|
||||
17
test/fixtures/expression_equality/all.b.json
vendored
Normal file
17
test/fixtures/expression_equality/all.b.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
"all",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"y_other"
|
||||
]
|
||||
]
|
||||
]
|
||||
17
test/fixtures/expression_equality/any.a.json
vendored
Normal file
17
test/fixtures/expression_equality/any.a.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
"any",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
]
|
||||
]
|
||||
]
|
||||
17
test/fixtures/expression_equality/any.b.json
vendored
Normal file
17
test/fixtures/expression_equality/any.b.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
"any",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"y_other"
|
||||
]
|
||||
]
|
||||
]
|
||||
11
test/fixtures/expression_equality/array.a.json
vendored
Normal file
11
test/fixtures/expression_equality/array.a.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
"array",
|
||||
[
|
||||
"literal",
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
]
|
||||
]
|
||||
11
test/fixtures/expression_equality/array.b.json
vendored
Normal file
11
test/fixtures/expression_equality/array.b.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
"array",
|
||||
[
|
||||
"literal",
|
||||
[
|
||||
1,
|
||||
2,
|
||||
4
|
||||
]
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/asin.a.json
vendored
Normal file
4
test/fixtures/expression_equality/asin.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"asin",
|
||||
0.5
|
||||
]
|
||||
4
test/fixtures/expression_equality/asin.b.json
vendored
Normal file
4
test/fixtures/expression_equality/asin.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"asin",
|
||||
1.5
|
||||
]
|
||||
20
test/fixtures/expression_equality/at.a.json
vendored
Normal file
20
test/fixtures/expression_equality/at.a.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"at",
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"i"
|
||||
]
|
||||
],
|
||||
[
|
||||
"array",
|
||||
[
|
||||
"get",
|
||||
"arr"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
20
test/fixtures/expression_equality/at.b.json
vendored
Normal file
20
test/fixtures/expression_equality/at.b.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"at",
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"i"
|
||||
]
|
||||
],
|
||||
[
|
||||
"array",
|
||||
[
|
||||
"get",
|
||||
"arr_other"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/atan.a.json
vendored
Normal file
4
test/fixtures/expression_equality/atan.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"atan",
|
||||
1
|
||||
]
|
||||
4
test/fixtures/expression_equality/atan.b.json
vendored
Normal file
4
test/fixtures/expression_equality/atan.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"atan",
|
||||
2
|
||||
]
|
||||
7
test/fixtures/expression_equality/boolean.a.json
vendored
Normal file
7
test/fixtures/expression_equality/boolean.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/boolean.b.json
vendored
Normal file
7
test/fixtures/expression_equality/boolean.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
14
test/fixtures/expression_equality/case.a.json
vendored
Normal file
14
test/fixtures/expression_equality/case.a.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
"case",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
"x",
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
],
|
||||
"y",
|
||||
"otherwise"
|
||||
]
|
||||
14
test/fixtures/expression_equality/case.b.json
vendored
Normal file
14
test/fixtures/expression_equality/case.b.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
"case",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
"x",
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
],
|
||||
"y",
|
||||
"otherwise_other"
|
||||
]
|
||||
16
test/fixtures/expression_equality/coalesce.a.json
vendored
Normal file
16
test/fixtures/expression_equality/coalesce.a.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
"coalesce",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
],
|
||||
[
|
||||
"get",
|
||||
"z"
|
||||
],
|
||||
0
|
||||
]
|
||||
16
test/fixtures/expression_equality/coalesce.b.json
vendored
Normal file
16
test/fixtures/expression_equality/coalesce.b.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
"coalesce",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
[
|
||||
"get",
|
||||
"y"
|
||||
],
|
||||
[
|
||||
"get",
|
||||
"z"
|
||||
],
|
||||
1
|
||||
]
|
||||
6
test/fixtures/expression_equality/concat.a.json
vendored
Normal file
6
test/fixtures/expression_equality/concat.a.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"concat",
|
||||
"a",
|
||||
"b",
|
||||
"c"
|
||||
]
|
||||
6
test/fixtures/expression_equality/concat.b.json
vendored
Normal file
6
test/fixtures/expression_equality/concat.b.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"concat",
|
||||
"a",
|
||||
"b",
|
||||
"c_other"
|
||||
]
|
||||
4
test/fixtures/expression_equality/cos.a.json
vendored
Normal file
4
test/fixtures/expression_equality/cos.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"cos",
|
||||
0
|
||||
]
|
||||
4
test/fixtures/expression_equality/cos.b.json
vendored
Normal file
4
test/fixtures/expression_equality/cos.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"cos",
|
||||
1
|
||||
]
|
||||
5
test/fixtures/expression_equality/divide.a.json
vendored
Normal file
5
test/fixtures/expression_equality/divide.a.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"/",
|
||||
10,
|
||||
5
|
||||
]
|
||||
5
test/fixtures/expression_equality/divide.b.json
vendored
Normal file
5
test/fixtures/expression_equality/divide.b.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"/",
|
||||
10,
|
||||
6
|
||||
]
|
||||
4
test/fixtures/expression_equality/downcase.a.json
vendored
Normal file
4
test/fixtures/expression_equality/downcase.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"downcase",
|
||||
"StRiNg"
|
||||
]
|
||||
4
test/fixtures/expression_equality/downcase.b.json
vendored
Normal file
4
test/fixtures/expression_equality/downcase.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"downcase",
|
||||
"StRiNg_other"
|
||||
]
|
||||
7
test/fixtures/expression_equality/get.a.json
vendored
Normal file
7
test/fixtures/expression_equality/get.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/get.b.json
vendored
Normal file
7
test/fixtures/expression_equality/get.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/has.a.json
vendored
Normal file
4
test/fixtures/expression_equality/has.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"has",
|
||||
"x"
|
||||
]
|
||||
4
test/fixtures/expression_equality/has.b.json
vendored
Normal file
4
test/fixtures/expression_equality/has.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"has",
|
||||
"x_other"
|
||||
]
|
||||
23
test/fixtures/expression_equality/heatmap-density.a.json
vendored
Normal file
23
test/fixtures/expression_equality/heatmap-density.a.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
[
|
||||
"interpolate",
|
||||
[
|
||||
"linear"
|
||||
],
|
||||
[
|
||||
"heatmap-density"
|
||||
],
|
||||
0,
|
||||
[
|
||||
"rgb",
|
||||
0,
|
||||
0,
|
||||
255
|
||||
],
|
||||
1,
|
||||
[
|
||||
"rgb",
|
||||
255,
|
||||
0,
|
||||
0
|
||||
]
|
||||
]
|
||||
23
test/fixtures/expression_equality/heatmap-density.b.json
vendored
Normal file
23
test/fixtures/expression_equality/heatmap-density.b.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
[
|
||||
"interpolate",
|
||||
[
|
||||
"linear"
|
||||
],
|
||||
[
|
||||
"heatmap-density"
|
||||
],
|
||||
0,
|
||||
[
|
||||
"rgb",
|
||||
0,
|
||||
0,
|
||||
255
|
||||
],
|
||||
1,
|
||||
[
|
||||
"rgb",
|
||||
255,
|
||||
255,
|
||||
255
|
||||
]
|
||||
]
|
||||
25
test/fixtures/expression_equality/let.a.json
vendored
Normal file
25
test/fixtures/expression_equality/let.a.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
[
|
||||
"let",
|
||||
"a",
|
||||
1,
|
||||
"b",
|
||||
2,
|
||||
[
|
||||
"+",
|
||||
[
|
||||
"+",
|
||||
[
|
||||
"var",
|
||||
"a"
|
||||
],
|
||||
[
|
||||
"var",
|
||||
"b"
|
||||
]
|
||||
],
|
||||
[
|
||||
"var",
|
||||
"a"
|
||||
]
|
||||
]
|
||||
]
|
||||
25
test/fixtures/expression_equality/let.b.json
vendored
Normal file
25
test/fixtures/expression_equality/let.b.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
[
|
||||
"let",
|
||||
"a",
|
||||
1,
|
||||
"b",
|
||||
3,
|
||||
[
|
||||
"+",
|
||||
[
|
||||
"+",
|
||||
[
|
||||
"var",
|
||||
"a"
|
||||
],
|
||||
[
|
||||
"var",
|
||||
"b"
|
||||
]
|
||||
],
|
||||
[
|
||||
"var",
|
||||
"b"
|
||||
]
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/ln.a.json
vendored
Normal file
4
test/fixtures/expression_equality/ln.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"ln",
|
||||
2
|
||||
]
|
||||
6
test/fixtures/expression_equality/ln.b.json
vendored
Normal file
6
test/fixtures/expression_equality/ln.b.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"ln",
|
||||
[
|
||||
"e"
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/log10.a.json
vendored
Normal file
4
test/fixtures/expression_equality/log10.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"log10",
|
||||
100
|
||||
]
|
||||
4
test/fixtures/expression_equality/log10.b.json
vendored
Normal file
4
test/fixtures/expression_equality/log10.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"log10",
|
||||
101
|
||||
]
|
||||
4
test/fixtures/expression_equality/log2.a.json
vendored
Normal file
4
test/fixtures/expression_equality/log2.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"log2",
|
||||
1024
|
||||
]
|
||||
4
test/fixtures/expression_equality/log2.b.json
vendored
Normal file
4
test/fixtures/expression_equality/log2.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"log2",
|
||||
1025
|
||||
]
|
||||
12
test/fixtures/expression_equality/match.a.json
vendored
Normal file
12
test/fixtures/expression_equality/match.a.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
[
|
||||
"match",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
"a",
|
||||
"Apple",
|
||||
"b",
|
||||
"Banana",
|
||||
"Kumquat"
|
||||
]
|
||||
12
test/fixtures/expression_equality/match.b.json
vendored
Normal file
12
test/fixtures/expression_equality/match.b.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
[
|
||||
"match",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
],
|
||||
"a",
|
||||
"Apple",
|
||||
"b",
|
||||
"Banana",
|
||||
"Kumquat_other"
|
||||
]
|
||||
6
test/fixtures/expression_equality/max.a.json
vendored
Normal file
6
test/fixtures/expression_equality/max.a.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"max",
|
||||
0,
|
||||
-1,
|
||||
100
|
||||
]
|
||||
6
test/fixtures/expression_equality/max.b.json
vendored
Normal file
6
test/fixtures/expression_equality/max.b.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"max",
|
||||
0,
|
||||
-1,
|
||||
101
|
||||
]
|
||||
5
test/fixtures/expression_equality/min.a.json
vendored
Normal file
5
test/fixtures/expression_equality/min.a.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"min",
|
||||
["get", "x"],
|
||||
0
|
||||
]
|
||||
5
test/fixtures/expression_equality/min.b.json
vendored
Normal file
5
test/fixtures/expression_equality/min.b.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"min",
|
||||
["get", "x"],
|
||||
1
|
||||
]
|
||||
5
test/fixtures/expression_equality/minus.a.json
vendored
Normal file
5
test/fixtures/expression_equality/minus.a.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"-",
|
||||
5,
|
||||
7
|
||||
]
|
||||
5
test/fixtures/expression_equality/minus.b.json
vendored
Normal file
5
test/fixtures/expression_equality/minus.b.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"-",
|
||||
5,
|
||||
8
|
||||
]
|
||||
5
test/fixtures/expression_equality/mod.a.json
vendored
Normal file
5
test/fixtures/expression_equality/mod.a.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"%",
|
||||
18,
|
||||
12
|
||||
]
|
||||
5
test/fixtures/expression_equality/mod.b.json
vendored
Normal file
5
test/fixtures/expression_equality/mod.b.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"%",
|
||||
18,
|
||||
13
|
||||
]
|
||||
10
test/fixtures/expression_equality/not.a.json
vendored
Normal file
10
test/fixtures/expression_equality/not.a.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
"!",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
]
|
||||
10
test/fixtures/expression_equality/not.b.json
vendored
Normal file
10
test/fixtures/expression_equality/not.b.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
"!",
|
||||
[
|
||||
"boolean",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/number.a.json
vendored
Normal file
7
test/fixtures/expression_equality/number.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/number.b.json
vendored
Normal file
7
test/fixtures/expression_equality/number.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/object.a.json
vendored
Normal file
7
test/fixtures/expression_equality/object.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"object",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/object.b.json
vendored
Normal file
7
test/fixtures/expression_equality/object.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"object",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/plus.a.json
vendored
Normal file
7
test/fixtures/expression_equality/plus.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"+",
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4
|
||||
]
|
||||
7
test/fixtures/expression_equality/plus.b.json
vendored
Normal file
7
test/fixtures/expression_equality/plus.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"+",
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
5
|
||||
]
|
||||
11
test/fixtures/expression_equality/pow.a.json
vendored
Normal file
11
test/fixtures/expression_equality/pow.a.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
"^",
|
||||
4,
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
]
|
||||
11
test/fixtures/expression_equality/pow.b.json
vendored
Normal file
11
test/fixtures/expression_equality/pow.b.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
"^",
|
||||
4,
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
]
|
||||
6
test/fixtures/expression_equality/rgb.a.json
vendored
Normal file
6
test/fixtures/expression_equality/rgb.a.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"rgb",
|
||||
0,
|
||||
0,
|
||||
255
|
||||
]
|
||||
6
test/fixtures/expression_equality/rgb.b.json
vendored
Normal file
6
test/fixtures/expression_equality/rgb.b.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"rgb",
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
7
test/fixtures/expression_equality/rgba.a.json
vendored
Normal file
7
test/fixtures/expression_equality/rgba.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"rgba",
|
||||
0,
|
||||
0,
|
||||
255,
|
||||
1
|
||||
]
|
||||
7
test/fixtures/expression_equality/rgba.b.json
vendored
Normal file
7
test/fixtures/expression_equality/rgba.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"rgba",
|
||||
0,
|
||||
0,
|
||||
255,
|
||||
0.5
|
||||
]
|
||||
4
test/fixtures/expression_equality/sin.a.json
vendored
Normal file
4
test/fixtures/expression_equality/sin.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"sin",
|
||||
0
|
||||
]
|
||||
4
test/fixtures/expression_equality/sin.b.json
vendored
Normal file
4
test/fixtures/expression_equality/sin.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"sin",
|
||||
1
|
||||
]
|
||||
7
test/fixtures/expression_equality/sqrt.a.json
vendored
Normal file
7
test/fixtures/expression_equality/sqrt.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"sqrt",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/sqrt.b.json
vendored
Normal file
7
test/fixtures/expression_equality/sqrt.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"sqrt",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
18
test/fixtures/expression_equality/step.a.json
vendored
Normal file
18
test/fixtures/expression_equality/step.a.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"step",
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
11,
|
||||
0,
|
||||
111,
|
||||
1,
|
||||
1111
|
||||
]
|
||||
]
|
||||
18
test/fixtures/expression_equality/step.b.json
vendored
Normal file
18
test/fixtures/expression_equality/step.b.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"step",
|
||||
[
|
||||
"number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
],
|
||||
11,
|
||||
0,
|
||||
111,
|
||||
1,
|
||||
1112
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/string.a.json
vendored
Normal file
7
test/fixtures/expression_equality/string.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"string",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/string.b.json
vendored
Normal file
7
test/fixtures/expression_equality/string.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"string",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/tan.a.json
vendored
Normal file
4
test/fixtures/expression_equality/tan.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"tan",
|
||||
0.7853981633974483
|
||||
]
|
||||
4
test/fixtures/expression_equality/tan.b.json
vendored
Normal file
4
test/fixtures/expression_equality/tan.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"tan",
|
||||
1.7853981633974483
|
||||
]
|
||||
7
test/fixtures/expression_equality/times.a.json
vendored
Normal file
7
test/fixtures/expression_equality/times.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"*",
|
||||
3,
|
||||
2,
|
||||
0.5,
|
||||
2
|
||||
]
|
||||
7
test/fixtures/expression_equality/times.b.json
vendored
Normal file
7
test/fixtures/expression_equality/times.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"*",
|
||||
3,
|
||||
2,
|
||||
0.5,
|
||||
3
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-boolean.a.json
vendored
Normal file
7
test/fixtures/expression_equality/to-boolean.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-boolean",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-boolean.b.json
vendored
Normal file
7
test/fixtures/expression_equality/to-boolean.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-boolean",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-color.a.json
vendored
Normal file
7
test/fixtures/expression_equality/to-color.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-color",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-color.b.json
vendored
Normal file
7
test/fixtures/expression_equality/to-color.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-color",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-number.a.json
vendored
Normal file
7
test/fixtures/expression_equality/to-number.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-number",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-number.b.json
vendored
Normal file
7
test/fixtures/expression_equality/to-number.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-number",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-string.a.json
vendored
Normal file
7
test/fixtures/expression_equality/to-string.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-string",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/to-string.b.json
vendored
Normal file
7
test/fixtures/expression_equality/to-string.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"to-string",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/typeof.a.json
vendored
Normal file
7
test/fixtures/expression_equality/typeof.a.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"typeof",
|
||||
[
|
||||
"get",
|
||||
"x"
|
||||
]
|
||||
]
|
||||
7
test/fixtures/expression_equality/typeof.b.json
vendored
Normal file
7
test/fixtures/expression_equality/typeof.b.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"typeof",
|
||||
[
|
||||
"get",
|
||||
"x_other"
|
||||
]
|
||||
]
|
||||
4
test/fixtures/expression_equality/upcase.a.json
vendored
Normal file
4
test/fixtures/expression_equality/upcase.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"upcase",
|
||||
"string"
|
||||
]
|
||||
4
test/fixtures/expression_equality/upcase.b.json
vendored
Normal file
4
test/fixtures/expression_equality/upcase.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"upcase",
|
||||
"string_other"
|
||||
]
|
||||
13
test/fixtures/expression_equality/zoom.a.json
vendored
Normal file
13
test/fixtures/expression_equality/zoom.a.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
[
|
||||
"interpolate",
|
||||
[
|
||||
"linear"
|
||||
],
|
||||
[
|
||||
"zoom"
|
||||
],
|
||||
0,
|
||||
0,
|
||||
30,
|
||||
30
|
||||
]
|
||||
13
test/fixtures/expression_equality/zoom.b.json
vendored
Normal file
13
test/fixtures/expression_equality/zoom.b.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
[
|
||||
"interpolate",
|
||||
[
|
||||
"linear"
|
||||
],
|
||||
[
|
||||
"zoom"
|
||||
],
|
||||
0,
|
||||
0,
|
||||
30,
|
||||
31
|
||||
]
|
||||
12
test/fixtures/style_parser/expressions.info.json
vendored
Normal file
12
test/fixtures/style_parser/expressions.info.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "Expected color but found number instead."],
|
||||
[1, "WARNING", "ParseStyle", "[2]: Expected number but found string instead."],
|
||||
[1, "WARNING", "ParseStyle", "\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression."],
|
||||
[1, "WARNING", "ParseStyle", "value must be a string"],
|
||||
[1, "WARNING", "ParseStyle", "property expressions not supported"],
|
||||
[1, "WARNING", "ParseStyle", "Type array<number> is not interpolatable."]
|
||||
]
|
||||
}
|
||||
}
|
||||
74
test/fixtures/style_parser/expressions.style.json
vendored
Normal file
74
test/fixtures/style_parser/expressions.style.json
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"version": 8,
|
||||
"sources": {
|
||||
"source": {
|
||||
"type": "vector",
|
||||
"url": "mapbox://mapbox.mapbox-streets-v5"
|
||||
}
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "valid expression",
|
||||
"type": "fill",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"fill-color": ["rgba", 10, ["number", ["get", "x"]], 30, 1]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression type - color",
|
||||
"type": "fill",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"fill-color": ["pi"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression - fails type checking",
|
||||
"type": "fill",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"fill-color": ["rgba", 1, "should be a number", 0, 1]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression - nested zoom expression",
|
||||
"type": "fill",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"fill-opacity": ["+", 0.5, ["interpolate", ["linear"], ["zoom"], 0, 0, 1, 1]]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression - not allowed in visibility",
|
||||
"type": "fill",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"layout": {
|
||||
"visibility": ["literal", true]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression - not a DDS property",
|
||||
"type": "fill-extrusion",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"fill-extrusion-opacity": ["get", "opacity"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "invalid expression - line-dasharray must use step interpolation",
|
||||
"type": "line",
|
||||
"source": "source",
|
||||
"source-layer": "layer",
|
||||
"paint": {
|
||||
"line-dasharray": ["interpolate", ["linear"], ["zoom"], 0, ["literal", [1, 2]], 1, ["literal", [3, 4]]]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <mbgl/style/conversion/json.hpp>
|
||||
#include <mbgl/style/conversion/constant.hpp>
|
||||
#include <mbgl/style/conversion/function.hpp>
|
||||
#include <mbgl/style/conversion/data_driven_property_value.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
@@ -50,3 +52,29 @@ TEST(StyleConversion, Function) {
|
||||
ASSERT_FALSE(fn9);
|
||||
ASSERT_EQ("function base must be a number", error.message);
|
||||
}
|
||||
|
||||
TEST(StyleConversion, CompositeFunctionExpression) {
|
||||
Error error;
|
||||
|
||||
auto parseFunction = [&](const std::string& src) {
|
||||
JSDocument doc;
|
||||
doc.Parse<0>(src);
|
||||
return convert<DataDrivenPropertyValue<float>>(doc, error);
|
||||
};
|
||||
|
||||
auto fn1 = parseFunction(R"(["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10])");
|
||||
ASSERT_TRUE(fn1);
|
||||
|
||||
auto fn2 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0])");
|
||||
ASSERT_TRUE(fn2);
|
||||
|
||||
auto fn3 = parseFunction(R"(["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10] ])");
|
||||
ASSERT_TRUE(fn3);
|
||||
|
||||
auto fn4 = parseFunction(R"(["coalesce", ["let", "a", 0, ["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10], 0 ])");
|
||||
ASSERT_TRUE(fn4);
|
||||
|
||||
auto fn5 = parseFunction(R"(["coalesce", ["interpolate", ["linear"], ["number", ["get", "x"]], 0, ["zoom"], 10, 10], 0])");
|
||||
ASSERT_FALSE(fn5);
|
||||
ASSERT_EQ(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)", error.message);
|
||||
}
|
||||
|
||||
91
test/style/expression/expression.test.cpp
Normal file
91
test/style/expression/expression.test.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
#include <mbgl/style/rapidjson_conversion.hpp>
|
||||
#include <mbgl/style/expression/is_expression.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
|
||||
TEST(Expression, IsExpression) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> spec;
|
||||
spec.Parse<0>(util::read_file("mapbox-gl-js/src/style-spec/reference/v8.json").c_str());
|
||||
ASSERT_FALSE(spec.HasParseError());
|
||||
ASSERT_TRUE(spec.IsObject() &&
|
||||
spec.HasMember("expression_name") &&
|
||||
spec["expression_name"].IsObject() &&
|
||||
spec["expression_name"].HasMember("values") &&
|
||||
spec["expression_name"]["values"].IsObject());
|
||||
|
||||
const auto& allExpressions = spec["expression_name"]["values"];
|
||||
|
||||
for(auto& entry : allExpressions.GetObject()) {
|
||||
const std::string name { entry.name.GetString(), entry.name.GetStringLength() };
|
||||
JSDocument document;
|
||||
document.Parse<0>(R"([")" + name + R"("])");
|
||||
|
||||
const JSValue* expression = &document;
|
||||
EXPECT_TRUE(expression::isExpression(conversion::Convertible(expression))) << name;
|
||||
}
|
||||
}
|
||||
|
||||
class ExpressionEqualityTest : public ::testing::TestWithParam<std::string> {};
|
||||
|
||||
TEST_P(ExpressionEqualityTest, ExpressionEquality) {
|
||||
const std::string base = std::string("test/fixtures/expression_equality/") + GetParam();
|
||||
|
||||
std::string error;
|
||||
auto parse = [&](std::string filename, std::string& error_) -> std::unique_ptr<expression::Expression> {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
|
||||
document.Parse<0>(util::read_file(filename).c_str());
|
||||
assert(!document.HasParseError());
|
||||
const JSValue* expression = &document;
|
||||
expression::ParsingContext ctx;
|
||||
expression::ParseResult parsed = ctx.parse(conversion::Convertible(expression));
|
||||
if (!parsed) {
|
||||
error_ = ctx.getErrors().size() > 0 ? ctx.getErrors()[0].message : "failed to parse";
|
||||
};
|
||||
return std::move(*parsed);
|
||||
};
|
||||
|
||||
std::unique_ptr<expression::Expression> expression_a1 = parse(base + ".a.json", error);
|
||||
ASSERT_TRUE(expression_a1) << GetParam() << ": " << error;
|
||||
|
||||
std::unique_ptr<expression::Expression> expression_a2 = parse(base + ".a.json", error);
|
||||
ASSERT_TRUE(expression_a2) << GetParam() << ": " << error;
|
||||
|
||||
std::unique_ptr<expression::Expression> expression_b = parse(base + ".b.json", error);
|
||||
ASSERT_TRUE(expression_b) << GetParam() << ": " << error;
|
||||
|
||||
|
||||
EXPECT_TRUE(*expression_a1 == *expression_a2);
|
||||
EXPECT_TRUE(*expression_a1 != *expression_b);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Expression, ExpressionEqualityTest, ::testing::ValuesIn([] {
|
||||
std::vector<std::string> names;
|
||||
const std::string ending = ".a.json";
|
||||
|
||||
const std::string style_directory = "test/fixtures/expression_equality";
|
||||
DIR *dir = opendir(style_directory.c_str());
|
||||
if (dir != nullptr) {
|
||||
for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) {
|
||||
const std::string name = dp->d_name;
|
||||
if (name.length() >= ending.length() && name.compare(name.length() - ending.length(), ending.length(), ending) == 0) {
|
||||
names.push_back(name.substr(0, name.length() - ending.length()));
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
EXPECT_GT(names.size(), 0u);
|
||||
return names;
|
||||
}()));
|
||||
23
test/style/expression/util.test.cpp
Normal file
23
test/style/expression/util.test.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/style/expression/util.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style::expression;
|
||||
|
||||
TEST(Expression, Util_rgba) {
|
||||
Result<Color> valid = rgba(0, 0, 0, 0);
|
||||
ASSERT_TRUE(valid);
|
||||
ASSERT_EQ(valid->r, 0);
|
||||
ASSERT_EQ(valid->g, 0);
|
||||
ASSERT_EQ(valid->b, 0);
|
||||
ASSERT_EQ(valid->a, 0);
|
||||
|
||||
ASSERT_FALSE(rgba(0, 0, 0, -0.1));
|
||||
ASSERT_FALSE(rgba(0, 0, 0, 1.1));
|
||||
ASSERT_FALSE(rgba(0, 0, -1, 1));
|
||||
ASSERT_FALSE(rgba(0, 0, 256, 1));
|
||||
ASSERT_FALSE(rgba(0, -1, 0, 1));
|
||||
ASSERT_FALSE(rgba(0, 256, 0, 1));
|
||||
ASSERT_FALSE(rgba(-1, 1, 0, 1));
|
||||
ASSERT_FALSE(rgba(-256, 1, 0, 1));
|
||||
}
|
||||
Reference in New Issue
Block a user