Verified Commit 3d4614d6 authored by Camil Staps's avatar Camil Staps

Very basic counterexample diff based on Text.GenParse's preparser

parent c07fdc68
Pipeline #12579 failed with stage
in 31 seconds
......@@ -26,51 +26,10 @@ import Testing.Options
import Testing.TestEvents
from Text import <+, class Text(join,replaceSubString,split,trim), instance Text String
import Text.GenJSON
import Text.GenParse
import Text.Language
gDiff{|JSONNode|} x y = case x of
JSONBool i -> case y of
JSONBool j -> gDiff{|*|} i j
_ -> add i ++ remove y
JSONInt i -> case y of
JSONInt j -> gDiff{|*|} i j
_ -> add i ++ remove y
JSONReal i -> case y of
JSONReal j -> gDiff{|*|} i j
_ -> add i ++ remove y
JSONString i -> case y of
JSONString j -> gDiff{|*|} i j
_ -> add i ++ remove y
JSONArray xs -> case y of
JSONArray ys -> gDiff{|*|} xs ys
_ -> add xs ++ remove y
JSONObject xs -> case y of
JSONObject ys -> [
{ status = if (all (\d -> d.status == Common) field_diffs) Common Changed
, value = "Object"
, children = field_diffs
}]
with
field_diffs =
[let ds = gDiff{|*|} (find k xs) (find k ys) in
{status=if (all (\d->d.status==Common) ds) Common Changed, value=k <+ "=", children=ds} \\ k <- both] ++
[{status=OnlyLeft, value=k <+ "=", children=[d]} \\ k <- xonly, d <- remove (find k xs)] ++
[{status=OnlyRight, value=k <+ "=", children=[d]} \\ k <- yonly, d <- add (find k ys)]
with
xkeys = map fst xs
ykeys = map fst ys
both = intersect xkeys ykeys
xonly = difference xkeys ykeys
yonly = difference ykeys xkeys
find k = fromJust o lookup k
_ -> add xs ++ remove y
_ -> abort "Unimplemented gDiff for JSONNode\n"
where
add :: a -> [Diff] | gDiff{|*|} a
add x = map (setStatus OnlyRight) (gDiff{|*|} x x)
remove :: a -> [Diff] | gDiff{|*|} a
remove x = map (setStatus OnlyLeft) (gDiff{|*|} x x)
derive gDiff GenConsAssoc, Maybe, Expr
:: *ProcessOutput =
{ lines :: ![String]
......@@ -390,7 +349,7 @@ where
where
printFA :: FailedAssertion -> String
printFA (ExpectedRelation x rel y) = "Expected " +++ toString rel +++ " on:\n" +++ case rel of
Eq -> diffToConsole $ gDiff{|*|} x y
Eq -> diffToConsole $ gDiff{|*|} (preParseString x) (preParseString y)
_ -> toString x +++ "\n" +++ toString y
printCE :: CounterExample -> String
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment