From d0a05042d7fa932eaba4950cd1b51bf929a76884 Mon Sep 17 00:00:00 2001 From: Iwan Date: Sun, 28 Mar 2021 14:25:08 +0200 Subject: [PATCH] Tweak outcome printer for object type. Adds extra tests + fix minor formatting issues. --- src/res_outcome_printer.ml | 41 +++++++++++++------------------- tests/oprint/oprint.res | 15 ++++++++++++ tests/oprint/oprint.res.snapshot | 33 ++++++++++++++++++++++--- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/res_outcome_printer.ml b/src/res_outcome_printer.ml index e7bfac47..7300bef4 100644 --- a/src/res_outcome_printer.ml +++ b/src/res_outcome_printer.ml @@ -435,8 +435,8 @@ let printPolyVarIdent txt = ) ] ); - Doc.softLine; Doc.trailingComma; + Doc.softLine; Doc.rbrace; ] ) @@ -678,29 +678,22 @@ let printPolyVarIdent txt = let constraints = match outTypeDecl.otype_cstrs with | [] -> Doc.nil | _ -> Doc.group ( - Doc.concat [ - Doc.line; - Doc.indent ( - Doc.concat [ - Doc.hardLine; - Doc.join ~sep:Doc.line (List.map (fun (typ1, typ2) -> - Doc.group ( - Doc.concat [ - Doc.text "constraint "; - printOutTypeDoc typ1; - Doc.text " ="; - Doc.indent ( - Doc.concat [ - Doc.line; - printOutTypeDoc typ2; - ] - ) - ] - ) - ) outTypeDecl.otype_cstrs) - ] - ) - ] + Doc.indent ( + Doc.concat [ + Doc.hardLine; + Doc.join ~sep:Doc.line (List.map (fun (typ1, typ2) -> + Doc.group ( + Doc.concat [ + Doc.text "constraint "; + printOutTypeDoc typ1; + Doc.text " ="; + Doc.space; + printOutTypeDoc typ2; + ] + ) + ) outTypeDecl.otype_cstrs) + ] + ) ) in Doc.group ( Doc.concat [ diff --git a/tests/oprint/oprint.res b/tests/oprint/oprint.res index 5deb0546..4b15c3cc 100644 --- a/tests/oprint/oprint.res +++ b/tests/oprint/oprint.res @@ -264,3 +264,18 @@ type obj6 = {"a": int} type obj7 = {. "a": int} type obj8<'a> = {.. "a": int} as 'a +type objUser = {"name": string, "age": int} +type objUserWithLongFields = {"name": string, "x": int, "age": int, "looooooongFiiiiiiiieeeeeeeldName": string, "anoooooooooooooooootherLongFiiiiiieeeeeeeldName": int} + +type objectCoordinate = {"x": float, "y": float} +type threeDimensionalCoordinate = {...objectCoordinate, "z": float} +type differentSpreadedCoordinate = {"z": float, ...objectCoordinate, "alpha": int} + +type multiSpreadedCoordinate = { + ...threeDimensionalCoordinate, + "a": int, + ...differentSpreadedCoordinate, + "b": int +} + +type dotdotObjectCoordinate<'a> = {.. "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame": float, "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame2222222222222": float} as 'a diff --git a/tests/oprint/oprint.res.snapshot b/tests/oprint/oprint.res.snapshot index f7328b95..df4b7a4d 100644 --- a/tests/oprint/oprint.res.snapshot +++ b/tests/oprint/oprint.res.snapshot @@ -404,10 +404,37 @@ type obj2 = {"a": int} type obj3 = {"a": int} type obj4 = {"a": int} type obj5<'a> = Js.t<'a> - constraint 'a = {..} type obj6 = {"a": int} type obj7 = {"a": int} type obj8<'a> = 'a - - constraint 'a = {.."a": int} \ No newline at end of file + constraint 'a = {.."a": int} +type objUser = {"age": int, "name": string} +type objUserWithLongFields = { + "age": int, + "anoooooooooooooooootherLongFiiiiiieeeeeeeldName": int, + "looooooongFiiiiiiiieeeeeeeldName": string, + "name": string, + "x": int, +} +type objectCoordinate = {"x": float, "y": float} +type threeDimensionalCoordinate = {"x": float, "y": float, "z": float} +type differentSpreadedCoordinate = { + "alpha": int, + "x": float, + "y": float, + "z": float, +} +type multiSpreadedCoordinate = { + "a": int, + "alpha": int, + "b": int, + "x": float, + "y": float, + "z": float, +} +type dotdotObjectCoordinate<'a> = 'a + constraint 'a = {.. + "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame": float, + "suuuuuuuuuuuperLooooooooooooongFieldNaaaaaaaaaaaame2222222222222": float, + } \ No newline at end of file