Skip to content

Commit

Permalink
Merge pull request #19 from jkuczm/mma_versions_compatibility
Browse files Browse the repository at this point in the history
Mma versions compatibility
  • Loading branch information
jkuczm committed May 21, 2016
2 parents ae9d039 + c5571a0 commit 6554c49
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 203 deletions.
2 changes: 1 addition & 1 deletion BootstrapInstall.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

BootstrapInstall[
"CellsToTeX",
"https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.1.4/CellsToTeX.zip"
"https://github.com/jkuczm/MathematicaCellsToTeX/releases/download/v0.2.0/CellsToTeX.zip"
,
{{
"SyntaxAnnotations",
Expand Down
45 changes: 32 additions & 13 deletions CellsToTeX/CellsToTeX.m
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ cell form (String or None)."
With[
{
msg = assoc["MessageTemplate"],
msgParam = assoc["MessageParameters"]
msgParam = assoc["MessageParameters"],
type = assoc["Type"]
}
,
ToBoxes @ Interpretation[
Expand All @@ -901,18 +902,30 @@ cell form (String or None)."
{
Style["\[WarningSign]", "Message", FontSize -> 35]
,
"Message: " <> ToString[
Style["Message:", FontColor->GrayLevel[0.5]]
,
ToString[
StringForm[msg, Sequence @@ msgParam],
StandardForm
]
},
{SpanFromAbove, "Tag:" <> ToString[tag, StandardForm]}
{
SpanFromAbove,
Style["Tag:", FontColor->GrayLevel[0.5]],
ToString[tag, StandardForm]
},
{
SpanFromAbove,
Style["Type:", FontColor->GrayLevel[0.5]],
ToString[type, StandardForm]
}
},
Alignment -> {Left, Top}
],
Failure[tag, assoc]
] /; msg =!= Missing["KeyAbsent", "MessageTemplate"] &&
msgParam =!= Missing["KeyAbsent", "MessageParameters"]
msgParam =!= Missing["KeyAbsent", "MessageParameters"] &&
msgParam =!= Missing["KeyAbsent", "Type"]
]
]

Expand Down Expand Up @@ -1011,12 +1024,13 @@ cell form (String or None)."
}
,
Throw[
Failure[tag,
Failure[CellsToTeXException,
Association[
"MessageTemplate" :>
MessageName[CellsToTeXException, messageName],
"MessageParameters" ->
List @@ HoldForm /@ HoldComplete[thrownBy, tag, vals]
List @@ HoldForm /@ HoldComplete[thrownBy, tag, vals],
"Type" -> {types, type}
]
],
tag
Expand Down Expand Up @@ -1112,7 +1126,11 @@ cell form (String or None)."
HoldComplete[value]
]&;

If[!MatchQ[value, Failure[tag, _Association]],
If[
!MatchQ[value,
Failure[CellsToTeXException, _Association]
]
(* then *),
throwInvValExc["NonFailureObject"]
];

Expand All @@ -1137,17 +1155,18 @@ cell form (String or None)."
]
}
,
assoc = Append[assoc,
assoc = Append[assoc, {
"MessageParameters" -> {
HoldForm[rethrownBy],
HoldForm[newTag],
Sequence @@ Drop[msgParams, 2],
Sequence @@ HoldForm /@
additionalMessageParameters
}
];
},
"Type" -> List @@ newTag
}];

