Skip to content

Commit b527e1f

Browse files
committed
use malva for testing
1 parent fab2fda commit b527e1f

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ serde_json = { version = "1.0", optional = true }
4242

4343
[dev-dependencies]
4444
dprint-development = "0.10.1"
45+
malva = "0.11.1"
4546
pretty_assertions = "1.3.0"
4647
serde_json = { version = "1.0" }

src/generation/generate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,7 +3025,7 @@ fn maybe_gen_tagged_tpl_with_external_formatter<'a>(node: &TaggedTpl<'a>, contex
30253025
for (i, quasi) in node.tpl.quasis.iter().enumerate() {
30263026
text.push(quasi.raw().to_string());
30273027
if i < expr_len {
3028-
text.push(format!("@dprint-placeholder-{}-id", i));
3028+
text.push(format!("dprint-placeholder-{}-id", i));
30293029
}
30303030
}
30313031

@@ -3039,7 +3039,7 @@ fn maybe_gen_tagged_tpl_with_external_formatter<'a>(node: &TaggedTpl<'a>, contex
30393039
items.push_signal(Signal::StartIndent);
30403040
for line in formatted_tpl.lines() {
30413041
let mut i = 0;
3042-
let re = regex::Regex::new("@dprint-placeholder-(\\d+)-id").unwrap();
3042+
let re = regex::Regex::new("dprint-placeholder-(\\d+)-id").unwrap();
30433043
re.captures_iter(line).for_each(|cap| {
30443044
let m = cap.get(0).unwrap();
30453045
let d = cap.get(1).unwrap().as_str().parse::<usize>().unwrap();

tests/spec_test.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,27 @@ use dprint_plugin_typescript::*;
99

1010
fn external_formatter(media_type: MediaType, text: String) -> Option<String> {
1111
assert_eq!(media_type, MediaType::Css);
12-
// Put each rule on a separate line.
13-
Some(
14-
text
15-
.split(';')
16-
.filter_map(|val| {
17-
let val = val.trim();
18-
if val.is_empty() {
19-
None
20-
} else {
21-
Some(format!("{};", val))
22-
}
23-
})
24-
.collect::<Vec<_>>()
25-
.join("\n"),
26-
)
12+
let Ok(text) = malva::format_text(&format!("a{{\n{}\n}}", text), malva::Syntax::Css, &malva::config::FormatOptions::default()) else {
13+
return None;
14+
};
15+
let mut buf = vec![];
16+
for (i, l) in text.lines().enumerate() {
17+
if i == 0 {
18+
continue;
19+
}
20+
if l.starts_with("}") {
21+
continue;
22+
}
23+
let mut chars = l.chars();
24+
// drop the first two chars
25+
chars.next();
26+
chars.next();
27+
buf.push(chars.as_str());
28+
}
29+
Some(buf.join("\n").to_string())
2730
}
2831

32+
2933
fn main() {
3034
//debug_here!();
3135
let global_config = GlobalConfiguration {

0 commit comments

Comments
 (0)