Changeset 9930 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r9701 r9930 453 453 @Override 454 454 public String toString() { 455 return lhs + " && " + rhs; 455 return (lhs instanceof BinaryMatch && !(lhs instanceof And) ? "(" + lhs + ")" : lhs) + " && " 456 + (rhs instanceof BinaryMatch && !(rhs instanceof And) ? "(" + rhs + ")" : rhs); 456 457 } 457 458 } … … 477 478 @Override 478 479 public String toString() { 479 return lhs + " || " + rhs; 480 return (lhs instanceof BinaryMatch && !(lhs instanceof Or) ? "(" + lhs + ")" : lhs) + " || " 481 + (rhs instanceof BinaryMatch && !(rhs instanceof Or) ? "(" + rhs + ")" : rhs); 480 482 } 481 483 } … … 501 503 @Override 502 504 public String toString() { 503 return lhs + " ^ " + rhs; 505 return (lhs instanceof BinaryMatch && !(lhs instanceof Xor) ? "(" + lhs + ")" : lhs) + " ^ " 506 + (rhs instanceof BinaryMatch && !(rhs instanceof Xor) ? "(" + rhs + ")" : rhs); 504 507 } 505 508 } -
trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java
r9701 r9930 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertThat;7 6 import static org.junit.Assert.assertTrue; 8 7 9 import org.hamcrest.CoreMatchers;10 8 import org.junit.Before; 11 9 import org.junit.Test; … … 97 95 assertTrue(c.match(newPrimitive("name", "hello-foo-xy"))); 98 96 assertFalse(c.match(newPrimitive("name", "X"))); 97 assertEquals("foo", c.toString()); 99 98 } 100 99 … … 110 109 assertFalse(c.match(newPrimitive("fooX", "bar"))); 111 110 assertFalse(c.match(newPrimitive("foo", "barX"))); 111 assertEquals("foo=bar", c.toString()); 112 112 } 113 113 … … 186 186 @Test 187 187 public void testNthParseNegative() throws ParseError { 188 assert That(SearchCompiler.compile("nth:-1").toString(), CoreMatchers.is("Nth{nth=-1, modulo=false}"));188 assertEquals("Nth{nth=-1, modulo=false}", SearchCompiler.compile("nth:-1").toString()); 189 189 } 190 190 … … 408 408 assertFalse(search.match(n1)); 409 409 } 410 411 /** 412 * Tests the implementation of the Boolean logic. 413 * @throws ParseError if an error has been encountered while compiling 414 */ 415 @Test 416 public void testBooleanLogic() throws ParseError { 417 final SearchCompiler.Match c1 = SearchCompiler.compile("foo AND bar AND baz"); 418 assertTrue(c1.match(newPrimitive("foobar", "baz"))); 419 assertEquals("foo && bar && baz", c1.toString()); 420 final SearchCompiler.Match c2 = SearchCompiler.compile("foo AND (bar OR baz)"); 421 assertTrue(c2.match(newPrimitive("foobar", "yes"))); 422 assertTrue(c2.match(newPrimitive("foobaz", "yes"))); 423 assertEquals("foo && (bar || baz)", c2.toString()); 424 final SearchCompiler.Match c3 = SearchCompiler.compile("foo OR (bar baz)"); 425 assertEquals("foo || (bar && baz)", c3.toString()); 426 final SearchCompiler.Match c4 = SearchCompiler.compile("foo1 OR (bar1 bar2 baz1 XOR baz2) OR foo2"); 427 assertEquals("foo1 || (bar1 && bar2 && (baz1 ^ baz2)) || foo2", c4.toString()); 428 } 410 429 }
Note:
See TracChangeset
for help on using the changeset viewer.