Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed Apr 27, 2024
1 parent 4e12d5d commit b711ea6
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/parser_test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct Arguments {

#[arg(short, long)]
mxml: bool,

#[arg(short, long)]
css: bool,
}

fn main() -> io::Result<()> {
Expand All @@ -23,7 +26,7 @@ fn main() -> io::Result<()> {
// Canonicalize path
// let source_path = std::path::Path::new(&source_path).canonicalize().unwrap().to_string_lossy().into_owned();

let source_path_ast_json = FlexPath::new_native(&source_path).change_extension(".ast.json").to_string_with_flex_separator();
let source_path_ast_json = FlexPath::new_native(&source_path).change_extension(".tree").to_string_with_flex_separator();
let source_path_diagnostics = FlexPath::new_native(&source_path).change_extension(".diag").to_string_with_flex_separator();
let source_content = fs::read_to_string(&source_path)?;
let compilation_unit = CompilationUnit::new(Some(source_path), source_content, &CompilerOptions::default());
Expand All @@ -32,6 +35,11 @@ fn main() -> io::Result<()> {
if arguments.file_log {
fs::write(&source_path_ast_json, serde_json::to_string_pretty(&document).unwrap())?;
}
} else if arguments.css {
let document = CssParserFacade(&compilation_unit, default()).parse_document();
if arguments.file_log {
fs::write(&source_path_ast_json, serde_json::to_string_pretty(&document).unwrap())?;
}
} else {
let program = ParserFacade(&compilation_unit, default()).parse_program();
if arguments.file_log {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion tests/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ To test parsing a program producing output to two files `.ast.json` and `.diag`,
cargo run --bin as3_parser_test -- --source-path tests/parser/Demo.as --file-log
```

For parsing MXML, pass the `--mxml` flag.
For parsing MXML, pass the `--mxml` flag.

For parsing CSS, pass the `--css` flag.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/parser/css/mediaQuery.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@media (application-dpi: 240) and (os-platform: "Windows"),,,,,,,,, {
.myStyleName1 {
fontSize: 30
}
}
Empty file.
92 changes: 92 additions & 0 deletions tests/parser/css/mediaQuery.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"location": "1:1-5:2",
"directives": [
{
"MediaQuery": {
"location": "1:1-5:2",
"conditions": [
{
"And": {
"location": "1:8-1:59",
"left": {
"ParenProperty": [
{
"location": "1:9-1:29",
"name": [
"applicationDpi",
"1:9-1:24"
],
"value": {
"Number": {
"location": "1:26-1:29",
"value": 240.0,
"unit": null
}
}
},
"1:8-1:30"
]
},
"right": {
"ParenProperty": [
{
"location": "1:36-1:58",
"name": [
"osPlatform",
"1:36-1:47"
],
"value": {
"String": {
"location": "1:49-1:58",
"value": "Windows"
}
}
},
"1:35-1:59"
]
}
}
}
],
"rules": [
{
"location": "2:5-4:6",
"selectors": [
{
"Base": {
"location": "2:5-2:18",
"namespace_prefix": null,
"element_name": null,
"conditions": [
{
"Class": [
"myStyleName1",
"2:5-2:18"
]
}
]
}
}
],
"properties": [
{
"location": "3:9-3:21",
"name": [
"fontSize",
"3:9-3:17"
],
"value": {
"Number": {
"location": "3:19-3:21",
"value": 30.0,
"unit": null
}
}
}
]
}
]
}
}
]
}
135 changes: 135 additions & 0 deletions tests/parser/css/selectors.ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"location": "1:1-7:2",
"directives": [
{
"Rule": {
"location": "1:1-3:2",
"selectors": [
{
"Combinator": {
"location": "1:1-1:34",
"left": {
"Base": {
"location": "1:1-1:25",
"namespace_prefix": null,
"element_name": null,
"conditions": [
{
"Class": [
"myStyleName1",
"1:1-1:14"
]
},
{
"Class": [
"anotherOne",
"1:14-1:25"
]
}
]
}
},
"right": {
"Base": {
"location": "1:26-1:34",
"namespace_prefix": [
"s",
"1:26-1:27"
],
"element_name": [
"VGroup",
"1:28-1:34"
],
"conditions": []
}
},
"combinator_type": "Descendant"
}
},
{
"Base": {
"location": "1:36-1:40",
"namespace_prefix": null,
"element_name": null,
"conditions": [
{
"Id": [
"id1",
"1:36-1:40"
]
}
]
}
}
],
"properties": [
{
"location": "2:5-2:17",
"name": [
"fontSize",
"2:5-2:13"
],
"value": {
"Number": {
"location": "2:15-2:17",
"value": 24.0,
"unit": null
}
}
}
]
}
},
{
"Rule": {
"location": "5:1-7:2",
"selectors": [
{
"Base": {
"location": "5:1-5:25",
"namespace_prefix": null,
"element_name": null,
"conditions": [
{
"Class": [
"myStyleName1",
"5:1-5:14"
]
},
{
"Attribute": {
"location": "5:14-5:25",
"name": [
"attr",
"5:15-5:19"
],
"operator": "BeginsWith",
"value": [
".",
"5:21-5:24"
]
}
}
]
}
}
],
"properties": [
{
"location": "6:5-6:15",
"name": [
"color",
"6:5-6:10"
],
"value": {
"Color": {
"location": "6:12-6:15",
"color_int": 16711680
}
}
}
]
}
}
]
}
7 changes: 7 additions & 0 deletions tests/parser/css/selectors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.myStyleName1.anotherOne s|VGroup, #id1 {
fontSize: 24
}

.myStyleName1[attr^="."] {
color: red
}
Empty file added tests/parser/css/selectors.diag
Empty file.

0 comments on commit b711ea6

Please sign in to comment.