diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2017-11-08 12:34:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-08 12:34:02 -0500 |
commit | f648cfeef6544755fdb10c3cf8847e878d70e0ff (patch) | |
tree | 49800ebd34969b787681691f1219c6396ed58579 /test | |
parent | 9aac976104f4c6453cf9e79e03a002565720f213 (diff) | |
download | qtlocation-mapboxgl-f648cfeef6544755fdb10c3cf8847e878d70e0ff.tar.gz |
Implement Expressions (#9439)
Ports https://github.com/mapbox/mapbox-gl-js/pull/4777 (and its several follow-ups)
Diffstat (limited to 'test')
97 files changed, 1012 insertions, 0 deletions
diff --git a/test/fixtures/expression_equality/acos.a.json b/test/fixtures/expression_equality/acos.a.json new file mode 100644 index 0000000000..1e9bb752ca --- /dev/null +++ b/test/fixtures/expression_equality/acos.a.json @@ -0,0 +1,4 @@ +[ + "acos", + 0.5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/acos.b.json b/test/fixtures/expression_equality/acos.b.json new file mode 100644 index 0000000000..54e035cb7e --- /dev/null +++ b/test/fixtures/expression_equality/acos.b.json @@ -0,0 +1,4 @@ +[ + "acos", + 1.5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/all.a.json b/test/fixtures/expression_equality/all.a.json new file mode 100644 index 0000000000..ec7154b7b9 --- /dev/null +++ b/test/fixtures/expression_equality/all.a.json @@ -0,0 +1,17 @@ +[ + "all", + [ + "boolean", + [ + "get", + "x" + ] + ], + [ + "boolean", + [ + "get", + "y" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/all.b.json b/test/fixtures/expression_equality/all.b.json new file mode 100644 index 0000000000..8eab839bb0 --- /dev/null +++ b/test/fixtures/expression_equality/all.b.json @@ -0,0 +1,17 @@ +[ + "all", + [ + "boolean", + [ + "get", + "x" + ] + ], + [ + "boolean", + [ + "get", + "y_other" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/any.a.json b/test/fixtures/expression_equality/any.a.json new file mode 100644 index 0000000000..3f044c1f79 --- /dev/null +++ b/test/fixtures/expression_equality/any.a.json @@ -0,0 +1,17 @@ +[ + "any", + [ + "boolean", + [ + "get", + "x" + ] + ], + [ + "boolean", + [ + "get", + "y" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/any.b.json b/test/fixtures/expression_equality/any.b.json new file mode 100644 index 0000000000..720662751f --- /dev/null +++ b/test/fixtures/expression_equality/any.b.json @@ -0,0 +1,17 @@ +[ + "any", + [ + "boolean", + [ + "get", + "x" + ] + ], + [ + "boolean", + [ + "get", + "y_other" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/array.a.json b/test/fixtures/expression_equality/array.a.json new file mode 100644 index 0000000000..3c31303ca3 --- /dev/null +++ b/test/fixtures/expression_equality/array.a.json @@ -0,0 +1,11 @@ +[ + "array", + [ + "literal", + [ + 1, + 2, + 3 + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/array.b.json b/test/fixtures/expression_equality/array.b.json new file mode 100644 index 0000000000..7606794d56 --- /dev/null +++ b/test/fixtures/expression_equality/array.b.json @@ -0,0 +1,11 @@ +[ + "array", + [ + "literal", + [ + 1, + 2, + 4 + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/asin.a.json b/test/fixtures/expression_equality/asin.a.json new file mode 100644 index 0000000000..3cd730ccbf --- /dev/null +++ b/test/fixtures/expression_equality/asin.a.json @@ -0,0 +1,4 @@ +[ + "asin", + 0.5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/asin.b.json b/test/fixtures/expression_equality/asin.b.json new file mode 100644 index 0000000000..2c862c8cbe --- /dev/null +++ b/test/fixtures/expression_equality/asin.b.json @@ -0,0 +1,4 @@ +[ + "asin", + 1.5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/at.a.json b/test/fixtures/expression_equality/at.a.json new file mode 100644 index 0000000000..c69b0d933b --- /dev/null +++ b/test/fixtures/expression_equality/at.a.json @@ -0,0 +1,20 @@ +[ + "number", + [ + "at", + [ + "number", + [ + "get", + "i" + ] + ], + [ + "array", + [ + "get", + "arr" + ] + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/at.b.json b/test/fixtures/expression_equality/at.b.json new file mode 100644 index 0000000000..6e19c28606 --- /dev/null +++ b/test/fixtures/expression_equality/at.b.json @@ -0,0 +1,20 @@ +[ + "number", + [ + "at", + [ + "number", + [ + "get", + "i" + ] + ], + [ + "array", + [ + "get", + "arr_other" + ] + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/atan.a.json b/test/fixtures/expression_equality/atan.a.json new file mode 100644 index 0000000000..b76406bc44 --- /dev/null +++ b/test/fixtures/expression_equality/atan.a.json @@ -0,0 +1,4 @@ +[ + "atan", + 1 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/atan.b.json b/test/fixtures/expression_equality/atan.b.json new file mode 100644 index 0000000000..aafbbb0594 --- /dev/null +++ b/test/fixtures/expression_equality/atan.b.json @@ -0,0 +1,4 @@ +[ + "atan", + 2 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/boolean.a.json b/test/fixtures/expression_equality/boolean.a.json new file mode 100644 index 0000000000..1230a2a926 --- /dev/null +++ b/test/fixtures/expression_equality/boolean.a.json @@ -0,0 +1,7 @@ +[ + "boolean", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/boolean.b.json b/test/fixtures/expression_equality/boolean.b.json new file mode 100644 index 0000000000..1ae91ef60c --- /dev/null +++ b/test/fixtures/expression_equality/boolean.b.json @@ -0,0 +1,7 @@ +[ + "boolean", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/case.a.json b/test/fixtures/expression_equality/case.a.json new file mode 100644 index 0000000000..84049294f5 --- /dev/null +++ b/test/fixtures/expression_equality/case.a.json @@ -0,0 +1,14 @@ +[ + "case", + [ + "get", + "x" + ], + "x", + [ + "get", + "y" + ], + "y", + "otherwise" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/case.b.json b/test/fixtures/expression_equality/case.b.json new file mode 100644 index 0000000000..038806043f --- /dev/null +++ b/test/fixtures/expression_equality/case.b.json @@ -0,0 +1,14 @@ +[ + "case", + [ + "get", + "x" + ], + "x", + [ + "get", + "y" + ], + "y", + "otherwise_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/coalesce.a.json b/test/fixtures/expression_equality/coalesce.a.json new file mode 100644 index 0000000000..8fae579e7c --- /dev/null +++ b/test/fixtures/expression_equality/coalesce.a.json @@ -0,0 +1,16 @@ +[ + "coalesce", + [ + "get", + "x" + ], + [ + "get", + "y" + ], + [ + "get", + "z" + ], + 0 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/coalesce.b.json b/test/fixtures/expression_equality/coalesce.b.json new file mode 100644 index 0000000000..4e0af8baa0 --- /dev/null +++ b/test/fixtures/expression_equality/coalesce.b.json @@ -0,0 +1,16 @@ +[ + "coalesce", + [ + "get", + "x" + ], + [ + "get", + "y" + ], + [ + "get", + "z" + ], + 1 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/concat.a.json b/test/fixtures/expression_equality/concat.a.json new file mode 100644 index 0000000000..08c95d7f49 --- /dev/null +++ b/test/fixtures/expression_equality/concat.a.json @@ -0,0 +1,6 @@ +[ + "concat", + "a", + "b", + "c" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/concat.b.json b/test/fixtures/expression_equality/concat.b.json new file mode 100644 index 0000000000..e3396d4fc0 --- /dev/null +++ b/test/fixtures/expression_equality/concat.b.json @@ -0,0 +1,6 @@ +[ + "concat", + "a", + "b", + "c_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/cos.a.json b/test/fixtures/expression_equality/cos.a.json new file mode 100644 index 0000000000..e41430de53 --- /dev/null +++ b/test/fixtures/expression_equality/cos.a.json @@ -0,0 +1,4 @@ +[ + "cos", + 0 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/cos.b.json b/test/fixtures/expression_equality/cos.b.json new file mode 100644 index 0000000000..5ba4424dae --- /dev/null +++ b/test/fixtures/expression_equality/cos.b.json @@ -0,0 +1,4 @@ +[ + "cos", + 1 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/divide.a.json b/test/fixtures/expression_equality/divide.a.json new file mode 100644 index 0000000000..40a67a871c --- /dev/null +++ b/test/fixtures/expression_equality/divide.a.json @@ -0,0 +1,5 @@ +[ + "/", + 10, + 5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/divide.b.json b/test/fixtures/expression_equality/divide.b.json new file mode 100644 index 0000000000..e3f7b155b2 --- /dev/null +++ b/test/fixtures/expression_equality/divide.b.json @@ -0,0 +1,5 @@ +[ + "/", + 10, + 6 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/downcase.a.json b/test/fixtures/expression_equality/downcase.a.json new file mode 100644 index 0000000000..ca367218c4 --- /dev/null +++ b/test/fixtures/expression_equality/downcase.a.json @@ -0,0 +1,4 @@ +[ + "downcase", + "StRiNg" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/downcase.b.json b/test/fixtures/expression_equality/downcase.b.json new file mode 100644 index 0000000000..fd9ea9881d --- /dev/null +++ b/test/fixtures/expression_equality/downcase.b.json @@ -0,0 +1,4 @@ +[ + "downcase", + "StRiNg_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/get.a.json b/test/fixtures/expression_equality/get.a.json new file mode 100644 index 0000000000..57c3df48e7 --- /dev/null +++ b/test/fixtures/expression_equality/get.a.json @@ -0,0 +1,7 @@ +[ + "number", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/get.b.json b/test/fixtures/expression_equality/get.b.json new file mode 100644 index 0000000000..d1843362d3 --- /dev/null +++ b/test/fixtures/expression_equality/get.b.json @@ -0,0 +1,7 @@ +[ + "number", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/has.a.json b/test/fixtures/expression_equality/has.a.json new file mode 100644 index 0000000000..8326754107 --- /dev/null +++ b/test/fixtures/expression_equality/has.a.json @@ -0,0 +1,4 @@ +[ + "has", + "x" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/has.b.json b/test/fixtures/expression_equality/has.b.json new file mode 100644 index 0000000000..20b6072303 --- /dev/null +++ b/test/fixtures/expression_equality/has.b.json @@ -0,0 +1,4 @@ +[ + "has", + "x_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/heatmap-density.a.json b/test/fixtures/expression_equality/heatmap-density.a.json new file mode 100644 index 0000000000..90bd396f54 --- /dev/null +++ b/test/fixtures/expression_equality/heatmap-density.a.json @@ -0,0 +1,23 @@ +[ + "interpolate", + [ + "linear" + ], + [ + "heatmap-density" + ], + 0, + [ + "rgb", + 0, + 0, + 255 + ], + 1, + [ + "rgb", + 255, + 0, + 0 + ] +] diff --git a/test/fixtures/expression_equality/heatmap-density.b.json b/test/fixtures/expression_equality/heatmap-density.b.json new file mode 100644 index 0000000000..bce8ab03a1 --- /dev/null +++ b/test/fixtures/expression_equality/heatmap-density.b.json @@ -0,0 +1,23 @@ +[ + "interpolate", + [ + "linear" + ], + [ + "heatmap-density" + ], + 0, + [ + "rgb", + 0, + 0, + 255 + ], + 1, + [ + "rgb", + 255, + 255, + 255 + ] +] diff --git a/test/fixtures/expression_equality/let.a.json b/test/fixtures/expression_equality/let.a.json new file mode 100644 index 0000000000..fb24e50cfb --- /dev/null +++ b/test/fixtures/expression_equality/let.a.json @@ -0,0 +1,25 @@ +[ + "let", + "a", + 1, + "b", + 2, + [ + "+", + [ + "+", + [ + "var", + "a" + ], + [ + "var", + "b" + ] + ], + [ + "var", + "a" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/let.b.json b/test/fixtures/expression_equality/let.b.json new file mode 100644 index 0000000000..26813cb6ff --- /dev/null +++ b/test/fixtures/expression_equality/let.b.json @@ -0,0 +1,25 @@ +[ + "let", + "a", + 1, + "b", + 3, + [ + "+", + [ + "+", + [ + "var", + "a" + ], + [ + "var", + "b" + ] + ], + [ + "var", + "b" + ] + ] +] diff --git a/test/fixtures/expression_equality/ln.a.json b/test/fixtures/expression_equality/ln.a.json new file mode 100644 index 0000000000..30d80f36ae --- /dev/null +++ b/test/fixtures/expression_equality/ln.a.json @@ -0,0 +1,4 @@ +[ + "ln", + 2 +] diff --git a/test/fixtures/expression_equality/ln.b.json b/test/fixtures/expression_equality/ln.b.json new file mode 100644 index 0000000000..9bc04ad586 --- /dev/null +++ b/test/fixtures/expression_equality/ln.b.json @@ -0,0 +1,6 @@ +[ + "ln", + [ + "e" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/log10.a.json b/test/fixtures/expression_equality/log10.a.json new file mode 100644 index 0000000000..32e4c18807 --- /dev/null +++ b/test/fixtures/expression_equality/log10.a.json @@ -0,0 +1,4 @@ +[ + "log10", + 100 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/log10.b.json b/test/fixtures/expression_equality/log10.b.json new file mode 100644 index 0000000000..8f32c204f9 --- /dev/null +++ b/test/fixtures/expression_equality/log10.b.json @@ -0,0 +1,4 @@ +[ + "log10", + 101 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/log2.a.json b/test/fixtures/expression_equality/log2.a.json new file mode 100644 index 0000000000..95cdc15373 --- /dev/null +++ b/test/fixtures/expression_equality/log2.a.json @@ -0,0 +1,4 @@ +[ + "log2", + 1024 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/log2.b.json b/test/fixtures/expression_equality/log2.b.json new file mode 100644 index 0000000000..2fffaeb32a --- /dev/null +++ b/test/fixtures/expression_equality/log2.b.json @@ -0,0 +1,4 @@ +[ + "log2", + 1025 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/match.a.json b/test/fixtures/expression_equality/match.a.json new file mode 100644 index 0000000000..ba8afc4126 --- /dev/null +++ b/test/fixtures/expression_equality/match.a.json @@ -0,0 +1,12 @@ +[ + "match", + [ + "get", + "x" + ], + "a", + "Apple", + "b", + "Banana", + "Kumquat" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/match.b.json b/test/fixtures/expression_equality/match.b.json new file mode 100644 index 0000000000..2404b8e2e7 --- /dev/null +++ b/test/fixtures/expression_equality/match.b.json @@ -0,0 +1,12 @@ +[ + "match", + [ + "get", + "x" + ], + "a", + "Apple", + "b", + "Banana", + "Kumquat_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/max.a.json b/test/fixtures/expression_equality/max.a.json new file mode 100644 index 0000000000..09a8f82bd7 --- /dev/null +++ b/test/fixtures/expression_equality/max.a.json @@ -0,0 +1,6 @@ +[ + "max", + 0, + -1, + 100 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/max.b.json b/test/fixtures/expression_equality/max.b.json new file mode 100644 index 0000000000..1b0beb20d6 --- /dev/null +++ b/test/fixtures/expression_equality/max.b.json @@ -0,0 +1,6 @@ +[ + "max", + 0, + -1, + 101 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/min.a.json b/test/fixtures/expression_equality/min.a.json new file mode 100644 index 0000000000..38cc90f1cd --- /dev/null +++ b/test/fixtures/expression_equality/min.a.json @@ -0,0 +1,5 @@ +[ + "min", + ["get", "x"], + 0 +] diff --git a/test/fixtures/expression_equality/min.b.json b/test/fixtures/expression_equality/min.b.json new file mode 100644 index 0000000000..84a5f66842 --- /dev/null +++ b/test/fixtures/expression_equality/min.b.json @@ -0,0 +1,5 @@ +[ + "min", + ["get", "x"], + 1 +] diff --git a/test/fixtures/expression_equality/minus.a.json b/test/fixtures/expression_equality/minus.a.json new file mode 100644 index 0000000000..9eb4f954e7 --- /dev/null +++ b/test/fixtures/expression_equality/minus.a.json @@ -0,0 +1,5 @@ +[ + "-", + 5, + 7 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/minus.b.json b/test/fixtures/expression_equality/minus.b.json new file mode 100644 index 0000000000..87042b98ef --- /dev/null +++ b/test/fixtures/expression_equality/minus.b.json @@ -0,0 +1,5 @@ +[ + "-", + 5, + 8 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/mod.a.json b/test/fixtures/expression_equality/mod.a.json new file mode 100644 index 0000000000..8439bafcd1 --- /dev/null +++ b/test/fixtures/expression_equality/mod.a.json @@ -0,0 +1,5 @@ +[ + "%", + 18, + 12 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/mod.b.json b/test/fixtures/expression_equality/mod.b.json new file mode 100644 index 0000000000..362e1721c1 --- /dev/null +++ b/test/fixtures/expression_equality/mod.b.json @@ -0,0 +1,5 @@ +[ + "%", + 18, + 13 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/not.a.json b/test/fixtures/expression_equality/not.a.json new file mode 100644 index 0000000000..b5f03e0ac0 --- /dev/null +++ b/test/fixtures/expression_equality/not.a.json @@ -0,0 +1,10 @@ +[ + "!", + [ + "boolean", + [ + "get", + "x" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/not.b.json b/test/fixtures/expression_equality/not.b.json new file mode 100644 index 0000000000..a4d77adf2e --- /dev/null +++ b/test/fixtures/expression_equality/not.b.json @@ -0,0 +1,10 @@ +[ + "!", + [ + "boolean", + [ + "get", + "x_other" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/number.a.json b/test/fixtures/expression_equality/number.a.json new file mode 100644 index 0000000000..57c3df48e7 --- /dev/null +++ b/test/fixtures/expression_equality/number.a.json @@ -0,0 +1,7 @@ +[ + "number", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/number.b.json b/test/fixtures/expression_equality/number.b.json new file mode 100644 index 0000000000..d1843362d3 --- /dev/null +++ b/test/fixtures/expression_equality/number.b.json @@ -0,0 +1,7 @@ +[ + "number", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/object.a.json b/test/fixtures/expression_equality/object.a.json new file mode 100644 index 0000000000..7551cfdbb2 --- /dev/null +++ b/test/fixtures/expression_equality/object.a.json @@ -0,0 +1,7 @@ +[ + "object", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/object.b.json b/test/fixtures/expression_equality/object.b.json new file mode 100644 index 0000000000..8444d40c0e --- /dev/null +++ b/test/fixtures/expression_equality/object.b.json @@ -0,0 +1,7 @@ +[ + "object", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/plus.a.json b/test/fixtures/expression_equality/plus.a.json new file mode 100644 index 0000000000..a00c4409fa --- /dev/null +++ b/test/fixtures/expression_equality/plus.a.json @@ -0,0 +1,7 @@ +[ + "+", + 1, + 2, + 3, + 4 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/plus.b.json b/test/fixtures/expression_equality/plus.b.json new file mode 100644 index 0000000000..87c071123f --- /dev/null +++ b/test/fixtures/expression_equality/plus.b.json @@ -0,0 +1,7 @@ +[ + "+", + 1, + 2, + 3, + 5 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/pow.a.json b/test/fixtures/expression_equality/pow.a.json new file mode 100644 index 0000000000..c1a1e67f86 --- /dev/null +++ b/test/fixtures/expression_equality/pow.a.json @@ -0,0 +1,11 @@ +[ + "^", + 4, + [ + "number", + [ + "get", + "x" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/pow.b.json b/test/fixtures/expression_equality/pow.b.json new file mode 100644 index 0000000000..ca5331b92a --- /dev/null +++ b/test/fixtures/expression_equality/pow.b.json @@ -0,0 +1,11 @@ +[ + "^", + 4, + [ + "number", + [ + "get", + "x_other" + ] + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/rgb.a.json b/test/fixtures/expression_equality/rgb.a.json new file mode 100644 index 0000000000..ce6c5e5dd0 --- /dev/null +++ b/test/fixtures/expression_equality/rgb.a.json @@ -0,0 +1,6 @@ +[ + "rgb", + 0, + 0, + 255 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/rgb.b.json b/test/fixtures/expression_equality/rgb.b.json new file mode 100644 index 0000000000..577c19748b --- /dev/null +++ b/test/fixtures/expression_equality/rgb.b.json @@ -0,0 +1,6 @@ +[ + "rgb", + 0, + 0, + 0 +] diff --git a/test/fixtures/expression_equality/rgba.a.json b/test/fixtures/expression_equality/rgba.a.json new file mode 100644 index 0000000000..e8ad7326c1 --- /dev/null +++ b/test/fixtures/expression_equality/rgba.a.json @@ -0,0 +1,7 @@ +[ + "rgba", + 0, + 0, + 255, + 1 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/rgba.b.json b/test/fixtures/expression_equality/rgba.b.json new file mode 100644 index 0000000000..81d442eaae --- /dev/null +++ b/test/fixtures/expression_equality/rgba.b.json @@ -0,0 +1,7 @@ +[ + "rgba", + 0, + 0, + 255, + 0.5 +] diff --git a/test/fixtures/expression_equality/sin.a.json b/test/fixtures/expression_equality/sin.a.json new file mode 100644 index 0000000000..0f7ae2966f --- /dev/null +++ b/test/fixtures/expression_equality/sin.a.json @@ -0,0 +1,4 @@ +[ + "sin", + 0 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/sin.b.json b/test/fixtures/expression_equality/sin.b.json new file mode 100644 index 0000000000..90f309b80f --- /dev/null +++ b/test/fixtures/expression_equality/sin.b.json @@ -0,0 +1,4 @@ +[ + "sin", + 1 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/sqrt.a.json b/test/fixtures/expression_equality/sqrt.a.json new file mode 100644 index 0000000000..56dd85bc1a --- /dev/null +++ b/test/fixtures/expression_equality/sqrt.a.json @@ -0,0 +1,7 @@ +[ + "sqrt", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/sqrt.b.json b/test/fixtures/expression_equality/sqrt.b.json new file mode 100644 index 0000000000..ab05d5084c --- /dev/null +++ b/test/fixtures/expression_equality/sqrt.b.json @@ -0,0 +1,7 @@ +[ + "sqrt", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/step.a.json b/test/fixtures/expression_equality/step.a.json new file mode 100644 index 0000000000..4fee85cd03 --- /dev/null +++ b/test/fixtures/expression_equality/step.a.json @@ -0,0 +1,18 @@ +[ + "number", + [ + "step", + [ + "number", + [ + "get", + "x" + ] + ], + 11, + 0, + 111, + 1, + 1111 + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/step.b.json b/test/fixtures/expression_equality/step.b.json new file mode 100644 index 0000000000..0a591a84df --- /dev/null +++ b/test/fixtures/expression_equality/step.b.json @@ -0,0 +1,18 @@ +[ + "number", + [ + "step", + [ + "number", + [ + "get", + "x" + ] + ], + 11, + 0, + 111, + 1, + 1112 + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/string.a.json b/test/fixtures/expression_equality/string.a.json new file mode 100644 index 0000000000..a79344f338 --- /dev/null +++ b/test/fixtures/expression_equality/string.a.json @@ -0,0 +1,7 @@ +[ + "string", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/string.b.json b/test/fixtures/expression_equality/string.b.json new file mode 100644 index 0000000000..6f77f3c3cf --- /dev/null +++ b/test/fixtures/expression_equality/string.b.json @@ -0,0 +1,7 @@ +[ + "string", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/tan.a.json b/test/fixtures/expression_equality/tan.a.json new file mode 100644 index 0000000000..c78e47e492 --- /dev/null +++ b/test/fixtures/expression_equality/tan.a.json @@ -0,0 +1,4 @@ +[ + "tan", + 0.7853981633974483 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/tan.b.json b/test/fixtures/expression_equality/tan.b.json new file mode 100644 index 0000000000..c22e64cf8a --- /dev/null +++ b/test/fixtures/expression_equality/tan.b.json @@ -0,0 +1,4 @@ +[ + "tan", + 1.7853981633974483 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/times.a.json b/test/fixtures/expression_equality/times.a.json new file mode 100644 index 0000000000..ce6d9b46e0 --- /dev/null +++ b/test/fixtures/expression_equality/times.a.json @@ -0,0 +1,7 @@ +[ + "*", + 3, + 2, + 0.5, + 2 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/times.b.json b/test/fixtures/expression_equality/times.b.json new file mode 100644 index 0000000000..147e011172 --- /dev/null +++ b/test/fixtures/expression_equality/times.b.json @@ -0,0 +1,7 @@ +[ + "*", + 3, + 2, + 0.5, + 3 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-boolean.a.json b/test/fixtures/expression_equality/to-boolean.a.json new file mode 100644 index 0000000000..ccf48149ec --- /dev/null +++ b/test/fixtures/expression_equality/to-boolean.a.json @@ -0,0 +1,7 @@ +[ + "to-boolean", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-boolean.b.json b/test/fixtures/expression_equality/to-boolean.b.json new file mode 100644 index 0000000000..7896261241 --- /dev/null +++ b/test/fixtures/expression_equality/to-boolean.b.json @@ -0,0 +1,7 @@ +[ + "to-boolean", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-color.a.json b/test/fixtures/expression_equality/to-color.a.json new file mode 100644 index 0000000000..de9ab59eec --- /dev/null +++ b/test/fixtures/expression_equality/to-color.a.json @@ -0,0 +1,7 @@ +[ + "to-color", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-color.b.json b/test/fixtures/expression_equality/to-color.b.json new file mode 100644 index 0000000000..c0566ef6a7 --- /dev/null +++ b/test/fixtures/expression_equality/to-color.b.json @@ -0,0 +1,7 @@ +[ + "to-color", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-number.a.json b/test/fixtures/expression_equality/to-number.a.json new file mode 100644 index 0000000000..65b2df5014 --- /dev/null +++ b/test/fixtures/expression_equality/to-number.a.json @@ -0,0 +1,7 @@ +[ + "to-number", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-number.b.json b/test/fixtures/expression_equality/to-number.b.json new file mode 100644 index 0000000000..b38dc5a455 --- /dev/null +++ b/test/fixtures/expression_equality/to-number.b.json @@ -0,0 +1,7 @@ +[ + "to-number", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-string.a.json b/test/fixtures/expression_equality/to-string.a.json new file mode 100644 index 0000000000..66f9a9caa1 --- /dev/null +++ b/test/fixtures/expression_equality/to-string.a.json @@ -0,0 +1,7 @@ +[ + "to-string", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/to-string.b.json b/test/fixtures/expression_equality/to-string.b.json new file mode 100644 index 0000000000..977a9d7769 --- /dev/null +++ b/test/fixtures/expression_equality/to-string.b.json @@ -0,0 +1,7 @@ +[ + "to-string", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/typeof.a.json b/test/fixtures/expression_equality/typeof.a.json new file mode 100644 index 0000000000..7843ff8c7f --- /dev/null +++ b/test/fixtures/expression_equality/typeof.a.json @@ -0,0 +1,7 @@ +[ + "typeof", + [ + "get", + "x" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/typeof.b.json b/test/fixtures/expression_equality/typeof.b.json new file mode 100644 index 0000000000..412482347a --- /dev/null +++ b/test/fixtures/expression_equality/typeof.b.json @@ -0,0 +1,7 @@ +[ + "typeof", + [ + "get", + "x_other" + ] +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/upcase.a.json b/test/fixtures/expression_equality/upcase.a.json new file mode 100644 index 0000000000..d12ca7b08d --- /dev/null +++ b/test/fixtures/expression_equality/upcase.a.json @@ -0,0 +1,4 @@ +[ + "upcase", + "string" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/upcase.b.json b/test/fixtures/expression_equality/upcase.b.json new file mode 100644 index 0000000000..ddeeb0300c --- /dev/null +++ b/test/fixtures/expression_equality/upcase.b.json @@ -0,0 +1,4 @@ +[ + "upcase", + "string_other" +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/zoom.a.json b/test/fixtures/expression_equality/zoom.a.json new file mode 100644 index 0000000000..fc675721ab --- /dev/null +++ b/test/fixtures/expression_equality/zoom.a.json @@ -0,0 +1,13 @@ +[ + "interpolate", + [ + "linear" + ], + [ + "zoom" + ], + 0, + 0, + 30, + 30 +]
\ No newline at end of file diff --git a/test/fixtures/expression_equality/zoom.b.json b/test/fixtures/expression_equality/zoom.b.json new file mode 100644 index 0000000000..6314858a5e --- /dev/null +++ b/test/fixtures/expression_equality/zoom.b.json @@ -0,0 +1,13 @@ +[ + "interpolate", + [ + "linear" + ], + [ + "zoom" + ], + 0, + 0, + 30, + 31 +]
\ No newline at end of file diff --git a/test/fixtures/style_parser/expressions.info.json b/test/fixtures/style_parser/expressions.info.json new file mode 100644 index 0000000000..9e1765ecd0 --- /dev/null +++ b/test/fixtures/style_parser/expressions.info.json @@ -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."] + ] + } +} diff --git a/test/fixtures/style_parser/expressions.style.json b/test/fixtures/style_parser/expressions.style.json new file mode 100644 index 0000000000..b9b4aeac7f --- /dev/null +++ b/test/fixtures/style_parser/expressions.style.json @@ -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]]] + } + } + ] +} diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index 9e8a6b3a7f..a48be2c075 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -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); +} diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp new file mode 100644 index 0000000000..694569695c --- /dev/null +++ b/test/style/expression/expression.test.cpp @@ -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; +}())); diff --git a/test/style/expression/util.test.cpp b/test/style/expression/util.test.cpp new file mode 100644 index 0000000000..0337cd871f --- /dev/null +++ b/test/style/expression/util.test.cpp @@ -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)); +} |