diff options
Diffstat (limited to 'test')
112 files changed, 1244 insertions, 176 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/shared_context/expected.png b/test/fixtures/shared_context/expected.png Binary files differnew file mode 100644 index 0000000000..3b3fd0e315 --- /dev/null +++ b/test/fixtures/shared_context/expected.png 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/gl/bucket.test.cpp b/test/gl/bucket.test.cpp index 5f9626bc99..0e73dfb28f 100644 --- a/test/gl/bucket.test.cpp +++ b/test/gl/bucket.test.cpp @@ -1,6 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_geometry_tile_feature.hpp> +#include <mbgl/renderer/backend_scope.hpp> #include <mbgl/renderer/buckets/circle_bucket.hpp> #include <mbgl/renderer/buckets/fill_bucket.hpp> #include <mbgl/renderer/buckets/line_bucket.hpp> @@ -9,6 +10,7 @@ #include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> #include <mbgl/gl/context.hpp> +#include <mbgl/gl/headless_backend.hpp> #include <mbgl/map/mode.hpp> @@ -41,6 +43,9 @@ PropertyMap properties; } // namespace TEST(Buckets, CircleBucket) { + HeadlessBackend backend({ 512, 256 }); + BackendScope scope { backend }; + gl::Context context; CircleBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {} }; ASSERT_FALSE(bucket.hasData()); @@ -57,6 +62,9 @@ TEST(Buckets, CircleBucket) { } TEST(Buckets, FillBucket) { + HeadlessBackend backend({ 512, 256 }); + BackendScope scope { backend }; + gl::Context context; FillBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {} }; ASSERT_FALSE(bucket.hasData()); @@ -72,6 +80,9 @@ TEST(Buckets, FillBucket) { } TEST(Buckets, LineBucket) { + HeadlessBackend backend({ 512, 256 }); + BackendScope scope { backend }; + gl::Context context; LineBucket bucket { { {0, 0, 0}, MapMode::Still, 1.0 }, {}, {} }; ASSERT_FALSE(bucket.hasData()); @@ -92,6 +103,9 @@ TEST(Buckets, LineBucket) { } TEST(Buckets, SymbolBucket) { + HeadlessBackend backend({ 512, 256 }); + BackendScope scope { backend }; + style::SymbolLayoutProperties::PossiblyEvaluated layout; bool sdfIcons = false; bool iconsNeedLinear = false; @@ -120,6 +134,9 @@ TEST(Buckets, SymbolBucket) { } TEST(Buckets, RasterBucket) { + HeadlessBackend backend({ 512, 256 }); + BackendScope scope { backend }; + gl::Context context; PremultipliedImage rgba({ 1, 1 }); diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp new file mode 100644 index 0000000000..19e8ad5928 --- /dev/null +++ b/test/gl/context.test.cpp @@ -0,0 +1,114 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/context.hpp> +#include <mbgl/map/map.hpp> +#include <mbgl/util/default_thread_pool.hpp> +#include <mbgl/storage/default_file_source.hpp> +#include <mbgl/gl/headless_frontend.hpp> +#include <mbgl/style/style.hpp> +#include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/util/io.hpp> +#include <mbgl/util/mat4.hpp> +#include <mbgl/util/run_loop.hpp> + +using namespace mbgl; +using namespace mbgl::style; + +static const GLchar* vertexShaderSource = R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif +attribute vec2 a_pos; +void main() { + gl_Position = vec4(a_pos, 0, 1); +} +)MBGL_SHADER"; + +static const GLchar* fragmentShaderSource = R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif +void main() { + gl_FragColor = vec4(0, 1, 0, 1); +} +)MBGL_SHADER"; + +struct Shader { + Shader(const GLchar* vertex, const GLchar* fragment) { + program = MBGL_CHECK_ERROR(glCreateProgram()); + vertexShader = MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)); + fragmentShader = MBGL_CHECK_ERROR(glCreateShader(GL_FRAGMENT_SHADER)); + MBGL_CHECK_ERROR(glShaderSource(vertexShader, 1, &vertex, nullptr)); + MBGL_CHECK_ERROR(glCompileShader(vertexShader)); + MBGL_CHECK_ERROR(glAttachShader(program, vertexShader)); + MBGL_CHECK_ERROR(glShaderSource(fragmentShader, 1, &fragment, nullptr)); + MBGL_CHECK_ERROR(glCompileShader(fragmentShader)); + MBGL_CHECK_ERROR(glAttachShader(program, fragmentShader)); + MBGL_CHECK_ERROR(glLinkProgram(program)); + a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos")); + } + + ~Shader() { + MBGL_CHECK_ERROR(glDetachShader(program, vertexShader)); + MBGL_CHECK_ERROR(glDetachShader(program, fragmentShader)); + MBGL_CHECK_ERROR(glDeleteShader(vertexShader)); + MBGL_CHECK_ERROR(glDeleteShader(fragmentShader)); + MBGL_CHECK_ERROR(glDeleteProgram(program)); + } + + GLuint program = 0; + GLuint vertexShader = 0; + GLuint fragmentShader = 0; + GLuint a_pos = 0; +}; + +struct Buffer { + Buffer(std::vector<GLfloat> data) { + MBGL_CHECK_ERROR(glGenBuffers(1, &buffer)); + MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, buffer)); + MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), data.data(), + GL_STATIC_DRAW)); + } + + ~Buffer() { + MBGL_CHECK_ERROR(glDeleteBuffers(1, &buffer)); + } + + GLuint buffer = 0; +}; + +TEST(GLContextMode, Shared) { + util::RunLoop loop; + + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); + ThreadPool threadPool(4); + float pixelRatio { 1 }; + + HeadlessFrontend frontend { pixelRatio, fileSource, threadPool, {}, GLContextMode::Shared }; + + Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Still); + map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); + map.setLatLngZoom({ 37.8, -122.5 }, 10); + + // Set transparent background layer. + map.getStyle().getLayer("background")->as<BackgroundLayer>()->setBackgroundColor( { { 1.0f, 0.0f, 0.0f, 0.5f } } ); + + { + // Custom rendering outside of GL Native render loop. + BackendScope scope { *frontend.getBackend() }; + frontend.getBackend()->bind(); + + Shader paintShader(vertexShaderSource, fragmentShaderSource); + Buffer triangleBuffer({ 0, 0.5, 0.5, -0.5, -0.5, -0.5 }); + MBGL_CHECK_ERROR(glUseProgram(paintShader.program)); + MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer)); + MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr)); + MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3)); + } + + test::checkImage("test/fixtures/shared_context", frontend.render(map), 0.5, 0.1); +} diff --git a/test/src/mbgl/test/conversion_stubs.hpp b/test/src/mbgl/test/conversion_stubs.hpp deleted file mode 100644 index 30395ddb97..0000000000 --- a/test/src/mbgl/test/conversion_stubs.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once - -#include <mbgl/style/conversion.hpp> -#include <mbgl/util/feature.hpp> -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> - -#include <string> -#include <unordered_map> - -namespace mbgl { -namespace style { -namespace conversion { - -class Value; -using ValueMap = std::unordered_map<std::string, Value>; -using ValueVector = std::vector<Value>; -class Value : public mbgl::variant<std::string, - float, - double, - bool, - mapbox::util::recursive_wrapper<ValueMap>, - mapbox::util::recursive_wrapper<ValueVector>> { - using variant::variant; -}; - -inline bool isUndefined(const Value&) { - // Variant is always intialized - return false; -} - -inline bool isArray(const Value& value) { - return value.is<mapbox::util::recursive_wrapper<ValueVector>>(); -} - -inline std::size_t arrayLength(const Value& value) { - return value.get<mapbox::util::recursive_wrapper<ValueVector>>().get().size(); -} - -inline Value arrayMember(const Value& value, std::size_t i) { - return value.get<mapbox::util::recursive_wrapper<ValueVector>>().get()[i]; -} - -inline bool isObject(const Value& value) { - return value.is<mapbox::util::recursive_wrapper<ValueMap>>(); -} - -inline optional<Value> objectMember(const Value& value, const char* key) { - auto map = value.get<ValueMap>(); - auto iter = map.find(key); - - if (iter != map.end()) { - return iter->second; - } else { - return {}; - } -} - -using EachMemberFn = std::function<optional<Error>(const std::string&, const Value&)>; - -optional<Error> eachMember(const Value& value, EachMemberFn&& fn) { - auto map = value.get<ValueMap>(); - auto iter = map.begin(); - - while (iter != map.end()) { - optional<Error> result = fn(iter->first, iter->second); - if (result) { - return result; - } - - ++iter; - } - - return {}; -} - -inline optional<bool> toBool(const Value& value) { - if (value.is<bool>()) { - return value.get<bool>(); - } else { - return {}; - } -} - -inline optional<float> toNumber(const Value& value) { - if (value.is<float>()) { - return value.get<float>(); - } else { - return {}; - } - return {}; -} - - -inline optional<double> toDouble(const Value& value) { - if (value.is<double>()) { - return value.get<double>(); - } - return {}; -} - -inline optional<std::string> toString(const Value& value) { - if (value.is<std::string>()) { - return value.get<std::string>(); - } else { - return {}; - } -} - -inline optional<mbgl::Value> toValue(const Value& value) { - if (value.is<bool>()) { - return { value.get<bool>() }; - } else if (value.is<std::string>()) { - return { value.get<std::string>() }; - } else if (value.is<float>()) { - return { double(value.get<float>()) }; - } else { - return {}; - } -} - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/test/src/mbgl/test/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp index 7891d5d907..0bbff84ff3 100644 --- a/test/src/mbgl/test/stub_file_source.cpp +++ b/test/src/mbgl/test/stub_file_source.cpp @@ -17,7 +17,12 @@ public: StubFileSource& fileSource; }; -StubFileSource::StubFileSource() { +StubFileSource::StubFileSource(ResponseType type_) + : type(type_) { + if (type == ResponseType::Synchronous) { + return; + } + timer.start(1ms, 1ms, [this] { // Explicit copy to avoid iterator invalidation if ~StubFileRequest gets called within the loop. auto pending_ = pending; @@ -46,7 +51,14 @@ StubFileSource::~StubFileSource() = default; std::unique_ptr<AsyncRequest> StubFileSource::request(const Resource& resource, Callback callback) { auto req = std::make_unique<StubFileRequest>(*this); - pending.emplace(req.get(), std::make_tuple(resource, response, callback)); + if (type == ResponseType::Synchronous) { + optional<Response> res = response(resource); + if (res) { + callback(*res); + } + } else { + pending.emplace(req.get(), std::make_tuple(resource, response, callback)); + } return std::move(req); } diff --git a/test/src/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp index 85118e1a77..6cee8377c6 100644 --- a/test/src/mbgl/test/stub_file_source.hpp +++ b/test/src/mbgl/test/stub_file_source.hpp @@ -9,7 +9,12 @@ namespace mbgl { class StubFileSource : public FileSource { public: - StubFileSource(); + enum class ResponseType { + Asynchronous = 0, + Synchronous + }; + + StubFileSource(ResponseType = ResponseType::Asynchronous); ~StubFileSource() override; std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override; @@ -36,6 +41,7 @@ private: optional<Response> defaultResponse(const Resource&); std::unordered_map<AsyncRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending; + ResponseType type; util::Timer timer; }; diff --git a/test/storage/offline.test.cpp b/test/storage/offline.test.cpp index e7ebe5199f..59aebebaba 100644 --- a/test/storage/offline.test.cpp +++ b/test/storage/offline.test.cpp @@ -4,6 +4,7 @@ #include <gtest/gtest.h> using namespace mbgl; +using SourceType = mbgl::style::SourceType; static const LatLngBounds sanFrancisco = LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }); diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index 1eff94d939..a48be2c075 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -1,9 +1,9 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#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; @@ -13,10 +13,8 @@ using namespace mbgl::style::conversion; TEST(StyleConversion, Function) { Error error; - auto parseFunction = [&](const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); - return convert<CameraFunction<float>, JSValue>(doc, error); + auto parseFunction = [&](const std::string& json) { + return convertJSON<CameraFunction<float>>(json, error); }; auto fn1 = parseFunction(R"({"stops":[]})"); @@ -54,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/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index a798ad6559..4c5a0c9aa4 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -1,8 +1,7 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/geojson_options.hpp> -#include <mbgl/test/conversion_stubs.hpp> #include <mbgl/util/logging.hpp> @@ -10,26 +9,22 @@ using namespace mbgl::style; using namespace mbgl::style::conversion; TEST(GeoJSONOptions, Basic) { - ValueMap map; - Value raw(map); Error error; - mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); + mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>("{}", error); ASSERT_TRUE((bool) converted); } TEST(GeoJSONOptions, ErrorHandling) { - ValueMap map {{"maxzoom", std::string{"should not be a string"}}}; - Value raw(map); Error error; - mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); + mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(R"JSON({ + "maxzoom": "should not be a string" + })JSON", error); ASSERT_FALSE((bool) converted); } TEST(GeoJSONOptions, RetainsDefaults) { - ValueMap map; - Value raw(map); Error error; - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); + GeoJSONOptions converted = *convertJSON<GeoJSONOptions>("{}", error); GeoJSONOptions defaults; // GeoJSON-VT @@ -44,22 +39,16 @@ TEST(GeoJSONOptions, RetainsDefaults) { ASSERT_EQ(converted.clusterMaxZoom, defaults.clusterMaxZoom); } - TEST(GeoJSONOptions, FullConversion) { - ValueMap map { - // GeoJSON-VT - {"maxzoom", 1.0f}, - {"buffer", 2.0f}, - {"tolerance", 3.0f}, - - // Supercluster - {"cluster", true}, - {"clusterRadius", 4.0f}, - {"clusterMaxZoom", 5.0f} - }; - Value raw(map); Error error; - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); + GeoJSONOptions converted = *convertJSON<GeoJSONOptions>(R"JSON({ + "maxzoom": 1, + "buffer": 2, + "tolerance": 3, + "cluster": true, + "clusterRadius": 4, + "clusterMaxZoom": 5 + })JSON", error); // GeoJSON-VT ASSERT_EQ(converted.minzoom, 0); diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index d51d7d33e2..33cd329999 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -1,10 +1,8 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> -#include <mbgl/util/rapidjson.hpp> using namespace mbgl; using namespace mbgl::style; @@ -12,10 +10,8 @@ using namespace mbgl::style::conversion; using namespace std::literals::chrono_literals; std::unique_ptr<Layer> parseLayer(const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); Error error; - return std::move(*convert<std::unique_ptr<Layer>, JSValue>(doc, error)); + return std::move(*convertJSON<std::unique_ptr<Layer>>(src, error)); } TEST(StyleConversion, LayerTransition) { diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp index 28e22b3550..67e48c942e 100644 --- a/test/style/conversion/light.test.cpp +++ b/test/style/conversion/light.test.cpp @@ -1,11 +1,10 @@ #include <mbgl/test/util.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/constant.hpp> #include <mbgl/style/conversion/light.hpp> #include <mbgl/style/position.hpp> -#include <mbgl/util/rapidjson.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/chrono.hpp> @@ -19,9 +18,7 @@ TEST(StyleConversion, Light) { Error error; auto parseLight = [&](const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); - return convert<Light>(doc, error); + return convertJSON<Light>(src, error); }; { 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)); +} diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index 96de125945..73f8e7626d 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -4,20 +4,15 @@ #include <mbgl/style/filter.hpp> #include <mbgl/style/filter_evaluator.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> -#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/filter.hpp> -#include <rapidjson/document.h> - using namespace mbgl; using namespace mbgl::style; Filter parse(const char * expression) { - rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; - doc.Parse<0>(expression); conversion::Error error; - optional<Filter> filter = conversion::convert<Filter, JSValue>(doc, error); + optional<Filter> filter = conversion::convertJSON<Filter>(expression, error); EXPECT_TRUE(bool(filter)); return *filter; } diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 919260ffe9..bee1b867b8 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -38,6 +38,7 @@ #include <cstdint> using namespace mbgl; +using SourceType = mbgl::style::SourceType; class SourceTest { public: diff --git a/test/text/glyph_loader.test.cpp b/test/text/glyph_loader.test.cpp index be197ebb46..20ac045925 100644 --- a/test/text/glyph_loader.test.cpp +++ b/test/text/glyph_loader.test.cpp @@ -214,3 +214,52 @@ TEST(GlyphManager, LoadingInvalid) { {{{"Test Stack"}}, {u'A', u'E'}} }); } + +TEST(GlyphManager, ImmediateFileSource) { + class GlyphManagerTestSynchronous { + public: + util::RunLoop loop; + StubFileSource fileSource = { StubFileSource::ResponseType::Synchronous }; + StubGlyphManagerObserver observer; + StubGlyphRequestor requestor; + GlyphManager glyphManager { fileSource }; + + void run(const std::string& url, GlyphDependencies dependencies) { + // Squelch logging. + Log::setObserver(std::make_unique<Log::NullObserver>()); + + glyphManager.setURL(url); + glyphManager.setObserver(&observer); + glyphManager.getGlyphs(requestor, std::move(dependencies)); + + loop.run(); + } + + void end() { + loop.stop(); + } + }; + + GlyphManagerTestSynchronous test; + + test.fileSource.glyphsResponse = [&] (const Resource&) { + Response response; + response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf")); + return response; + }; + + test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) { + FAIL(); + test.end(); + }; + + test.requestor.glyphsAvailable = [&] (GlyphMap) { + test.end(); + }; + + test.run( + "test/fixtures/resources/glyphs.pbf", + GlyphDependencies { + {{{"Test Stack"}}, {u'a', u'å', u' '}} + }); +} diff --git a/test/util/geo.test.cpp b/test/util/geo.test.cpp index d0d01b6f88..38f29d1dd4 100644 --- a/test/util/geo.test.cpp +++ b/test/util/geo.test.cpp @@ -220,3 +220,9 @@ TEST(LatLngBounds, FromTileID) { ASSERT_DOUBLE_EQ(util::LATITUDE_MAX, bounds.north()); } } + +TEST(LatLngBounds, Contains) { + const LatLngBounds bounds( CanonicalTileID(4,2,6)); + const LatLngBounds innerBounds( CanonicalTileID(9,82,197)); + EXPECT_TRUE(bounds.contains(innerBounds)); +} diff --git a/test/util/mapbox.test.cpp b/test/util/mapbox.test.cpp index cdbd85118f..301475dae4 100644 --- a/test/util/mapbox.test.cpp +++ b/test/util/mapbox.test.cpp @@ -7,6 +7,7 @@ #include <stdexcept> using namespace mbgl; +using SourceType = mbgl::style::SourceType; TEST(Mapbox, SourceURL) { EXPECT_EQ( |