<commit_before>package oap.io;

import oap.testng.AbstractTest;
import oap.testng.Env;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.function.Consumer;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static oap.testng.Env.tmpPath;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertEqualsNoOrder;

/**
 * Created by <NAME> on 14.01.2016.
 */
public class FileWalkerTest extends AbstractTest {

    @BeforeMethod
    @Override
    public void beforeMethod() throws Exception {
        super.beforeMethod();

        Files.writeString( Env.tmp( "/wildcard/1.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/3.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/33.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/w1/4.txt" ), "1" );
    }

    @Test
    public void walkFileTreeBasePathNotFound() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( Paths.get( "/aaa" ), "*.txt" ).walkFileTree( visitor );

        assertThat( visitor.files ).isEmpty();
    }

    @Test
    public void walkFileTreeStaticPath() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3.txt" ).walkFileTree( visitor );

        assertEquals( visitor.files, singletonList( tmpPath( "/wildcard/w2/3.txt" ) ) );
    }

    @Test
    public void walkFileTreeStaticPathNotFound() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "unknown/3.txt" ).walkFileTree( visitor );

        assertEquals( visitor.files, emptyList() );
    }

    @Test
    public void walkFileTreeAny() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2\\*" ).walkFileTree( visitor );

        assertEqualsNoOrder( visitor.files.toArray(), new Path[] {
            tmpPath( "/wildcard/w2/33.txt" ), tmpPath( "/wildcard/w2/w1" ), tmpPath( "/wildcard/w2/3.txt" )
        } );
    }

    @Test
    public void walkFileTreeAny2() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "*/*.txt" ).walkFileTree( visitor );

        assertEqualsNoOrder( visitor.files.toArray(), new Path[] {
            tmpPath( "/wildcard/w2/33.txt" ), tmpPath( "/wildcard/w2/3.txt" )
        } );
    }

    @Test
    public void walkFileTreeFilePattern() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3*.txt" ).walkFileTree( visitor );

        assertEquals( visitor.files, asList(
            tmpPath( "/wildcard/w2/3.txt" ), tmpPath( "/wildcard/w2/33.txt" )
        ) );
    }

    @Test
    public void walkFileTreeFilePatternCache() throws Exception {
        final FileWalkerCache fwc = new FileWalkerCache();

        final MockVisitor visitor1 = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3*.txt", fwc ).walkFileTree( visitor1 );
        assertThat( visitor1.files ).containsOnly( tmpPath( "/wildcard/w2/3.txt" ), tmpPath( "/wildcard/w2/33.txt" ) );

        final MockVisitor visitor2 = new MockVisitor();<commit_msg>fix: tests<commit_after>package oap.io;

import oap.testng.AbstractTest;
import oap.testng.Env;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.function.Consumer;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static oap.testng.Env.tmpPath;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertEqualsNoOrder;

/**
 * Created by <NAME> on 14.01.2016.
 */
public class FileWalkerTest extends AbstractTest {

    @BeforeMethod
    @Override
    public void beforeMethod() throws Exception {
        super.beforeMethod();

        Files.writeString( Env.tmp( "/wildcard/1.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/3.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/33.txt" ), "1" );
        Files.writeString( Env.tmp( "/wildcard/w2/w1/4.txt" ), "1" );
    }

    @Test
    public void walkFileTreeBasePathNotFound() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( Paths.get( "/aaa" ), "*.txt" ).walkFileTree( visitor );

        assertThat( visitor.files ).isEmpty();
    }

    @Test
    public void walkFileTreeStaticPath() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3.txt" ).walkFileTree( visitor );

        assertEquals( visitor.files, singletonList( tmpPath( "/wildcard/w2/3.txt" ) ) );
    }

    @Test
    public void walkFileTreeStaticPathNotFound() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "unknown/3.txt" ).walkFileTree( visitor );

        assertEquals( visitor.files, emptyList() );
    }

    @Test
    public void walkFileTreeAny() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2\\*" ).walkFileTree( visitor );

        assertEqualsNoOrder( visitor.files.toArray(), new Path[] {
            tmpPath( "/wildcard/w2/33.txt" ), tmpPath( "/wildcard/w2/w1" ), tmpPath( "/wildcard/w2/3.txt" )
        } );
    }

    @Test
    public void walkFileTreeAny2() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "*/*.txt" ).walkFileTree( visitor );

        assertEqualsNoOrder( visitor.files.toArray(), new Path[] {
            tmpPath( "/wildcard/w2/33.txt" ), tmpPath( "/wildcard/w2/3.txt" )
        } );
    }

    @Test
    public void walkFileTreeFilePattern() throws Exception {
        final MockVisitor visitor = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3*.txt" ).walkFileTree( visitor );

        assertThat( visitor.files)
            .containsOnly( tmpPath( "/wildcard/w2/3.txt" ), tmpPath( "/wildcard/w2/33.txt" ) );
    }

    @Test
    public void walkFileTreeFilePatternCache() throws Exception {
        final FileWalkerCache fwc = new FileWalkerCache();

        final MockVisitor visitor1 = new MockVisitor();
        new FileWalker( tmpPath( "wildcard" ), "w2/3*.txt", fwc ).walkFileTree( visitor1 );
        assertThat( visitor1.files ).containsOnly( tmpPath( "/wildcard/w2/3.txt" ), tmpPath( "/wildcard/w2/33.txt" ) );

        final MockVisitor visitor2 = new MockVisitor();
{'fraction_non_alphanumeric': 0.1341875528020276, 'fraction_numerical': 0.016333427203604617, 'mean_word_length': 3.077497129735936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7243902', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2125, 'n_words': 506}