aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/text/Ascii7BitMatcherTestCase.java
blob: 4c1ef3232ff73136df9cf9096e904e7dad2a9f9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;

public class Ascii7BitMatcherTestCase {
    @Test
    public void testThatListedCharsAreLegal() {
        assertTrue(new Ascii7BitMatcher("a").matches("aaaa"));
        assertTrue(new Ascii7BitMatcher("ab").matches("abbbbbbbbb"));
        assertTrue(new Ascii7BitMatcher("ab").matches("bbbbbbbbbba"));
        assertTrue(new Ascii7BitMatcher("1").matches("1"));
    }
    @Test
    public void requireThatNotListedCharsFail() {
        assertFalse(new Ascii7BitMatcher("a").matches("b"));
    }

    @Test
    public void testThatLegalFirstAndRestPass() {
        assertTrue(new Ascii7BitMatcher("a", "").matches("a"));
        assertTrue(new Ascii7BitMatcher("a", "b").matches("abbbbbbbbb"));
        assertTrue(new Ascii7BitMatcher("abc", "0123").matches("a123120"));
    }
    @Test
    public void requireThatIllegalFirstOrSecondFail() {
        assertFalse(new Ascii7BitMatcher("a", "").matches("aa"));
        assertFalse(new Ascii7BitMatcher("a", "b").matches("aa"));
        assertFalse(new Ascii7BitMatcher("", "a").matches("a"));
        assertFalse(new Ascii7BitMatcher("a", "b").matches("bb"));
        assertFalse(new Ascii7BitMatcher("a", "b").matches("abbbbbx"));
    }
    @Test
    public void requireThatNonAsciiFailConstruction() {
        try {
            new Ascii7BitMatcher("aæb");
            Assert.fail("'æ' should not be allowed");
        } catch (IllegalArgumentException e) {
            assertEquals("Char 'æ' at position 1 is not valid ascii 7 bit char", e.getMessage());
        }
    }
}