1 /*
2 * Copyright (c) 2001-2017, Zoltan Farkas All Rights Reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Additionally licensed with:
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32 package org.spf4j.zel.vm;
33
34 import java.util.concurrent.ExecutionException;
35 import java.util.function.Predicate;
36 import org.junit.Assert;
37 import org.junit.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42 * @author zoly
43 */
44 public final class LikeTest {
45
46
47 private static final Logger LOG = LoggerFactory.getLogger(LikeTest.class);
48
49 @Test
50 public void test() throws CompileException, ExecutionException, InterruptedException {
51 Program prog = Program.compile("a like '.*bula.*'", "a");
52 LOG.debug("Program = {}", prog);
53 Boolean result = (Boolean) prog.execute("balabulan");
54 Assert.assertTrue(result);
55 }
56
57 @Test
58 public void test2() throws CompileException, ExecutionException, InterruptedException {
59 Program prog = Program.compile("a like '.*bula.*'", "a");
60 LOG.debug("Program = {}", prog);
61 Boolean result = (Boolean) prog.execute("crap");
62 Assert.assertFalse(result);
63 }
64
65 @Test
66 public void test3() throws CompileException, ExecutionException, InterruptedException {
67 Program prog = Program.compile("a case-insensitive like '.*bula.*'", "a");
68 LOG.debug("Program = {}", prog);
69 Boolean result = (Boolean) prog.execute("balaBULAn");
70 Assert.assertTrue(result);
71 }
72
73
74 @Test
75 public void test4() throws CompileException {
76 Predicate<Object> pred = Program.compilePredicate("a case-insensitive like '.*bula.*'", "a");
77 LOG.debug("Program = {}", pred);
78 Assert.assertTrue(pred.test("balaBULAn"));
79 }
80
81 }