source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/ExpressionTest.java@ 17862

Last change on this file since 17862 was 17862, checked in by simon04, 3 years ago

fix #17177 - Add support for Mapbox Vector Tile (patch by taylor.smock)

Signed-off-by: Taylor Smock <tsmock@…>

File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery.vectortile.mapbox.style;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6
7import javax.json.Json;
8import javax.json.JsonValue;
9
10import nl.jqno.equalsverifier.EqualsVerifier;
11import org.junit.jupiter.api.Test;
12
13/**
14 * Test class for {@link Expression}
15 * @author Taylor Smock
16 * @since xxx
17 */
18class ExpressionTest {
19 @Test
20 void testInvalidJson() {
21 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.NULL));
22 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.FALSE));
23 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.TRUE));
24 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.EMPTY_JSON_OBJECT));
25 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(JsonValue.EMPTY_JSON_ARRAY));
26 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createObjectBuilder().add("bad", "value").build()));
27 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue(1)));
28 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue(1.0)));
29 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createValue("bad string")));
30 }
31
32 @Test
33 void testBasicExpressions() {
34 // "filter": [ "==|>=|<=|<|>", "key", "value" ]
35 assertEquals("[key=value]", new Expression(Json.createArrayBuilder().add("==").add("key").add("value").build()).toString());
36 assertEquals("[key>=true]", new Expression(Json.createArrayBuilder().add(">=").add("key").add(true).build()).toString());
37 assertEquals("[key<=false]", new Expression(Json.createArrayBuilder().add("<=").add("key").add(false).build()).toString());
38 assertEquals("[key<1]", new Expression(Json.createArrayBuilder().add("<").add("key").add(1).build()).toString());
39 assertEquals("[key>2.5]", new Expression(Json.createArrayBuilder().add(">").add("key").add(2.5).build()).toString());
40 // Test bad expression
41 assertEquals(Expression.EMPTY_EXPRESSION, new Expression(Json.createArrayBuilder().add(">>").add("key").add("value").build()));
42
43 // Test expressions with a subarray and object. This is expected to fail when properly supported, so it should be fixed.
44 assertEquals("[key=[{bad:value}]]", new Expression(Json.createArrayBuilder().add("==").add("key").add(
45 Json.createArrayBuilder().add(Json.createObjectBuilder().add("bad", "value"))).build()).toString());
46 assertEquals("[key=]", new Expression(Json.createArrayBuilder().add("==").add("key").add(JsonValue.NULL).build()).toString());
47 }
48
49 @Test
50 void testEquals() {
51 EqualsVerifier.forClass(Expression.class).verify();
52 }
53}
Note: See TracBrowser for help on using the repository browser.