Skip to content

Commit

Permalink
test: add more test cases on format tool behavior
Browse files Browse the repository at this point in the history
Signed-off-by: xiarui.xr <[email protected]>
  • Loading branch information
amyXia1994 committed Oct 18, 2023
1 parent 4486c08 commit fbe29e1
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kclvm/ast_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<'p> Printer<'p> {
}
}

/// Print AST to string
/// Print AST to string. The default format is according to the KCL code style defined here: https://kcl-lang.io/docs/reference/lang/spec/codestyle
pub fn print_ast_module(module: &Module) -> String {
let mut printer = Printer::default();
printer.write_module(module);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import a

schema A:
name: str = a.name

A {}

# Break one blank line between different statements e.g., import, schema and expression statements.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import a
schema A:
name: str = a.name
A{}

# Break one blank line between different statements e.g., import, schema and expression statements.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
dict = {
"key": "value"
}

dict2 = {"key": "value"}

list = [
first
second
]

list2 = [first, second]

expr = Person {
name: "Alice"
}

expr2 = Person {name: "Alice"}

# It's both acceptable to write each entry in the list/dict/schema expr without line breaks, or separate each entry with one line break.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
dict = {
"key": "value"
}

dict2 = {"key": "value"}

list = [
first
second
]

list2 = [first, second]

expr = Person {
name: "Alice"
}

expr2 = Person {name: "Alice"}

# It's both acceptable to write each entry in the list/dict/schema expr without line breaks, or separate each entry with one line break.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
workloadType: "Deployment" | "StatefulSet" = "Deployment"
ServiceType: "LoadBalance" | "ClusterIP" = "LoadBalance"
abc: A | B | C = A {}

# In union types, there should be one and only one whitespace both before and after the union operator |
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
workloadType: "Deployment"|"StatefulSet" = "Deployment"
ServiceType: "LoadBalance" |"ClusterIP" = "LoadBalance"
abc: A|B|C = A{}

# In union types, there should be one and only one whitespace both before and after the union operator |
3 changes: 3 additions & 0 deletions kclvm/tools/src/format/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const TEST_CASES: &[&str; 18] = &[
"string",
"type_alias",
"unary",
// "union_types",
// "different_stmts_line_breaks",
// "list_dict_schema_expr",
];

fn read_data(data_name: &str) -> (String, String) {
Expand Down

0 comments on commit fbe29e1

Please sign in to comment.