<commit_before>/*
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.api.internal.file.pattern;

import com.google.common.base.Joiner;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

public class PatternMatcherFactoryTest {
    private PatternMatcher matcher;

    @Test public void testEmpty() {
        matcher = PatternMatcherFactory.getPatternMatcher(true, true, "");
        assertThat(matcher, matchesFile());
        assertThat(matcher, not(matchesFile("a")));
        assertThat(matcher, not(matchesFile("a", "b")));
    }

    @Test public void testSlashDirection() {<commit_msg>Add unit tests<commit_after>/*
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.api.internal.file.pattern;

import com.google.common.base.Joiner;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;

import java.util.LinkedHashSet;
import java.util.Set;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

public class PatternMatcherFactoryTest {
    private PatternMatcher matcher;

    @Test public void testNoStackOverflowForManyPatterns() {
        // The only reason for this unit test is to verify that no StackOverflowException is being thrown when
        // many patterns are passed to getPatternsMatcher. See https://github.com/gradle/gradle/issues/10329
        Set<String> manyPatterns =  new LinkedHashSet<String>();
        for (int i = 0; i < 5000; i++) {
            manyPatterns.add("some/package/Some" + i + "ClassName.class");
            manyPatterns.add("some/package/Some" + i + "ClassName.java");
            manyPatterns.add("some/package/Some" + i + "ClassName.h");
            manyPatterns.add("some/package/Some" + i + "ClassName$*.class");
            manyPatterns.add("some/package/Some" + i + "ClassName$*.java");
            manyPatterns.add("some/package/Some" + i + "ClassName$*.h");
        }
        matcher = PatternMatcherFactory.getPatternsMatcher(true, true, manyPatterns);
        assertThat(matcher, not(matchesFile("some", "package", "SomeClassName.java")));
        assertThat(matcher, matchesFile("some", "package", "Some123ClassName.java"));
    }

    @Test public void testManyOr() {
        Set<String> manyPatterns =  new LinkedHashSet<String>();
        manyPatterns.add("some/package/SomeClassName.class");
        manyPatterns.add("some/package/SomeClassName.java");
        manyPatterns.add("some/package/SomeClassName.h");
        manyPatterns.add("some/package/SomeClassName$*.class");
        manyPatterns.add("some/package/SomeClassName$*.java");
        manyPatterns.add("some/package/SomeClassName$*.h");
        matcher = PatternMatcherFactory.getPatternsMatcher(true, true, manyPatterns);
        assertThat(matcher, not(matchesFile()));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName.java"));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName.class"));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName.h"));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName$*.java"));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName$*.class"));
        assertThat(matcher, matchesFile("some", "package", "SomeClassName$*.h"));
        assertThat(matcher, not(matchesFile("a")));
    }

    @Test public void testEmpty() {
        matcher = PatternMatcherFactory.getPatternMatcher(true, true, "");
        assertThat(matcher, matchesFile());
        assertThat(matcher, not(matchesFile("a")));
        assertThat(matcher, not(matchesFile("a", "b")));
    }

    @Test public void testSlashDirection() {
{'fraction_non_alphanumeric': 0.12112288967412642, 'fraction_numerical': 0.005692972124067531, 'mean_word_length': 3.9084778420038537, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6894691', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1397, 'n_words': 384}