@Test
    public void testParseTerminals() throws ParseException {
        // Test number values.
        assertParse("true");
        assertParse("music.hmm == 123");
        assertParse("music.hmm == 123.53", "music.hmm == +123.53");
        assertParse("music.hmm == -123.5");
        assertParse("music.hmm == 2.3412352E8", "music.hmm == 234123.52e3");
        assertParse("music.hmm == -234.12352", "music.hmm == -234123.52E-3");
        assertParse("music.hmm < aaa");

        // Test string values.
        assertParse("music.hmm == \"test\"");

        // Test map and struct stuff.
        assertParse("music.hmm{test} == \"test\"");
        assertParse("music.hmm{test}.foo[3].key == \"test\"");

        // Test whitespaces.
        assertParse("music.hmm == \"te st \"");
        assertParse("music.hmm == \"test\"", " \t music.hmm\t==  \t \"test\"\t");

        // Test escaping.
        assertParse("music.hmm == \"tab\\ttest\"");
        assertParse("music.hmm == \"tab\\u0666test\"", "music.hmm == \"tab\\u0666test\"");
        assertParse("music.hmm == \"tabcomplete\"", "music.hmm == \"tabcomplete\"");
        assertParse("music.hmm == \"tabysf\"", "music.hmm == \"tab\\ysf\""); // excessive escapes are removed
        assertParse("music.h == \"\\ttx48 \\n\"", "music.h == \"\\tt\\x48 \\n\"");

        // Test illegal operator.
        assertParseError("music.hmm <> 12", "Exception parsing document selector 'music.hmm <> 12': Encountered \" \">\" \">\"\" at line 1, column 12.");

        // Test comparison operators.
        assertParse("music.hmm >= 123");
        assertParse("music.hmm > 123");
        assertParse("music.hmm <= 123");
        assertParse("music.hmm < 123");
        assertParse("music.hmm != 123");

        // Test defined.
        assertParse("music.hmm");

        // Test boolean expressions.
        assertParse("true", "TRUE");
        assertParse("false", "FALSE");
        assertParse("true", "true");
        assertParse("false", "false");
        assertParse("false", "faLSe");

        // Test document types.
        assertParse("mytype");

        // Test document id.
        assertParse("id == \"id:ns:mytype::mytest\"");
        assertParse("id.namespace == \"myspace\"");
        assertParse("id.scheme == \"id\"");
        assertParse("id.type == \"mytype\"");
        assertParse("id.user == 1234");
        assertParse("id.bucket == 8388608", "id.bucket == 0x800000");
        assertParse("id.bucket == 8429568", "id.bucket == 0x80a000");
        assertParse("id.bucket == -9223372036854775566",
                    "id.bucket == 0x80000000000000f2");
        assertParse("id.group == \"yahoo.com\"");
        assertParse("id.specific == \"mypart\"");

        // Test other operators.
        assertParse("id.scheme = \"*doc\"");
        assertParse("music.artist =~ \"(john|barry|shrek)\"");

        // Verify functions.
        assertParse("id.hash() == 124");
        assertParse("id.specific.hash() == 124");
        assertParse("music.artist.lowercase() == \"chang\"");
        assertParse("music.artist.lowercase().hash() == 124");
        assertParse("music.version() == 8");
        assertParse("music == 8"); // will evaluate to false

        // Value grouping.
        assertParse("(123) < (200)", "(123) < (200)");
        assertParse("(\"hmm\") < (id.scheme)", "(\"hmm\") < (id.scheme)");

        // Arithmetics.
        assertParse("(1 + 2) > 1");
        assertParse("1 + 2 > 1", "1 + 2 > 1");
        assertParse("(1 - 2) > 1");
        assertParse("(1 * 2) > 1");
        assertParse("(1 / 2) > 1");
        assertParse("(1 % 2) > 1");
        assertParse("((1 + 2) * (4 - 2)) == 1");
        assertParse("(1 + 2) * (4 - 2) == 1", "(1 + 2) * (4 - 2) == 1");
        assertParse("((23 + 643) / (34 % 10)) > 34");
        assertParse("23 + 643 / 34 % 10 > 34", "23 + 643 / 34 % 10 > 34");
    }
@author Simon Thoresen Hult
@author bratseth
document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java