2021-08-23 15:42:13 +03:00
|
|
|
//! Tests ported from https://github.com/thysultan/stylis.js
|
|
|
|
//!
|
|
|
|
//! License is MIT, which is original license at the time of copying.
|
|
|
|
//! Original test authors have copyright for their work.
|
2022-03-03 19:35:41 +03:00
|
|
|
#![deny(warnings)]
|
2022-02-20 13:44:21 +03:00
|
|
|
#![allow(clippy::needless_update)]
|
2021-08-23 15:42:13 +03:00
|
|
|
|
2021-12-07 15:04:54 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-07-20 06:12:40 +03:00
|
|
|
use preset_env_base::query::{Query, Targets};
|
2022-03-09 06:18:49 +03:00
|
|
|
use swc_css_ast::Stylesheet;
|
2021-08-23 15:42:13 +03:00
|
|
|
use swc_css_codegen::{
|
|
|
|
writer::basic::{BasicCssWriter, BasicCssWriterConfig},
|
|
|
|
CodegenConfig, Emit,
|
|
|
|
};
|
|
|
|
use swc_css_parser::{parse_file, parser::ParserConfig};
|
2022-07-20 06:12:40 +03:00
|
|
|
use swc_css_prefixer::{options::Options, prefixer};
|
2021-08-23 15:42:13 +03:00
|
|
|
use swc_css_visit::VisitMutWith;
|
2021-12-07 15:04:54 +03:00
|
|
|
use testing::NormalizedOutput;
|
2021-08-23 15:42:13 +03:00
|
|
|
|
2022-07-20 06:12:40 +03:00
|
|
|
fn prefix(input: PathBuf, options: Options, suffix: Option<&str>) {
|
|
|
|
let parent = input.parent().unwrap();
|
|
|
|
let output = match suffix {
|
|
|
|
Some(suffix) => parent.join("output.".to_owned() + suffix + ".css"),
|
|
|
|
_ => parent.join("output.css"),
|
|
|
|
};
|
2021-12-07 15:04:54 +03:00
|
|
|
|
|
|
|
testing::run_test2(false, |cm, handler| {
|
|
|
|
//
|
|
|
|
let fm = cm.load_file(&input).unwrap();
|
|
|
|
let mut errors = vec![];
|
|
|
|
let mut ss: Stylesheet = parse_file(
|
|
|
|
&fm,
|
2023-10-10 14:42:20 +03:00
|
|
|
None,
|
2021-12-07 15:04:54 +03:00
|
|
|
ParserConfig {
|
|
|
|
allow_wrong_line_comments: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&mut errors,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
for err in errors {
|
|
|
|
err.to_diagnostics(&handler).emit();
|
|
|
|
}
|
|
|
|
|
2022-07-20 06:12:40 +03:00
|
|
|
ss.visit_mut_with(&mut prefixer(options));
|
2021-12-07 15:04:54 +03:00
|
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
{
|
2022-03-11 08:22:14 +03:00
|
|
|
let mut wr = BasicCssWriter::new(&mut s, None, BasicCssWriterConfig::default());
|
2021-12-07 15:04:54 +03:00
|
|
|
let mut gen =
|
2022-03-08 11:31:10 +03:00
|
|
|
swc_css_codegen::CodeGenerator::new(&mut wr, CodegenConfig { minify: false });
|
2021-12-07 15:04:54 +03:00
|
|
|
|
|
|
|
gen.emit(&ss).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
NormalizedOutput::from(s).compare_to_file(&output).unwrap();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|
2022-07-20 06:12:40 +03:00
|
|
|
|
|
|
|
#[testing::fixture("tests/fixture/**/input.css")]
|
|
|
|
fn test_without_env(input: PathBuf) {
|
|
|
|
prefix(input, Options::default(), None)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[testing::fixture("tests/fixture/**/input.css")]
|
|
|
|
fn test_with_env(input: PathBuf) {
|
|
|
|
prefix(
|
|
|
|
input,
|
|
|
|
Options {
|
|
|
|
env: Some(Targets::Query(Query::Single(String::from(
|
|
|
|
"defaults, not IE 11",
|
|
|
|
)))),
|
|
|
|
},
|
|
|
|
Some("defaults-not-ie-11"),
|
|
|
|
)
|
|
|
|
}
|