1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.corrector;
|
---|
3 |
|
---|
4 | import org.junit.Assert;
|
---|
5 | import org.junit.BeforeClass;
|
---|
6 | import org.junit.Test;
|
---|
7 | import org.openstreetmap.josm.JOSMFixture;
|
---|
8 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Unit tests of {@link ReverseWayTagCorrector} class.
|
---|
12 | */
|
---|
13 | public class ReverseWayTagCorrectorTest {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Setup test.
|
---|
17 | */
|
---|
18 | @BeforeClass
|
---|
19 | public static void setUp() {
|
---|
20 | JOSMFixture.createUnitTestFixture().init();
|
---|
21 | }
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test of {@link ReverseWayTagCorrector.TagSwitcher#apply} method.
|
---|
25 | */
|
---|
26 | @Test
|
---|
27 | public void testTagSwitch() {
|
---|
28 | // oneway
|
---|
29 | assertSwitch(new Tag("oneway", "yes"), new Tag("oneway", "-1"));
|
---|
30 | assertSwitch(new Tag("oneway", "true"), new Tag("oneway", "-1"));
|
---|
31 | assertSwitch(new Tag("oneway", "-1"), new Tag("oneway", "yes"));
|
---|
32 | assertSwitch(new Tag("oneway", "no"), new Tag("oneway", "no"));
|
---|
33 | assertSwitch(new Tag("oneway", "something"), new Tag("oneway", "something"));
|
---|
34 | // incline/direction
|
---|
35 | for (String k : new String[]{"incline", "direction"}) {
|
---|
36 | assertSwitch(new Tag(k, "up"), new Tag(k, "down"));
|
---|
37 | assertSwitch(new Tag(k, "down"), new Tag(k, "up"));
|
---|
38 | assertSwitch(new Tag(k, "something"), new Tag(k, "something"));
|
---|
39 | }
|
---|
40 | // :left/:right with oneway (see #10977)
|
---|
41 | assertSwitch(new Tag("cycleway:left:oneway", "-1"), new Tag("cycleway:right:oneway", "yes"));
|
---|
42 | // :forward/:backward (see #8518)
|
---|
43 | assertSwitch(new Tag("turn:forward", "right"), new Tag("turn:backward", "right"));
|
---|
44 | assertSwitch(new Tag("change:forward", "not_right"), new Tag("change:backward", "not_right"));
|
---|
45 | assertSwitch(new Tag("placement:forward", "right_of:1"), new Tag("placement:backward", "right_of:1"));
|
---|
46 | assertSwitch(new Tag("turn:lanes:forward", "left|right"), new Tag("turn:lanes:backward", "left|right"));
|
---|
47 | assertSwitch(new Tag("change:lanes:forward", "not_right|only_left"), new Tag("change:lanes:backward", "not_right|only_left"));
|
---|
48 | // keys
|
---|
49 | assertSwitch(new Tag("forward", "something"), new Tag("backward", "something"));
|
---|
50 | assertSwitch(new Tag("backward", "something"), new Tag("forward", "something"));
|
---|
51 | assertSwitch(new Tag("up", "something"), new Tag("down", "something"));
|
---|
52 | assertSwitch(new Tag("down", "something"), new Tag("up", "something"));
|
---|
53 | assertSwitch(new Tag("east", "something"), new Tag("west", "something"));
|
---|
54 | assertSwitch(new Tag("west", "something"), new Tag("east", "something"));
|
---|
55 | assertSwitch(new Tag("south", "something"), new Tag("north", "something"));
|
---|
56 | assertSwitch(new Tag("north", "something"), new Tag("south", "something"));
|
---|
57 | // values
|
---|
58 | assertSwitch(new Tag("something", "forward"), new Tag("something", "backward"));
|
---|
59 | assertSwitch(new Tag("something", "backward"), new Tag("something", "forward"));
|
---|
60 | assertSwitch(new Tag("something", "up"), new Tag("something", "down"));
|
---|
61 | assertSwitch(new Tag("something", "down"), new Tag("something", "up"));
|
---|
62 | assertSwitch(new Tag("something", "east"), new Tag("something", "west"));
|
---|
63 | assertSwitch(new Tag("something", "west"), new Tag("something", "east"));
|
---|
64 | assertSwitch(new Tag("something", "south"), new Tag("something", "north"));
|
---|
65 | assertSwitch(new Tag("something", "north"), new Tag("something", "south"));
|
---|
66 | // value[:_]suffix
|
---|
67 | assertSwitch(new Tag("something", "forward:suffix"), new Tag("something", "backward:suffix"));
|
---|
68 | assertSwitch(new Tag("something", "backward_suffix"), new Tag("something", "forward_suffix"));
|
---|
69 | assertSwitch(new Tag("something", "up:suffix"), new Tag("something", "down:suffix"));
|
---|
70 | assertSwitch(new Tag("something", "down_suffix"), new Tag("something", "up_suffix"));
|
---|
71 | assertSwitch(new Tag("something", "east:suffix"), new Tag("something", "west:suffix"));
|
---|
72 | assertSwitch(new Tag("something", "west_suffix"), new Tag("something", "east_suffix"));
|
---|
73 | assertSwitch(new Tag("something", "south:suffix"), new Tag("something", "north:suffix"));
|
---|
74 | assertSwitch(new Tag("something", "north_suffix"), new Tag("something", "south_suffix"));
|
---|
75 | // prefix[:_]value
|
---|
76 | assertSwitch(new Tag("something", "prefix:forward"), new Tag("something", "prefix:backward"));
|
---|
77 | assertSwitch(new Tag("something", "prefix_backward"), new Tag("something", "prefix_forward"));
|
---|
78 | assertSwitch(new Tag("something", "prefix:up"), new Tag("something", "prefix:down"));
|
---|
79 | assertSwitch(new Tag("something", "prefix_down"), new Tag("something", "prefix_up"));
|
---|
80 | assertSwitch(new Tag("something", "prefix:east"), new Tag("something", "prefix:west"));
|
---|
81 | assertSwitch(new Tag("something", "prefix_west"), new Tag("something", "prefix_east"));
|
---|
82 | assertSwitch(new Tag("something", "prefix:south"), new Tag("something", "prefix:north"));
|
---|
83 | assertSwitch(new Tag("something", "prefix_north"), new Tag("something", "prefix_south"));
|
---|
84 | // prefix[:_]value[:_]suffix
|
---|
85 | assertSwitch(new Tag("something", "prefix:forward:suffix"), new Tag("something", "prefix:backward:suffix"));
|
---|
86 | assertSwitch(new Tag("something", "prefix_backward:suffix"), new Tag("something", "prefix_forward:suffix"));
|
---|
87 | assertSwitch(new Tag("something", "prefix:up_suffix"), new Tag("something", "prefix:down_suffix"));
|
---|
88 | assertSwitch(new Tag("something", "prefix_down_suffix"), new Tag("something", "prefix_up_suffix"));
|
---|
89 | assertSwitch(new Tag("something", "prefix:east:suffix"), new Tag("something", "prefix:west:suffix"));
|
---|
90 | assertSwitch(new Tag("something", "prefix_west:suffix"), new Tag("something", "prefix_east:suffix"));
|
---|
91 | assertSwitch(new Tag("something", "prefix:south_suffix"), new Tag("something", "prefix:north_suffix"));
|
---|
92 | assertSwitch(new Tag("something", "prefix_north_suffix"), new Tag("something", "prefix_south_suffix"));
|
---|
93 | // #8499
|
---|
94 | assertSwitch(new Tag("type", "drawdown"), new Tag("type", "drawdown"));
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void assertSwitch(Tag oldTag, Tag newTag) {
|
---|
98 | Assert.assertEquals(ReverseWayTagCorrector.TagSwitcher.apply(oldTag), newTag);
|
---|
99 | }
|
---|
100 | }
|
---|