{-
-Copyright (C) 2012 Google Inc.
+Copyright (C) 2012, 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
, JobDependency(..)
, OpSubmitPriority(..)
, opSubmitPriorityToRaw
+ , parseSubmitPriority
+ , fmtSubmitPriority
, OpStatus(..)
, opStatusToRaw
, opStatusFromRaw
])
$(THH.makeJSONInstance ''OpSubmitPriority)
+-- | Parse submit priorities from a string.
+parseSubmitPriority :: (Monad m) => String -> m OpSubmitPriority
+parseSubmitPriority "low" = return OpPrioLow
+parseSubmitPriority "normal" = return OpPrioNormal
+parseSubmitPriority "high" = return OpPrioHigh
+parseSubmitPriority str = fail $ "Unknown priority '" ++ str ++ "'"
+
+-- | Format a submit priority as string.
+fmtSubmitPriority :: OpSubmitPriority -> String
+fmtSubmitPriority OpPrioLow = "low"
+fmtSubmitPriority OpPrioNormal = "normal"
+fmtSubmitPriority OpPrioHigh = "high"
+
-- | Our ADT for the OpCode status at runtime (while in a job).
$(THH.declareSADT "OpStatus"
[ ("OP_STATUS_QUEUED", 'C.opStatusQueued)
{-
-Copyright (C) 2012 Google Inc.
+Copyright (C) 2012, 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
prop_OpSubmitPriority_serialisation :: OpSubmitPriority -> Property
prop_OpSubmitPriority_serialisation = testSerialisation
+-- | Tests string formatting for 'OpSubmitPriority'.
+prop_OpSubmitPriority_string :: OpSubmitPriority -> Property
+prop_OpSubmitPriority_string prio =
+ parseSubmitPriority (fmtSubmitPriority prio) ==? Just prio
+
-- | Test 'ELogType' serialisation.
prop_ELogType_serialisation :: ELogType -> Property
prop_ELogType_serialisation = testSerialisation
, 'case_JobId_BadTypes
, 'prop_JobDependency_serialisation
, 'prop_OpSubmitPriority_serialisation
+ , 'prop_OpSubmitPriority_string
, 'prop_ELogType_serialisation
]