001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.boolex;
015
016import junit.framework.TestCase;
017import ch.qos.logback.core.Context;
018import ch.qos.logback.core.ContextBase;
019
020public class MatcherTest extends TestCase {
021
022    Context context;
023    Matcher matcher;
024
025    public void setUp() throws Exception {
026        context = new ContextBase();
027        matcher = new Matcher();
028        matcher.setContext(context);
029        matcher.setName("testMatcher");
030        super.setUp();
031    }
032
033    public void tearDown() throws Exception {
034        matcher = null;
035        super.tearDown();
036    }
037
038    public void testFullRegion() throws Exception {
039        matcher.setRegex(".*test.*");
040        matcher.start();
041        assertTrue(matcher.matches("test"));
042        assertTrue(matcher.matches("xxxxtest"));
043        assertTrue(matcher.matches("testxxxx"));
044        assertTrue(matcher.matches("xxxxtestxxxx"));
045    }
046
047    public void testPartRegion() throws Exception {
048        matcher.setRegex("test");
049        matcher.start();
050        assertTrue(matcher.matches("test"));
051        assertTrue(matcher.matches("xxxxtest"));
052        assertTrue(matcher.matches("testxxxx"));
053        assertTrue(matcher.matches("xxxxtestxxxx"));
054    }
055
056    public void testCaseInsensitive() throws Exception {
057        matcher.setRegex("test");
058        matcher.setCaseSensitive(false);
059        matcher.start();
060
061        assertTrue(matcher.matches("TEST"));
062        assertTrue(matcher.matches("tEst"));
063        assertTrue(matcher.matches("tESt"));
064        assertTrue(matcher.matches("TesT"));
065    }
066
067    public void testCaseSensitive() throws Exception {
068        matcher.setRegex("test");
069        matcher.setCaseSensitive(true);
070        matcher.start();
071
072        assertFalse(matcher.matches("TEST"));
073        assertFalse(matcher.matches("tEst"));
074        assertFalse(matcher.matches("tESt"));
075        assertFalse(matcher.matches("TesT"));
076    }
077}