Throw[Failure[newTag, assoc], newTag]
Throw[Failure[CellsToTeXException, assoc], newTag]
]
]
]
Expand Down Expand Up @@ -1320,7 +1339,7 @@ cell form (String or None)."
name_String
(* else *),
name_String /;
StringMatchQ[name, RegularExpression["[[:ascii:]]*"]]
StringMatchQ[name, RegularExpression["[\\x00-\\x7F]*"]]
],
type:allowedTypes,
___
Expand Down Expand Up @@ -2368,7 +2387,7 @@ cell form (String or None)."
If[nonASCIIHandler =!= Identity,
With[{nonASCIIHandler = nonASCIIHandler},
AppendTo[stringRules,
char:RegularExpression["[^[:ascii:]]"] :>
char:RegularExpression["[^\\x00-\\x7F]"] :>
nonASCIIHandler[char]
]
]
Expand Down
87 changes: 55 additions & 32 deletions CellsToTeX/Tests/Integration/CellToTeX.mt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ $ContextPath =
Join[{"CellsToTeX`Configuration`", "CellsToTeX`Backports`"}, $ContextPath]


(* In tests we use pattern matching on contents of Association, it works since
Mathematica v10.4, and for backported Association for versions < 10.0,
but not for versions from 10.0 to 10.3, so for this versions we normalize
Associations. *)
normalAssoc =
If[10 <= $VersionNumber < 10.4,
Module[{association},
(# /. assoc_Association :> association @@ Normal[assoc])&
]
(* else *),
Identity
]


(* ::Section:: *)
(*Tests*)

Expand Down Expand Up @@ -366,14 +380,15 @@ With[
}
,
TestMatch[
CellToTeX[Cell[BoxData["contents"]]]
CellToTeX[Cell[BoxData["contents"]]] // normalAssoc
,
Failure[CellsToTeXException["Missing", "CellStyle"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::missingCellStyle,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Missing", "CellStyle"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand All @@ -396,14 +411,16 @@ With[
}
,
TestMatch[
CellToTeX[Cell[BoxData["contents"], "testUnsupportedStyle"]]
CellToTeX[Cell[BoxData["contents"], "testUnsupportedStyle"]] //
normalAssoc
,
Failure[CellsToTeXException["Unsupported", "CellStyle"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "CellStyle"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand All @@ -427,14 +444,15 @@ With[
CellToTeX[
Cell["contents", "Input"],
"ProcessorOptions" -> {"FormatType" -> testFormatType}
]
] // normalAssoc
,
Failure[CellsToTeXException["Unsupported", "FormatType"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "FormatType"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand All @@ -459,14 +477,15 @@ With[
BoxData[testUnsupportedBox],
"Style" -> "Output",
"ProcessorOptions" -> {"BoxRules" -> {testSupportedBox[b_] :> b}}
]
] // normalAssoc
,
Failure[CellsToTeXException["Unsupported", "Box"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "Box"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand Down Expand Up @@ -499,14 +518,15 @@ Block[
CellToTeX[
BoxData[RowBox[{"testUndefinedSymbol"}]],
"Style" -> "Input"
]
] // normalAssoc
,
Failure[CellsToTeXException["Unsupported", "AnnotationType"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "AnnotationType"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand Down Expand Up @@ -538,14 +558,15 @@ With[
ShowCellLabel -> True
],
"ProcessorOptions" -> {"BoxRules" -> {testSupportedBox -> ""}}
]
] // normalAssoc
,
Failure[CellsToTeXException["Unsupported", "Box"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "Box"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand Down Expand Up @@ -593,14 +614,15 @@ With[
CellToTeX[
Cell[BoxData["contents"], "Print"],
"Processor" -> trackCellIndexProcessor
]
] // normalAssoc
,
Failure[CellsToTeXException["Missing", "Keys", "ProcessorArgument"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::missingProcArg,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Missing", "Keys", "ProcessorArgument"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand Down Expand Up @@ -638,14 +660,15 @@ With[
CellToTeX[
Cell[BoxData["contents"], "Message"],
"Processor" -> Identity
]
] // normalAssoc
,
Failure[CellsToTeXException["Missing", "Keys", "ProcessorResult"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::missingProcRes,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Missing", "Keys", "ProcessorResult"}
]
]
] // normalAssoc
,
{heldMessage}
,
Expand Down
37 changes: 16 additions & 21 deletions CellsToTeX/Tests/Integration/CellsToTeXPreamble.mt
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ Module[{unsupportedValue},
]
}
,
TestMatch[
Test[
CellsToTeXPreamble["Gobble" -> unsupportedValue]
,
Failure[
CellsToTeXException["Unsupported", "OptionValue", "Gobble"],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "OptionValue", "Gobble"}
]
]
,
Expand Down Expand Up @@ -161,16 +161,14 @@ Module[{unsupportedValue},
]
}
,
TestMatch[
Test[
CellsToTeXPreamble["UseListings" -> unsupportedValue]
,
Failure[
CellsToTeXException[
"Unsupported", "OptionValue", "UseListings"
],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "OptionValue", "UseListings"}
]
]
,
Expand Down Expand Up @@ -211,15 +209,14 @@ Module[{unsupportedValue},
]
}
,
TestMatch[
Test[
CellsToTeXPreamble["TeXOptions" -> unsupportedValue]
,
Failure[
CellsToTeXException["Unsupported", "OptionValue", "TeXOptions"]
,
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "OptionValue", "TeXOptions"}
]
]
,
Expand Down Expand Up @@ -268,16 +265,14 @@ With[
]
}
,
TestMatch[
Test[
CellsToTeXPreamble["TeXMathReplacement" -> "unsupportedValue"]
,
Failure[
CellsToTeXException[
"Unsupported", "OptionValue", "TeXMathReplacement"
],
Failure[CellsToTeXException,
Association[
"MessageTemplate" :> CellsToTeXException::unsupported,
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]]
"MessageParameters" -> (List @@@ heldMessage)[[1, 2;;]],
"Type" -> {"Unsupported", "OptionValue", "TeXMathReplacement"}
]
]
,
Expand Down
Loading

0 comments on commit 6554c49

Please sign in to comment.