diff --git a/kclvm/ast/src/ast.rs b/kclvm/ast/src/ast.rs index 6c9c80702..663879f17 100644 --- a/kclvm/ast/src/ast.rs +++ b/kclvm/ast/src/ast.rs @@ -1556,7 +1556,7 @@ impl ToString for Type { } for (i, t) in x.type_elements.iter().enumerate() { if i > 0 { - w.push('|'); + w.push_str(" | ") } to_str(&t.node, w); } diff --git a/kclvm/tools/src/format/test_data/format_data/type_alias.golden b/kclvm/tools/src/format/test_data/format_data/type_alias.golden index 7bc0ef6b1..87616fb37 100644 --- a/kclvm/tools/src/format/test_data/format_data/type_alias.golden +++ b/kclvm/tools/src/format/test_data/format_data/type_alias.golden @@ -4,4 +4,4 @@ schema Person: type PersonOther = Person type Int = int -type UnionType = int|float|str +type UnionType = int | float | str diff --git a/kclvm/tools/src/format/test_data/format_data/union_types.golden b/kclvm/tools/src/format/test_data/format_data/union_types.golden index 86f5bc5d7..b4f853579 100644 --- a/kclvm/tools/src/format/test_data/format_data/union_types.golden +++ b/kclvm/tools/src/format/test_data/format_data/union_types.golden @@ -2,4 +2,10 @@ workloadType: "Deployment" | "StatefulSet" = "Deployment" ServiceType: "LoadBalance" | "ClusterIP" = "LoadBalance" abc: A | B | C = A {} +schema Server: + [name: str | int]: str | int + workloadType: "Deployment" | "StatefulSet" + dict: {str:str | int} + +type some_alias = "abc" | "def" | {str | int:} # In union types, there should be one and only one whitespace both before and after the union operator | diff --git a/kclvm/tools/src/format/test_data/format_data/union_types.input b/kclvm/tools/src/format/test_data/format_data/union_types.input index 0dd6de4f9..03d8b64fd 100644 --- a/kclvm/tools/src/format/test_data/format_data/union_types.input +++ b/kclvm/tools/src/format/test_data/format_data/union_types.input @@ -2,4 +2,10 @@ workloadType: "Deployment"|"StatefulSet" = "Deployment" ServiceType: "LoadBalance" |"ClusterIP" = "LoadBalance" abc: A|B|C = A{} +schema Server: + [name: str|int]: str|int + workloadType: "Deployment"| "StatefulSet" + dict: {str: str|int} + +type some_alias = "abc"|"def"|{str|int:} # In union types, there should be one and only one whitespace both before and after the union operator | diff --git a/kclvm/tools/src/format/tests.rs b/kclvm/tools/src/format/tests.rs index 0b483abfe..1acdebfc6 100644 --- a/kclvm/tools/src/format/tests.rs +++ b/kclvm/tools/src/format/tests.rs @@ -5,7 +5,7 @@ use walkdir::WalkDir; const FILE_INPUT_SUFFIX: &str = ".input"; const FILE_OUTPUT_SUFFIX: &str = ".golden"; -const TEST_CASES: &[&str; 18] = &[ +const TEST_CASES: &[&str; 19] = &[ "assert", "check", "blankline", @@ -24,7 +24,7 @@ const TEST_CASES: &[&str; 18] = &[ "string", "type_alias", "unary", - // "union_types", + "union_types", // "different_stmts_line_breaks", // "list_dict_schema_expr", ];