Skip to content

Commit

Permalink
fix: format behavior of union types
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 ec71539 commit a4f6be2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kclvm/ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ schema Person:

type PersonOther = Person
type Int = int
type UnionType = int|float|str
type UnionType = int | float | str
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
4 changes: 2 additions & 2 deletions kclvm/tools/src/format/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
];
Expand Down

0 comments on commit a4f6be2

Please sign in to comment.