<commit_before>extern crate ra_syntax;
#[macro_use]
extern crate test_utils;
extern crate walkdir;

use std::{
    fmt::Write,
    fs,
    path::{Path, PathBuf, Component},
};

use ra_syntax::{
    utils::{check_fuzz_invariants, dump_tree},
    SourceFileNode,
};

#[test]
fn lexer_tests() {
    dir_tests(&["lexer"], |text, _| {
        let tokens = ra_syntax::tokenize(text);
        dump_tokens(&tokens, text)
    })
}

#[test]
fn parser_tests() {
    dir_tests(&["parser/inline/ok", "parser/ok"], |text, path| {
        let file = SourceFileNode::parse(text);
        let errors = file.errors();
        assert_eq!(
            &*errors,
            &[] as &[ra_syntax::SyntaxError],
            "There should be no errors in the file {:?}",
            path.display()
        );
        dump_tree(file.syntax())
    });
    dir_tests(&["parser/err", "parser/inline/err"], |text, path| {
        let file = SourceFileNode::parse(text);
        let errors = file.errors();
        assert_ne!(
            &*errors,
            &[] as &[ra_syntax::SyntaxError],
            "There should be errors in the file {:?}",
            path.display()
        );
        dump_tree(file.syntax())
    });
}

#[test]
fn parser_fuzz_tests() {
    for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
        check_fuzz_invariants(&text)
    }
}

/// Test that Rust-analyzer can parse and validate the rust-analyser
/// TODO: Use this as a benchmark
#[test]
fn self_hosting_parsing() {
    use std::ffi::OsStr;
    let dir = project_dir().join("crates");
    let mut count = 0;
    for entry in walkdir::WalkDir::new(dir)
        .into_iter()
        .filter_entry(|entry| {
            !entry
                .path()
                .components()
                // TODO: this more neatly
                .any(|component| {
                    // Get all files which are not in the crates/ra_syntax/tests/data folder
                    component == Component::Normal(OsStr::new("data"))
                })
        })
        .map(|e| e.unwrap())<commit_msg>Remove TODO on self_hosting_parsing<commit_after>extern crate ra_syntax;
#[macro_use]
extern crate test_utils;
extern crate walkdir;

use std::{
    fmt::Write,
    fs,
    path::{Path, PathBuf, Component},
};

use ra_syntax::{
    utils::{check_fuzz_invariants, dump_tree},
    SourceFileNode,
};

#[test]
fn lexer_tests() {
    dir_tests(&["lexer"], |text, _| {
        let tokens = ra_syntax::tokenize(text);
        dump_tokens(&tokens, text)
    })
}

#[test]
fn parser_tests() {
    dir_tests(&["parser/inline/ok", "parser/ok"], |text, path| {
        let file = SourceFileNode::parse(text);
        let errors = file.errors();
        assert_eq!(
            &*errors,
            &[] as &[ra_syntax::SyntaxError],
            "There should be no errors in the file {:?}",
            path.display()
        );
        dump_tree(file.syntax())
    });
    dir_tests(&["parser/err", "parser/inline/err"], |text, path| {
        let file = SourceFileNode::parse(text);
        let errors = file.errors();
        assert_ne!(
            &*errors,
            &[] as &[ra_syntax::SyntaxError],
            "There should be errors in the file {:?}",
            path.display()
        );
        dump_tree(file.syntax())
    });
}

#[test]
fn parser_fuzz_tests() {
    for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
        check_fuzz_invariants(&text)
    }
}

/// Test that Rust-analyzer can parse and validate the rust-analyser
/// TODO: Use this as a benchmark
#[test]
fn self_hosting_parsing() {
    use std::ffi::OsStr;
    let dir = project_dir().join("crates");
    let mut count = 0;
    for entry in walkdir::WalkDir::new(dir)
        .into_iter()
        .filter_entry(|entry| {
            !entry.path().components().any(|component| {
                // Get all files which are not in the crates/ra_syntax/tests/data folder
                component == Component::Normal(OsStr::new("data"))
            })
        })
        .map(|e| e.unwrap())
{'fraction_non_alphanumeric': 0.1536361379995036, 'fraction_numerical': 0.0004964010920824026, 'mean_word_length': 2.255250403877221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1439619', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1267, 'n_words': 285}