[6674] | 1 | package org.openstreetmap.josm.data.osm
|
---|
| 2 |
|
---|
| 3 | class SimplePrimitiveIdTest extends GroovyTestCase {
|
---|
| 4 |
|
---|
| 5 | void testNode() {
|
---|
| 6 | assert SimplePrimitiveId.fromString("node/123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE)
|
---|
| 7 | assert SimplePrimitiveId.fromString("n123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE)
|
---|
| 8 | assert SimplePrimitiveId.fromString("node123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE)
|
---|
| 9 | assert SimplePrimitiveId.fromString("n123456789123456789") == new SimplePrimitiveId(123456789123456789, OsmPrimitiveType.NODE)
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | void testWay() {
|
---|
| 13 | assert SimplePrimitiveId.fromString("way/123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY)
|
---|
| 14 | assert SimplePrimitiveId.fromString("w123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY)
|
---|
| 15 | assert SimplePrimitiveId.fromString("way123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY)
|
---|
| 16 | assert SimplePrimitiveId.fromString("w123456789123456789") == new SimplePrimitiveId(123456789123456789, OsmPrimitiveType.WAY)
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | void testRelation() {
|
---|
| 20 | assert SimplePrimitiveId.fromString("relation/123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION)
|
---|
| 21 | assert SimplePrimitiveId.fromString("r123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION)
|
---|
| 22 | assert SimplePrimitiveId.fromString("rel123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION)
|
---|
| 23 | assert SimplePrimitiveId.fromString("relation123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION)
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[8496] | 26 | void testBad() {
|
---|
| 27 | shouldFail { SimplePrimitiveId.fromString("foobar") }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[6674] | 30 | void testFuzzy() {
|
---|
| 31 | assert SimplePrimitiveId.fuzzyParse("foo relation/123 bar").toString() == "[relation 123]"
|
---|
| 32 | assert SimplePrimitiveId.fuzzyParse("foo relation/123 and way/345 but also node/789").toString() == "[relation 123, way 345, node 789]"
|
---|
[8496] | 33 | assert SimplePrimitiveId.fuzzyParse("foo relation/123-24 and way/345-346 but also node/789").toString() == "[relation 123, relation 124, way 345, way 346, node 789]"
|
---|
[6674] | 34 | }
|
---|
[8194] | 35 |
|
---|
| 36 | void testFromCopyAction() {
|
---|
| 37 | assert SimplePrimitiveId.fromString("node 123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE)
|
---|
| 38 | assert SimplePrimitiveId.fromString("way 123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY)
|
---|
| 39 | assert SimplePrimitiveId.fromString("relation 123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION)
|
---|
| 40 | }
|
---|
[8496] | 41 |
|
---|
| 42 | void testMultipleIDs() {
|
---|
| 43 | assert SimplePrimitiveId.multipleFromString("node/234").toString() == "[node 234]"
|
---|
| 44 | assert SimplePrimitiveId.multipleFromString("node/234-234").toString() == "[node 234]"
|
---|
| 45 | assert SimplePrimitiveId.multipleFromString("node/2-1").toString() == "[]"
|
---|
| 46 | assert SimplePrimitiveId.multipleFromString("node/123-124").toString() == "[node 123, node 124]"
|
---|
| 47 | assert SimplePrimitiveId.multipleFromString("n/123-124").toString() == "[node 123, node 124]"
|
---|
| 48 | assert SimplePrimitiveId.multipleFromString("node123-126").toString() == "[node 123, node 124, node 125, node 126]"
|
---|
| 49 | assert SimplePrimitiveId.multipleFromString("way/123-123").toString() == "[way 123]"
|
---|
| 50 | assert SimplePrimitiveId.multipleFromString("w/123-127").toString() == "[way 123, way 124, way 125, way 126, way 127]"
|
---|
| 51 | assert SimplePrimitiveId.multipleFromString("way123-125").toString() == "[way 123, way 124, way 125]"
|
---|
| 52 | assert SimplePrimitiveId.multipleFromString("relation/123-125").toString() == "[relation 123, relation 124, relation 125]"
|
---|
| 53 | assert SimplePrimitiveId.multipleFromString("r/123-125").toString() == "[relation 123, relation 124, relation 125]"
|
---|
| 54 | assert SimplePrimitiveId.multipleFromString("relation123-125").toString() == "[relation 123, relation 124, relation 125]"
|
---|
| 55 | assert SimplePrimitiveId.multipleFromString("node/234-5").toString() == "[node 234, node 235]"
|
---|
| 56 | assert SimplePrimitiveId.multipleFromString("node/234-35").toString() == "[node 234, node 235]"
|
---|
| 57 | assert SimplePrimitiveId.multipleFromString("node/234-235").toString() == "[node 234, node 235]"
|
---|
| 58 | assert SimplePrimitiveId.multipleFromString("node/998-1001").toString() == "[node 998, node 999, node 1000, node 1001]"
|
---|
| 59 | shouldFail { SimplePrimitiveId.multipleFromString("foo node123 bar") }
|
---|
| 60 | }
|
---|
[6674] | 61 | }
|
---|