Commit e5599148 authored by Michael Hanus's avatar Michael Hanus
Browse files

Add tests

parent a84bb339
*~
.curry
.cpm
*_PUBLIC.curry
src/TEST*.curry
Copyright (c) 2021, Michael Hanus, Jonas Oberschweiber
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the names of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- Some simple tests for the JSON package.
import Data.Maybe
import Test.Prop
import JSON.Data
import JSON.Parser
import JSON.Pretty
-- A simple JSON value.
jsonDoc :: JValue
jsonDoc = JObject [("hello", JArray [JString "world", JString "kiel"])]
-- Parsing JSON strings.
testParse :: Prop
testParse = parseJSON "{ \"hello\": [\"world\", \"kiel\"] }" -=- Just jsonDoc
-- Test pretty printing and parsing.
testPrint :: Prop
testPrint = parseJSON (ppJSON jsonDoc) -=- Just jsonDoc
-- Equality of JSON values where float equality is approximated.
eqJValue :: JValue -> JValue -> Bool
eqJValue jv1 jv2 = case (jv1,jv2) of
(JNumber x, JNumber y) -> abs (x - y) < 0.0001
(JArray xs, JArray ys) -> all (uncurry eqJValue) (zip xs ys)
(JObject xs,JObject ys) -> all eqComp (zip xs ys)
_ -> jv1 == jv2
where
eqComp ((s,x),(t,y)) = s == t && eqJValue x y
-- Test property of pretty printing and parsing.
testParsePrint :: JValue -> Prop
testParsePrint json =
always (eqJValue (fromJust (parseJSON (ppJSON json))) json)
......@@ -5,6 +5,8 @@
"maintainer": "Michael Hanus <mh@informatik.uni-kiel.de>",
"synopsis": "A JSON library for Curry",
"category": [ "Data", "Web" ],
"license": "BSD-3-Clause",
"licenseFile": "LICENSE",
"dependencies": {
"det-parse": ">= 3.0.0, < 4.0.0",
"wl-pprint": ">= 3.0.0, < 4.0.0",
......@@ -15,6 +17,14 @@
"kics2": ">= 3.0.0, < 4.0.0"
},
"exportedModules": ["JSON.Data", "JSON.Parser", "JSON.Pretty"],
"testsuite": [
{ "src-dir": "src",
"modules": ["JSON.Data", "JSON.Parser", "JSON.Pretty"]
},
{ "src-dir": "examples",
"modules": [ "SimpleTest" ]
}
],
"source": {
"git": "https://git.ps.informatik.uni-kiel.de/curry-packages/json.git",
"tag": "$version"
......
Supports Markdown
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