Skip to content

Commit

Permalink
feat: Some array literal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 28, 2023
1 parent 1533886 commit aae9d63
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
117 changes: 117 additions & 0 deletions server/src/lang/tests/generic/array_literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#[cfg(test)]
use crate::lang::tests::helpers::compare_parsed_to_expected;

#[cfg(test)]
use serde_json::json;

#[cfg(test)]
use crate::assert_parsing;

#[cfg(test)]
assert_parsing! {
plain_declare: {
"var $arr = [1, 'abc', { \\key: `val` }];" => {
"type": "Stmt::Program",
"body": [
{
"type": "Stmt::Declaration",
"variable": "$arr",
"expr": {
"type": "Expr::Literal",
"raw": "",
"value": {
"type": "Array",
"value": [
{
"type": "Expr::Literal",
"value": "Num(1.0)",
"raw": "1",
},
{
"type": "Expr::Literal",
"value": "Str(\"abc\")",
"raw": "abc",
},
{
"type": "Expr::Literal",
"raw": "",
"value": {
"type": "Object",
"value": [
{
"key": "key",
"value": {
"type": "Expr::Literal",
"value": "Str(\"val\")",
"raw": "val",
}
},
]
}
}
]
}
}
}
]
}
},
two_dimensional: {
"var $arr = [[1, 2], [3, 4]];" => {
"type": "Stmt::Program",
"body": [
{
"type": "Stmt::Declaration",
"variable": "$arr",
"expr": {
"type": "Expr::Literal",
"raw": "",
"value": {
"type": "Array",
"value": [
{
"type": "Expr::Literal",
"raw": "",
"value": {
"type": "Array",
"value": [
{
"type": "Expr::Literal",
"value": "Num(1.0)",
"raw": "1",
},
{
"type": "Expr::Literal",
"value": "Num(2.0)",
"raw": "2",
}
]
}
},
{
"type": "Expr::Literal",
"raw": "",
"value": {
"type": "Array",
"value": [
{
"type": "Expr::Literal",
"value": "Num(3.0)",
"raw": "3",
},
{
"type": "Expr::Literal",
"value": "Num(4.0)",
"raw": "4",
}
]
}
}
]
}
}
}
]
}
}
}
1 change: 1 addition & 0 deletions server/src/lang/tests/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pub mod function_call;
pub mod grouping;
pub mod number_literal;
pub mod object_literal;
pub mod array_literal;
pub mod unary;
pub mod variable;

0 comments on commit aae9d63

Please sign in to comment.