Skip to content

Commit

Permalink
challenge(formatter): sloppy mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-teles committed Nov 20, 2023
1 parent e60c49b commit db4d812
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 152 deletions.
22 changes: 20 additions & 2 deletions crates/biome_js_formatter/tests/prettier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, path::Path};
use biome_formatter::IndentStyle;
use biome_formatter_test::test_prettier_snapshot::{PrettierSnapshot, PrettierTestFile};
use biome_js_formatter::context::JsFormatOptions;
use biome_js_syntax::JsFileSource;
use biome_js_syntax::{JsFileSource, ModuleKind};

mod language;

Expand All @@ -18,7 +18,7 @@ fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) {
));

let test_file = PrettierTestFile::new(input, root_path);
let source_type = {
let mut source_type = {
// Prettier testing suite uses JSX tags inside JS files.
// As there's no way to know in advance which files have JSX syntax, we
// change the source type only here
Expand All @@ -31,12 +31,30 @@ fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) {
}
};

if is_sloppy_mode_case(test_file.relative_file_name()) {
source_type = source_type.with_module_kind(ModuleKind::Script)
}

let options = JsFormatOptions::new(source_type)
.with_indent_style(IndentStyle::Space)
.with_indent_width(2.into());

let language = language::JsTestFormatLanguage::new(source_type);

let snapshot = PrettierSnapshot::new(test_file, language, options);

snapshot.test()
}

fn is_sloppy_mode_case(file_name: &str) -> bool {
let test_cases_paths = [
"js/with",
"js/sloppy-mode",
"js/identifier/parentheses/const.js",
];

test_cases_paths
.map(Path::new)
.iter()
.any(|path| path.to_str().is_some_and(|path| file_name.contains(path)))
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ while (false) function foo(){}
```
function-declaration-in-while.js:1:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× In strict mode code, functions can only be declared at top level or inside a block
× In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if or labelled statement
> 1 │ while (false) function foo(){}
│ ^^^^^^^^^^^^^^^^
Expand Down

This file was deleted.

0 comments on commit db4d812

Please sign in to comment.