From 4d2fe984aab30af9c0faf1db0dd9c68b7861e979 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Thu, 13 Aug 2015 13:54:19 +0200
Subject: Check well known units on result, alternative, reference

See commit 1d63c5147500e10d386f3843ba6930fe533ab4e5
---
 src/Codec/Pesto/Lint.lhs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

(limited to 'src/Codec')

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
-- 
cgit v1.2.3