source: josm/trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java@ 7937

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1package org.openstreetmap.josm.actions.search;
2
3import org.junit.Assert;
4import org.junit.Before;
5import org.junit.Test;
6import org.openstreetmap.josm.JOSMFixture;
7import org.openstreetmap.josm.data.osm.Node;
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9
10public class SearchCompilerTest {
11
12 /**
13 * Setup test.
14 */
15 @Before
16 public void setUp() {
17 JOSMFixture.createUnitTestFixture().init();
18 }
19
20 protected OsmPrimitive newPrimitive(String key, String value) {
21 final Node p = new Node();
22 p.put(key, value);
23 return p;
24 }
25
26 @Test
27 public void testAny() throws Exception {
28 final SearchCompiler.Match c = SearchCompiler.compile("foo", false, false);
29 Assert.assertTrue(c.match(newPrimitive("foobar", "true")));
30 Assert.assertTrue(c.match(newPrimitive("name", "hello-foo-xy")));
31 Assert.assertFalse(c.match(newPrimitive("name", "X")));
32 }
33
34 @Test
35 public void testEquals() throws Exception {
36 final SearchCompiler.Match c = SearchCompiler.compile("foo=bar", false, false);
37 Assert.assertFalse(c.match(newPrimitive("foobar", "true")));
38 Assert.assertTrue(c.match(newPrimitive("foo", "bar")));
39 Assert.assertFalse(c.match(newPrimitive("fooX", "bar")));
40 Assert.assertFalse(c.match(newPrimitive("foo", "barX")));
41 }
42
43 @Test
44 public void testCompare() throws Exception {
45 final SearchCompiler.Match c1 = SearchCompiler.compile("start_date>1950", false, false);
46 Assert.assertTrue(c1.match(newPrimitive("start_date", "1950-01-01")));
47 Assert.assertTrue(c1.match(newPrimitive("start_date", "1960")));
48 Assert.assertFalse(c1.match(newPrimitive("start_date", "1950")));
49 Assert.assertFalse(c1.match(newPrimitive("start_date", "1000")));
50 Assert.assertTrue(c1.match(newPrimitive("start_date", "101010")));
51 final SearchCompiler.Match c2 = SearchCompiler.compile("start_date<1960", false, false);
52 Assert.assertTrue(c2.match(newPrimitive("start_date", "1950-01-01")));
53 Assert.assertFalse(c2.match(newPrimitive("start_date", "1960")));
54 Assert.assertTrue(c2.match(newPrimitive("start_date", "1950")));
55 Assert.assertTrue(c2.match(newPrimitive("start_date", "1000")));
56 Assert.assertTrue(c2.match(newPrimitive("start_date", "200")));
57 final SearchCompiler.Match c3 = SearchCompiler.compile("name<I", false, false);
58 Assert.assertTrue(c3.match(newPrimitive("name", "Alpha")));
59 Assert.assertFalse(c3.match(newPrimitive("name", "Sigma")));
60 final SearchCompiler.Match c4 = SearchCompiler.compile("\"start_date\"<1960", false, false);
61 Assert.assertTrue(c4.match(newPrimitive("start_date", "1950-01-01")));
62 Assert.assertFalse(c4.match(newPrimitive("start_date", "2000")));
63
64 }
65}
Note: See TracBrowser for help on using the repository browser.