From 10346f359d3201c87f22ba3a0b32901768d7cb68 Mon Sep 17 00:00:00 2001 From: jkuczm Date: Mon, 30 Mar 2015 16:43:18 +0200 Subject: [PATCH 1/4] Add tests of throwing known exceptions --- CellsToTeX/Tests/Unit/throwException.mt | 184 ++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/CellsToTeX/Tests/Unit/throwException.mt b/CellsToTeX/Tests/Unit/throwException.mt index 3d6620c..ec106bc 100644 --- a/CellsToTeX/Tests/Unit/throwException.mt +++ b/CellsToTeX/Tests/Unit/throwException.mt @@ -324,6 +324,190 @@ Module[{thrownBy, errType}, ] +(* ::Subsection:: *) +(*Known exceptions*) + + +Module[{thrownBy, elementType, subType, expr}, + Test[ + Catch[ + throwException[thrownBy, {"Failed", elementType, subType}, {expr}]; + , + _ + , + HoldComplete + ] + , + HoldComplete @@ { + Failure[CellsToTeXException["Failed", elementType, subType], + Association[ + "MessageTemplate" :> CellsToTeXException::failed, + "MessageParameters" -> { + HoldForm[thrownBy], + HoldForm @ CellsToTeXException[ + "Failed", elementType, subType + ], + HoldForm[expr] + } + ] + ], + CellsToTeXException["Failed", elementType, subType] + } + , + TestID -> "Known exception: Failed" + ] +] + + +Module[{thrownBy, elementType, subType, missing, available}, + Test[ + Catch[ + throwException[thrownBy, {"Missing", elementType, subType}, + {missing, available} + ]; + , + _ + , + HoldComplete + ] + , + HoldComplete @@ { + Failure[CellsToTeXException["Missing", elementType, subType], + Association[ + "MessageTemplate" :> CellsToTeXException::missing, + "MessageParameters" -> { + HoldForm[thrownBy], + HoldForm @ CellsToTeXException[ + "Missing", elementType, subType + ], + HoldForm[elementType], + HoldForm[missing], + HoldForm[available] + } + ] + ], + CellsToTeXException["Missing", elementType, subType] + } + , + TestID -> "Known exception: Missing" + ] +] + + +Module[{thrownBy, elementType, subType, invalid}, + Test[ + Catch[ + throwException[thrownBy, {"Invalid", elementType, subType}, + {invalid} + ]; + , + _ + , + HoldComplete + ] + , + HoldComplete @@ { + Failure[CellsToTeXException["Invalid", elementType, subType], + Association[ + "MessageTemplate" :> CellsToTeXException::invalid, + "MessageParameters" -> { + HoldForm[thrownBy], + HoldForm @ CellsToTeXException[ + "Invalid", elementType, subType + ], + HoldForm[elementType], + HoldForm[invalid] + } + ] + ], + CellsToTeXException["Invalid", elementType, subType] + } + , + TestID -> "Known exception: Invalid" + ] +] + + +Module[ + { + thrownBy, elementType, subType, unsupported, supported, + prettifyPatternsResult, $prettifyPatternsLog = {} + }, + Block[{prettifyPatterns}, + mockFunction[prettifyPatterns, + $prettifyPatternsLog, prettifyPatternsResult + ]; + + Test[ + Catch[ + throwException[thrownBy, {"Unsupported", elementType, subType}, + {{unsupported}, {supported}} + ]; + , + _ + , + HoldComplete + ] + , + HoldComplete @@ { + Failure[ + CellsToTeXException["Unsupported", elementType, subType], + Association[ + "MessageTemplate" :> CellsToTeXException::unsupported, + "MessageParameters" -> { + HoldForm[thrownBy], + HoldForm @ CellsToTeXException[ + "Unsupported", elementType, subType + ], + HoldForm[elementType], + HoldForm[{unsupported}], + HoldForm[{prettifyPatternsResult}] + } + ] + ], + CellsToTeXException["Unsupported", elementType, subType] + } + , + TestID -> "Known exception: Unsupported" + ] + ] +] + + +Module[{thrownBy, elementType, subType, val1, val2}, + Test[ + Catch[ + throwException[thrownBy, {"Error", elementType, subType}, + {val1, val2} + ]; + , + _ + , + HoldComplete + ] + , + HoldComplete @@ { + Failure[CellsToTeXException["Error", elementType, subType], + Association[ + "MessageTemplate" :> CellsToTeXException::error, + "MessageParameters" -> { + HoldForm[thrownBy], + HoldForm @ CellsToTeXException[ + "Error", elementType, subType + ], + HoldForm[val1], + HoldForm[val2] + } + ] + ], + CellsToTeXException["Error", elementType, subType] + } + , + TestID -> "Known exception: Error" + ] +] + + (* ::Subsection:: *) (*Incorrect arguments*) From 86dd2b2e489142dfa0dbb4e489dd1235741f5ec4 Mon Sep 17 00:00:00 2001 From: jkuczm Date: Mon, 30 Mar 2015 16:44:26 +0200 Subject: [PATCH 2/4] Fix tests involving "Invalid" exception --- CellsToTeX/Tests/Integration/toInputFormProcessor.mt | 1 + CellsToTeX/Tests/Unit/boxesToInputFormBoxes.mt | 1 + 2 files changed, 2 insertions(+) diff --git a/CellsToTeX/Tests/Integration/toInputFormProcessor.mt b/CellsToTeX/Tests/Integration/toInputFormProcessor.mt index 69cbec7..2b5fe73 100644 --- a/CellsToTeX/Tests/Integration/toInputFormProcessor.mt +++ b/CellsToTeX/Tests/Integration/toInputFormProcessor.mt @@ -148,6 +148,7 @@ Test[ HoldForm @ toInputFormProcessor[{"Boxes" -> RowBox[{"f", "["}]}], HoldForm @ CellsToTeXException["Invalid", "Boxes"], + HoldForm @ "Boxes", HoldForm @ RowBox[{"f", "["}] } ] diff --git a/CellsToTeX/Tests/Unit/boxesToInputFormBoxes.mt b/CellsToTeX/Tests/Unit/boxesToInputFormBoxes.mt index 640725f..ab8027f 100644 --- a/CellsToTeX/Tests/Unit/boxesToInputFormBoxes.mt +++ b/CellsToTeX/Tests/Unit/boxesToInputFormBoxes.mt @@ -114,6 +114,7 @@ Test[ "MessageParameters" -> { HoldForm @ boxesToInputFormBoxes[RowBox[{"f", "["}]], HoldForm @ CellsToTeXException["Invalid", "Boxes"], + HoldForm @ "Boxes", HoldForm @ RowBox[{"f", "["}] } ] From 4c50cb29ef0f291fc0f816c4e473014eb9b24248 Mon Sep 17 00:00:00 2001 From: jkuczm Date: Mon, 30 Mar 2015 16:45:56 +0200 Subject: [PATCH 3/4] Add special definition for throwing "Invalid" exception --- CellsToTeX/CellsToTeX.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CellsToTeX/CellsToTeX.m b/CellsToTeX/CellsToTeX.m index eef4491..e4813a7 100644 --- a/CellsToTeX/CellsToTeX.m +++ b/CellsToTeX/CellsToTeX.m @@ -884,14 +884,14 @@ cell form (String or None)." throwException[ HoldComplete[thrownBy_] | thrownBy_, - {"Unsupported", elementType_}, + {"Unsupported", elementType_, subTypes___}, (List | HoldComplete)[unsupported_, supported_], messageName:(_String | Automatic):Automatic ] := With[{supportedPretty = prettifyPatterns /@ supported}, throwException[ thrownBy, - {"Unsupported", elementType}, + {"Unsupported", elementType, subTypes}, HoldComplete[elementType, unsupported, supportedPretty], messageName ] @@ -910,6 +910,19 @@ cell form (String or None)." messageName ] +throwException[ + HoldComplete[thrownBy_] | thrownBy_, + {"Invalid", elementType_, subTypes___}, + (List | HoldComplete)[boxes_], + messageName:(_String | Automatic):Automatic +] := + throwException[ + thrownBy, + {"Invalid", elementType, subTypes}, + HoldComplete[elementType, boxes], + messageName + ] + throwException[ HoldComplete[thrownBy_] | thrownBy_, {types__} | type_String, From 3dbf4c7bc6a30bb761353e5393b5eab87cd1e787 Mon Sep 17 00:00:00 2001 From: jkuczm Date: Mon, 30 Mar 2015 16:48:58 +0200 Subject: [PATCH 4/4] Version bump: 0.1.1 --- BootstrapInstall.m | 2 +- PacletInfo.m | 4 ++-- README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BootstrapInstall.m b/BootstrapInstall.m index 415c6d8..1f5195a 100644 --- a/BootstrapInstall.m +++ b/BootstrapInstall.m @@ -5,7 +5,7 @@ BootstrapInstall[ "CellsToTeX", - "https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.1.0/CellsToTeX.zip" + "https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.1.1/CellsToTeX.zip" , {{ "SyntaxAnnotations", diff --git a/PacletInfo.m b/PacletInfo.m index dc32080..26d1c6d 100644 --- a/PacletInfo.m +++ b/PacletInfo.m @@ -1,10 +1,10 @@ (* Paclet Info File *) -(* created 2015/03/27*) +(* created 2015/03/30*) Paclet[ Name -> "CellsToTeX", - Version -> "0.1.0", + Version -> "0.1.1", MathematicaVersion -> "6+", Description -> "Convert Mathematica cells to TeX, retaining formatting", Creator -> "Jakub Kuczmarski", diff --git a/README.md b/README.md index f6b137c..4941f94 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ To load CellsToTeX package evaluate: ``Needs["CellsToTeX`"]``. ### Manual installation 1. Download latest released - [CellsToTeX.zip](https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.1.0/CellsToTeX.zip) + [CellsToTeX.zip](https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.1.1/CellsToTeX.zip) file. 2. Extract downloaded `CellsToTeX.zip` to any directory which is on