Parser implements ParserConstants { public Boolean validate() { try { parse(); return result; } catch (Exception e) { return false; } } Parser(String rules, String field);  Parser(java.io.InputStream stream);  Parser(java.io.InputStream stream, String encoding);  Parser(java.io.Reader stream);  Parser(ParserTokenManager tm); Boolean validate(); final void parse(); final void expression(); final void queryTerm(); final boolean compareTerm(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(java.io.Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
@Test public void shouldRightValidateCompulsoryField() throws Exception { String rules = "обязательное"; assertTrue(new Parser(rules, "qwerty").validate()); assertFalse(new Parser(rules, "").validate()); }
@Test public void shouldRightValidateRussianField() throws Exception { String rules = "русский"; assertTrue(new Parser(rules, "йцукен").validate()); assertFalse(new Parser(rules, "qwerty").validate()); }
@Test public void shouldRightValidateAndTerms() throws Exception { String rules = "русский && обязательное"; assertFalse(new Parser(rules, "").validate()); assertFalse(new Parser(rules, "qwerty").validate()); assertTrue(new Parser(rules, "йцукен").validate()); }
@Test public void shouldRightValidateValue() throws Exception { String rules = "значение > 80"; assertFalse(new Parser(rules, "5").validate()); assertFalse(new Parser(rules, "80").validate()); assertTrue(new Parser(rules, "100").validate()); }
@Test public void shouldRightValidateLength() throws Exception { String rules = "русский && длина > 4"; assertFalse(new Parser(rules, "ы").validate()); assertFalse(new Parser(rules, "dssdffs").validate()); assertTrue(new Parser(rules, "ываыавыа").validate()); }
@Test public void shouldRightValidateEmail() throws Exception { String rules = "email"; assertTrue(new Parser(rules, "test2@mail.ru").validate()); assertFalse(new Parser(rules, "ы").validate()); }