Ignore:
Timestamp:
2018-03-18T23:36:36+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #16104 - better support of space characters in values for tags copy/paste

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/TextTagParserTest.java

    r10758 r13541  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.junit.Assert.assertEquals;
    35
    46import java.util.Collections;
     
    68import java.util.Map;
    79
    8 import org.junit.Assert;
    910import org.junit.Rule;
    1011import org.junit.Test;
     
    3233        s = "\"2 3 4\"";
    3334        s1 = "2 3 4";
    34         Assert.assertEquals(s1, TextTagParser.unescape(s));
     35        assertEquals(s1, TextTagParser.unescape(s));
    3536
    3637        s = "\"2 \\\"3\\\" 4\"";
    3738        s1 = "2 \"3\" 4";
    38         Assert.assertEquals(s1, TextTagParser.unescape(s));
     39        assertEquals(s1, TextTagParser.unescape(s));
    3940
    4041        s = "\"2 3 ===4===\"";
    4142        s1 = "2 3 ===4===";
    42         Assert.assertEquals(s1, TextTagParser.unescape(s));
     43        assertEquals(s1, TextTagParser.unescape(s));
    4344
    4445        s = "\"2 3 \\\\\\\\===4===\"";
    4546        s1 = "2 3 \\\\===4===";
    46         Assert.assertEquals(s1, TextTagParser.unescape(s));
     47        assertEquals(s1, TextTagParser.unescape(s));
    4748    }
    4849
     
    5758        } };
    5859        Map<String, String> tags = TextTagParser.readTagsFromText(txt);
    59         Assert.assertEquals(correctTags, tags);
     60        assertEquals(correctTags, tags);
    6061    }
    6162
     
    7172        } };
    7273        Map<String, String> tags = TextTagParser.readTagsFromText(txt);
    73         Assert.assertEquals(correctTags, tags);
     74        assertEquals(correctTags, tags);
    7475    }
    7576
     
    8485        correctTags = new HashMap<String, String>() { { put("a", "1"); put("b", "2 3 4"); } };
    8586        tags = TextTagParser.readTagsFromText(txt);
    86         Assert.assertEquals(correctTags, tags);
     87        assertEquals(correctTags, tags);
    8788
    8889        txt = "\"a\"  :     \"1 1 1\", \"b2\"  :\"2 \\\"3 qwe\\\" 4\"";
    8990        correctTags = new HashMap<String, String>() { { put("a", "1 1 1"); put("b2", "2 \"3 qwe\" 4"); } };
    9091        tags = TextTagParser.readTagsFromText(txt);
    91         Assert.assertEquals(correctTags, tags);
     92        assertEquals(correctTags, tags);
    9293
    9394        txt = " \"aыыы\"   :    \"val\\\"\\\"\\\"ue1\"";
    9495        correctTags = new HashMap<String, String>() { { put("aыыы", "val\"\"\"ue1"); } };
    9596        tags = TextTagParser.readTagsFromText(txt);
    96         Assert.assertEquals(correctTags, tags);
     97        assertEquals(correctTags, tags);
    9798    }
    9899
     
    107108        } };
    108109        Map<String, String> tags = TextTagParser.readTagsFromText(txt);
    109         Assert.assertEquals(correctTags, tags);
     110        assertEquals(correctTags, tags);
    110111    }
    111112
     
    117118        String txt = "a=2 b=3 4";
    118119        Map<String, String> tags = TextTagParser.readTagsFromText(txt);
    119         Assert.assertEquals(Collections.EMPTY_MAP, tags);
     120        assertEquals(Collections.EMPTY_MAP, tags);
    120121    }
    121122
     
    125126    @Test
    126127    public void testTab() {
    127         Assert.assertEquals(TextTagParser.readTagsFromText("shop\tjewelry"), Collections.singletonMap("shop", "jewelry"));
    128         Assert.assertEquals(TextTagParser.readTagsFromText("!shop\tjewelry"), Collections.singletonMap("shop", "jewelry"));
    129         Assert.assertEquals(TextTagParser.readTagsFromText("!!!shop\tjewelry"), Collections.singletonMap("shop", "jewelry"));
    130         Assert.assertEquals(TextTagParser.readTagsFromText("shop\t\t\tjewelry"), Collections.singletonMap("shop", "jewelry"));
     128        assertEquals(Collections.singletonMap("shop", "jewelry"), TextTagParser.readTagsFromText("shop\tjewelry"));
     129        assertEquals(Collections.singletonMap("shop", "jewelry"), TextTagParser.readTagsFromText("!shop\tjewelry"));
     130        assertEquals(Collections.singletonMap("shop", "jewelry"), TextTagParser.readTagsFromText("!!!shop\tjewelry"));
     131        assertEquals(Collections.singletonMap("shop", "jewelry"), TextTagParser.readTagsFromText("shop\t\t\tjewelry"));
     132    }
     133
     134    /**
     135     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/16104">#16104</a>
     136     */
     137    @Test
     138    public void testTicket16104() {
     139        Map<String, String> expected = new HashMap<>();
     140        expected.put("boundary", "national_park");
     141        expected.put("name", "Raet nasjonalpark");
     142        expected.put("naturbase:iid", "VV00003273");
     143        expected.put("naturbase:verneform", "NP");
     144        expected.put("operator", "Raet Nasjonalparkstyre");
     145        expected.put("protect_class", "2");
     146        expected.put("related_law", "https://lovdata.no/forskrift/2016-12-16-1632");
     147        expected.put("short_name", "Raet");
     148        expected.put("start_date", "2016-12-16");
     149        expected.put("type", "boundary");
     150        expected.put("url", "http://faktaark.naturbase.no/?id=VV00003273");
     151        assertEquals(expected, TextTagParser.readTagsFromText(
     152                "boundary=national_park\n" +
     153                "name=Raet nasjonalpark\n" +
     154                "naturbase:iid=VV00003273\n" +
     155                "naturbase:verneform=NP\n" +
     156                "operator=Raet Nasjonalparkstyre\n" +
     157                "protect_class=2\n" +
     158                "related_law=https://lovdata.no/forskrift/2016-12-16-1632\n" +
     159                "short_name=Raet\n" +
     160                "start_date=2016-12-16\n" +
     161                "type=boundary\n" +
     162                "url=http://faktaark.naturbase.no/?id=VV00003273"));
    131163    }
    132164}
Note: See TracChangeset for help on using the changeset viewer.