@@ -5,11 +5,11 @@ import Point from '@mapbox/point-geometry';
55import MercatorCoordinate from '../../geo/mercator_coordinate' ;
66import EXTENT from '../../data/extent' ;
77import { CanonicalTileID } from '../../source/tile_id' ;
8- import { ExpressionFilterSpecification , FilterSpecification } from '../types.g' ;
8+ import { ExpressionFilterSpecification , ExpressionInputType , ExpressionSpecification , FilterSpecification } from '../types.g' ;
99import { Feature } from '../expression' ;
1010
1111describe ( 'filter' , ( ) => {
12- test ( 'exprssions transpilation test' , ( ) => {
12+ test ( 'expressions transpilation test' , ( ) => {
1313 function compileTimeCheck ( _ : ExpressionFilterSpecification ) {
1414 expect ( true ) . toBeTruthy ( ) ;
1515 }
@@ -36,13 +36,43 @@ describe('filter', () => {
3636 compileTimeCheck ( [ 'match' , [ 'get' , 'TYPE' ] , [ 'TARGETPOINT:HOSPITAL' ] , true , false ] ) ;
3737 compileTimeCheck ( [ 'match' , [ 'get' , 'TYPE' ] , [ 'ADIZ' , 'AMA' , 'AWY' , 'CLASS' , 'NO-FIR' , 'OCA' , 'OTA' , 'P' , 'RAS' , 'RCA' , 'UTA' , 'UTA-P' ] , true , false ] ) ;
3838 compileTimeCheck ( [ '==' , [ 'get' , 'MILITARYAIRPORT' ] , 1 ] ) ;
39+ compileTimeCheck ( [ 'interpolate' , [ 'linear' ] , [ 'line-progress' ] , 0 , 10 , 0.5 , 100 , 1 , 1000 ] ) ; // number output
40+ compileTimeCheck ( [ 'interpolate' , [ 'linear' ] , [ 'line-progress' ] , 0 , 'red' , 0.5 , 'green' , 1 , 'blue' ] ) ; // color output
41+ compileTimeCheck ( [ 'interpolate' , [ 'linear' ] , [ 'line-progress' ] , 0 , [ 10 , 20 , 30 ] , 0.5 , [ 20 , 30 , 40 ] , 1 , [ 30 , 40 , 80 ] ] ) ; // number array output!
42+ compileTimeCheck ( [ 'interpolate-hcl' , [ 'linear' ] , [ 'line-progress' ] , 0 , 'red' , 0.5 , 'green' , 1 , 'blue' ] ) ;
43+ compileTimeCheck ( [ 'interpolate-lab' , [ 'linear' ] , [ 'line-progress' ] , 0 , 'red' , 0.5 , 'green' , 1 , 'blue' ] ) ;
44+ compileTimeCheck ( [ 'step' , [ 'get' , 'point_count' ] , '#df2d43' , 50 , '#df2d43' , 200 , '#df2d43' ] ) ;
45+ compileTimeCheck ( [ 'step' , [ 'get' , 'point_count' ] , 20 , 50 , 30 , 200 , 40 ] ) ;
46+ compileTimeCheck ( [ 'step' , [ 'get' , 'point_count' ] , 0.6 , 50 , 0.7 , 200 , 0.8 ] ) ;
47+
48+ // checks, where parts of the expression are injected from constants
49+ // as in most cases the styling is read from JSON, these are rather optional tests.
50+ // due to typescript inferring rather broad types, this is only possible in few places without specifying a type for the constant.
3951 const colorStops = [ 0 , 'red' , 0.5 , 'green' , 1 , 'blue' ] ;
4052 compileTimeCheck ( [
4153 'interpolate' ,
4254 [ 'linear' ] ,
4355 [ 'line-progress' ] ,
4456 ...colorStops
4557 ] ) ;
58+ compileTimeCheck ( [
59+ 'interpolate-hcl' ,
60+ [ 'linear' ] ,
61+ [ 'line-progress' ] ,
62+ ...colorStops
63+ ] ) ;
64+ compileTimeCheck ( [
65+ 'interpolate-lab' ,
66+ [ 'linear' ] ,
67+ [ 'line-progress' ] ,
68+ ...colorStops
69+ ] ) ;
70+ const [ firstOutput , ...steps ] = [ '#df2d43' , 50 , '#df2d43' , 200 , '#df2d43' ] ;
71+ compileTimeCheck ( [ 'step' , [ 'get' , 'point_count' ] , firstOutput , ...steps ] ) ;
72+ const strings = [ 'first' , 'second' , 'third' ] ;
73+ compileTimeCheck ( [ 'concat' , ...strings ] ) ;
74+ const values : ( ExpressionInputType | ExpressionSpecification ) [ ] = [ [ 'get' , 'name' ] , [ 'get' , 'code' ] , 'NONE' ] ; // type is necessary!
75+ compileTimeCheck ( [ 'coalesce' , ...values ] ) ;
4676 } ) ;
4777
4878 test ( 'expression, zoom' , ( ) => {
0 commit comments