summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-08-13 13:54:19 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-08-16 10:08:15 +0200
commit4d2fe984aab30af9c0faf1db0dd9c68b7861e979 (patch)
tree1e88916a8c03060d73216e76b800b1dad70b4f55
parent980ccb41e46df0c4909c3ac8f4c5a9a04661053f (diff)
downloadpesto-4d2fe984aab30af9c0faf1db0dd9c68b7861e979.tar.gz
pesto-4d2fe984aab30af9c0faf1db0dd9c68b7861e979.tar.bz2
pesto-4d2fe984aab30af9c0faf1db0dd9c68b7861e979.zip
Check well known units on result, alternative, reference
See commit 1d63c5147500e10d386f3843ba6930fe533ab4e5
-rw-r--r--src/Codec/Pesto/Lint.lhs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Codec/Pesto/Lint.lhs b/src/Codec/Pesto/Lint.lhs
index ecfac79..a829e5d 100644
--- a/src/Codec/Pesto/Lint.lhs
+++ b/src/Codec/Pesto/Lint.lhs
@@ -15,6 +15,7 @@ Linting
> import Text.Parsec hiding (parse)
> import Data.Char (isSpace)
> import Data.Ratio ((%))
+> import Data.Maybe (fromMaybe)
>
> import Codec.Pesto.Graph hiding (test)
> import Codec.Pesto.Parse hiding (test)
@@ -146,10 +147,10 @@ Check the metadata’s value format. I.e. yield/time must be quantity
For instance a german language recipe for one person would look like this:
> testMetadata = [
-> cmpLintMeta "+foo >1 Portion foobar (language: de) (x-app-key: value)"
+> cmpLintMeta "+foo >1 ml foobar (language: de) (x-app-key: value)"
> []
> (Just [(1, ("title", MetaStr "foobar"))
-> , (1, ("yield", MetaQty (Quantity (Exact (AmountRatio (1%1))) "Portion" "foobar")))
+> , (1, ("yield", MetaQty (Quantity (Exact (AmountRatio (1%1))) "ml" "foobar")))
> , (2, ("language", MetaStr "de"))
> , (3, ("x-app-key", MetaStr "value"))])
@@ -233,9 +234,13 @@ accepted.
> wellKnownUnit nodes _ = foldl f [] nodes
> where
-> f xs (nodeid, Ingredient q) | (not . known) q =
-> LintResult UnitNotWellKnown [nodeid]:xs
-> f xs (nodeid, Tool q) | (not . known) q =
+> extractQty (Ingredient q) = Just q
+> extractQty (Tool q) = Just q
+> extractQty (Result q) = Just q
+> extractQty (Alternative q) = Just q
+> extractQty (Reference q) = Just q
+> extractQty _ = Nothing
+> f xs (nodeid, instr) | fromMaybe False (extractQty instr >>= (return . not . known)) =
> LintResult UnitNotWellKnown [nodeid]:xs
> f xs _ = xs
> known (Quantity _ unit _) = unit `elem` knownUnits