Changeset 9940 in josm for trunk/test


Ignore:
Timestamp:
2016-03-06T17:12:42+01:00 (8 years ago)
Author:
simon04
Message:

see #12554 - Allow to ignore keys/tags from recent tags

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r9930 r9940  
    1919import org.openstreetmap.josm.data.osm.RelationData;
    2020import org.openstreetmap.josm.data.osm.RelationMember;
     21import org.openstreetmap.josm.data.osm.Tag;
    2122import org.openstreetmap.josm.data.osm.User;
    2223import org.openstreetmap.josm.data.osm.Way;
     
    427428        assertEquals("foo1 || (bar1 && bar2 && (baz1 ^ baz2)) || foo2", c4.toString());
    428429    }
     430
     431    /**
     432     * Tests {@code buildSearchStringForTag}.
     433     * @throws ParseError if an error has been encountered while compiling
     434     */
     435    @Test
     436    public void testBuildSearchStringForTag() throws ParseError {
     437        final Tag tag1 = new Tag("foo=", "bar\"");
     438        final Tag tag2 = new Tag("foo=", "=bar");
     439        final String search1 = SearchCompiler.buildSearchStringForTag(tag1.getKey(), tag1.getValue());
     440        assertEquals("\"foo=\"=\"bar\\\"\"", search1);
     441        assertTrue(SearchCompiler.compile(search1).match(tag1));
     442        assertFalse(SearchCompiler.compile(search1).match(tag2));
     443        final String search2 = SearchCompiler.buildSearchStringForTag(tag1.getKey(), "");
     444        assertEquals("\"foo=\"=*", search2);
     445        assertTrue(SearchCompiler.compile(search2).match(tag1));
     446        assertTrue(SearchCompiler.compile(search2).match(tag2));
     447    }
    429448}
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollectionTest.java

    r9939 r9940  
    1212import org.junit.Test;
    1313import org.openstreetmap.josm.JOSMFixture;
     14import org.openstreetmap.josm.actions.search.SearchAction;
     15import org.openstreetmap.josm.actions.search.SearchCompiler;
    1416import org.openstreetmap.josm.data.osm.Tag;
    1517import org.openstreetmap.josm.data.preferences.CollectionProperty;
     
    3032    /**
    3133     * Performs various tests on a {@link RecentTagCollection}.
    32       */
     34     *
     35     * @throws SearchCompiler.ParseError if an error has been encountered while compiling
     36     */
    3337    @Test
    34     public void test() {
     38    public void test() throws SearchCompiler.ParseError {
    3539        final RecentTagCollection recentTags = new RecentTagCollection(2);
    3640        assertTrue(recentTags.isEmpty());
     
    5559        assertEquals(Collections.singletonList(new Tag("key=", "=value")), recentTags.toList());
    5660
     61        recentTags.add(foo);
     62        recentTags.add(bar);
     63        recentTags.add(baz);
     64        final SearchAction.SearchSetting searchSetting = new SearchAction.SearchSetting();
     65        recentTags.ignoreTag(baz, searchSetting);
     66        recentTags.ignoreTag(new Tag("something", "else"), searchSetting);
     67        assertEquals("\"name\"=\"baz\" OR \"something\"=\"else\"", searchSetting.text);
     68        assertEquals(Collections.singletonList(bar), recentTags.toList());
     69        recentTags.add(baz);
     70        assertEquals(Collections.singletonList(bar), recentTags.toList());
     71        searchSetting.text = "";
     72        recentTags.setTagsToIgnore(searchSetting);
     73        assertEquals(Collections.singletonList(bar), recentTags.toList());
     74        recentTags.add(baz);
     75        assertEquals(Arrays.asList(bar, baz), recentTags.toList());
     76        recentTags.ignoreTag(new Tag("name", /*all values */""), searchSetting);
     77        assertEquals(Collections.emptyList(), recentTags.toList());
     78
    5779    }
    5880}
Note: See TracChangeset for help on using the changeset viewer.