Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more test cases on format tool behavior #786

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading