From 4e163c13d17289ff448e7f5cbcf3805b16f7a454 Mon Sep 17 00:00:00 2001
From: Jiri Vlasak <jiri.hubacek@gmail.com>
Date: Sun, 13 Jan 2019 01:54:55 +0100
Subject: [PATCH] Add unit test for `element of` operator

See: #10391
---
 data_nodist/buildings-in-residential.osm           | 59 ++++++++++++++++++++++
 .../mappaint/mapcss/ChildOrParentSelectorTest.java | 25 +++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 data_nodist/buildings-in-residential.osm

diff --git a/data_nodist/buildings-in-residential.osm b/data_nodist/buildings-in-residential.osm
new file mode 100644
index 000000000..d30383554
--- /dev/null
+++ b/data_nodist/buildings-in-residential.osm
@@ -0,0 +1,59 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<osm version='0.6' generator='JOSM'>
+  <node id='-39804' action='modify' visible='true' lat='-11.1381068304' lon='30.01079208962' />
+  <node id='-39805' action='modify' visible='true' lat='-11.13804838855' lon='30.01083422008' />
+  <node id='-39806' action='modify' visible='true' lat='-11.1380833706' lon='30.01088462689' />
+  <node id='-39807' action='modify' visible='true' lat='-11.13814181244' lon='30.01084249643' />
+  <node id='-39818' action='modify' visible='true' lat='-11.13790167136' lon='30.01090273127' />
+  <node id='-39819' action='modify' visible='true' lat='-11.13791088227' lon='30.01096442208' />
+  <node id='-39825' action='modify' visible='true' lat='-11.13789513304' lon='30.01096263651' />
+  <node id='-39826' action='modify' visible='true' lat='-11.13788236978' lon='30.01095306438' />
+  <node id='-39827' action='modify' visible='true' lat='-11.13787601238' lon='30.01093827054' />
+  <node id='-39828' action='modify' visible='true' lat='-11.13787776432' lon='30.01092221898' />
+  <node id='-39829' action='modify' visible='true' lat='-11.13788715616' lon='30.0109092107' />
+  <node id='-39830' action='modify' visible='true' lat='-11.13791742059' lon='30.01090451684' />
+  <node id='-39831' action='modify' visible='true' lat='-11.13793018385' lon='30.01091408896' />
+  <node id='-39832' action='modify' visible='true' lat='-11.13793654125' lon='30.01092888281' />
+  <node id='-39833' action='modify' visible='true' lat='-11.13793478931' lon='30.01094493437' />
+  <node id='-39834' action='modify' visible='true' lat='-11.13792539748' lon='30.01095794264' />
+  <node id='-39844' action='modify' visible='true' lat='-11.13819469613' lon='30.0107381907' />
+  <node id='-39845' action='modify' visible='true' lat='-11.13819469613' lon='30.01093852581' />
+  <node id='-39846' action='modify' visible='true' lat='-11.13798942497' lon='30.01101832099' />
+  <node id='-39847' action='modify' visible='true' lat='-11.13782312864' lon='30.01101832099' />
+  <node id='-39848' action='modify' visible='true' lat='-11.13782312864' lon='30.01084883235' />
+  <node id='-39849' action='modify' visible='true' lat='-11.13799550484' lon='30.0107381907' />
+  <way id='101' version='3' action='modify' visible='true'>
+    <nd ref='-39804' />
+    <nd ref='-39805' />
+    <nd ref='-39806' />
+    <nd ref='-39807' />
+    <nd ref='-39804' />
+    <tag k='building' v='yes' />
+  </way>
+  <way id='102' version='3' action='modify' visible='true'>
+    <nd ref='-39819' />
+    <nd ref='-39825' />
+    <nd ref='-39826' />
+    <nd ref='-39827' />
+    <nd ref='-39828' />
+    <nd ref='-39829' />
+    <nd ref='-39818' />
+    <nd ref='-39830' />
+    <nd ref='-39831' />
+    <nd ref='-39832' />
+    <nd ref='-39833' />
+    <nd ref='-39834' />
+    <nd ref='-39819' />
+    <tag k='building' v='yes' />
+  </way>
+  <way id='103' version='3' action='modify' visible='true'>
+    <nd ref='-39844' />
+    <nd ref='-39845' />
+    <nd ref='-39846' />
+    <nd ref='-39847' />
+    <nd ref='-39848' />
+    <nd ref='-39849' />
+    <nd ref='-39844' />
+    <tag k='landuse' v='residential' />
+  </way>
+</osm>
diff --git a/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.java b/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.java
index 0d0b669e0..86018ae8f 100644
--- a/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.java
+++ b/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.java
@@ -192,4 +192,29 @@ public class ChildOrParentSelectorTest {
         assertTrue(css.matches(new Environment(ds.getPrimitiveById(123, OsmPrimitiveType.WAY))));
         assertTrue(css.matches(new Environment(ds.getPrimitiveById(123, OsmPrimitiveType.RELATION))));
     }
+
+    /**
+     * Test the element of operator.
+     *
+     * See ticket #10391 (https://josm.openstreetmap.de/ticket/10391).
+     */
+    @Test
+    public void testElementOfOperator() throws Exception {
+        FileInputStream fi;
+        fi = new FileInputStream("data_nodist/buildings-in-residential.osm");
+        ds = OsmReader.parseDataSet(fi, null);
+
+        ChildOrParentSelector s;
+        s = parse("area[building] ∈ area[landuse=residential][landuse] {}");
+
+        Environment e;
+        e = new Environment(ds.getPrimitiveById(101, OsmPrimitiveType.WAY));
+        assertTrue(s.matches(e));
+
+        e = new Environment(ds.getPrimitiveById(102, OsmPrimitiveType.WAY));
+        assertTrue(s.matches(e));
+
+        e = new Environment(ds.getPrimitiveById(103, OsmPrimitiveType.WAY));
+        assertFalse(s.matches(e));
+    }
 }
-- 
2.11.0

