Skip to content

Commit 22d8148

Browse files
authored
Merge pull request #68 from haskellari/issue-67
Add a test for issue #67
2 parents 25d34c2 + 608b934 commit 22d8148

File tree

9 files changed

+75
-27
lines changed

9 files changed

+75
-27
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# version: 0.15.20220808
11+
# version: 0.15.20221225
1212
#
13-
# REGENDATA ("0.15.20220808",["github","cabal.project"])
13+
# REGENDATA ("0.15.20221225",["github","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -300,3 +300,11 @@ jobs:
300300
run: |
301301
rm -f cabal.project.local
302302
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
303+
- name: prepare for constraint sets
304+
run: |
305+
rm -f cabal.project.local
306+
- name: constraint set random-hashable
307+
run: |
308+
if [ $((! GHCJSARITH && HCNUMVER >= 90400)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='hashable >=1.3.2.0' --constraint='hashable +random-initial-seed' --dependencies-only -j2 all ; fi
309+
if [ $((! GHCJSARITH && HCNUMVER >= 90400)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='hashable >=1.3.2.0' --constraint='hashable +random-initial-seed' all ; fi
310+
if [ $((! GHCJSARITH && HCNUMVER >= 90400)) -ne 0 ] ; then $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='hashable >=1.3.2.0' --constraint='hashable +random-initial-seed' all ; fi

ChangeLog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 0.3
2+
3+
- Breaking change:
4+
Make HashSet and HashMap ToExpr instances sort the resulting
5+
lists of expressions.
6+
This makes the results deterministic.
7+
... but your golden files will need adjustment.
8+
https://github.com/haskellari/tree-diff/issues/67
9+
10+
- Add `Ord Expr` and `Ord OMap` instances
11+
- Depend on `data-array-byte` to provide more `ByteArray` instances
12+
113
## 0.2.2
214

315
- Add instances for base and primitive's `ByteArray`s.

cabal.haskell-ci

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ docspec: >=8
77
-- constraint-set bytestring-0.11
88
-- ghc: >=7.8
99
-- constraints: bytestring ^>=0.11
10+
11+
constraint-set random-hashable
12+
ghc: ==9.4.*
13+
constraints: hashable >=1.3.2.0, hashable +random-initial-seed
14+
tests: True
15+
run-tests: True

fixtures/HashSet.expr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
HS.fromList
2+
[
3+
"ax",
4+
"ay",
5+
"az",
6+
"bx",
7+
"by",
8+
"bz",
9+
"cx",
10+
"cy",
11+
"cz",
12+
"dx",
13+
"dy",
14+
"dz"]

src/Data/TreeDiff/Class.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Data.TreeDiff.Class (
2121
) where
2222

2323
import Data.Foldable (toList)
24+
import Data.List (sort)
2425
import Data.List.Compat (uncons)
2526
import Data.Proxy (Proxy (..))
2627
import GHC.Generics
@@ -108,7 +109,7 @@ import Data.These (These (..))
108109
-- primitive
109110
import qualified Data.Primitive as Prim
110111

111-
#if MIN_VERSION_base(4,17,0)
112+
#if MIN_VERSION_base(4,9,0)
112113
import Data.Array.Byte (ByteArray (..))
113114
#endif
114115

@@ -550,9 +551,9 @@ instance ToExpr a => ToExpr (Hashed a) where
550551
-------------------------------------------------------------------------------
551552

552553
instance (ToExpr k, ToExpr v) => ToExpr (HM.HashMap k v) where
553-
toExpr x = App "HM.fromList" [ toExpr $ HM.toList x ]
554+
toExpr x = App "HM.fromList" [ Lst $ sort $ map toExpr $ HM.toList x ]
554555
instance (ToExpr k) => ToExpr (HS.HashSet k) where
555-
toExpr x = App "HS.fromList" [ toExpr $ HS.toList x ]
556+
toExpr x = App "HS.fromList" [ Lst $ sort $ map toExpr $ HS.toList x ]
556557

557558
-------------------------------------------------------------------------------
558559
-- aeson
@@ -601,7 +602,7 @@ instance (ToExpr a, ToExpr b) => ToExpr (These a b) where
601602
instance ToExpr Prim.ByteArray where
602603
toExpr ba = App "Prim.byteArrayFromList" [toExpr (Prim.foldrByteArray (:) [] ba :: [Word8])]
603604

604-
#if MIN_VERSION_base(4,17,0)
605+
#if MIN_VERSION_base(4,9,0)
605606
-- | @since 0.2.2
606607
instance ToExpr ByteArray where
607608
toExpr (ByteArray ba) = App "byteArrayFromList" [toExpr (Prim.foldrByteArray (:) [] (Prim.ByteArray ba) :: [Word8])]

src/Data/TreeDiff/Expr.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data Expr
3535
= App ConstructorName [Expr] -- ^ application
3636
| Rec ConstructorName (OMap FieldName Expr) -- ^ record constructor
3737
| Lst [Expr] -- ^ list constructor
38-
deriving (Eq, Show)
38+
deriving (Eq, Ord, Show)
3939

4040
instance NFData Expr where
4141
rnf (App n es) = rnf n `seq` rnf es

src/Data/TreeDiff/OMap.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ instance (Show k, Show v) => Show (OMap k v) where
6161
-- False
6262
--
6363
instance (Eq k, Eq v) => Eq (OMap k v) where
64-
xs == ys = go (toAscList xs) (toAscList ys) where
65-
go [] [] = True
66-
go _ [] = False
67-
go [] _ = False
68-
go ((k1, v1) : kvs1) ((k2, v2) : kvs2) =
69-
k1 == k2 && v1 == v2 && go kvs1 kvs2
64+
xs == ys = toAscList xs == toAscList ys
65+
66+
instance (Ord k, Ord v) => Ord (OMap k v) where
67+
compare xs ys = compare (toAscList xs) (toAscList ys)
7068

7169
-------------------------------------------------------------------------------
7270
-- deepseq

tests/Tests.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Test.Tasty (TestTree, defaultMain, testGroup)
1111
import Test.Tasty.Golden.Advanced (goldenTest)
1212
import Test.Tasty.QuickCheck (testProperty)
1313

14+
import qualified Data.HashSet as HS
1415
import qualified Text.Parsec as P
1516
import qualified Text.PrettyPrint.ANSI.Leijen as WL
1617
import qualified Text.Trifecta as T (eof, parseString)
@@ -163,5 +164,9 @@ goldenTests = testGroup "Golden"
163164
return $ MyInt3 42
164165
, ediffGolden goldenTest "Positional" "fixtures/Positional.expr" $
165166
return $ Positional 12 True 'z'
167+
168+
-- issue #67
169+
, ediffGolden goldenTest "HashSet" "fixtures/HashSet.expr" $
170+
return $ HS.fromList [ [x,y] | x <- "abcd", y <- "xyz" ]
166171
]
167172

tree-diff.cabal

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: tree-diff
3-
version: 0.2.2
3+
version: 0.3
44
synopsis: Diffing of (expression) trees.
55
category: Data, Testing
66
description:
@@ -85,22 +85,22 @@ library
8585

8686
-- GHC boot libraries
8787
build-depends:
88-
, base >=4.5 && <4.18
89-
, bytestring ^>=0.9.2.1 || ^>=0.10.0.2 || ^>=0.11.0.0
90-
, containers ^>=0.4.2.1 || ^>=0.5.0.0 || ^>=0.6.0.1
91-
, deepseq ^>=1.3.0.0 || ^>=1.4.0.0
88+
, base >=4.5 && <4.18
89+
, bytestring ^>=0.9.2.1 || ^>=0.10.0.2 || ^>=0.11.0.0
90+
, containers ^>=0.4.2.1 || ^>=0.5.0.0 || ^>=0.6.0.1
91+
, deepseq ^>=1.3.0.0 || ^>=1.4.0.0
9292
, parsec ^>=3.1.13.0
9393
, pretty ^>=1.1.1.0
94-
, text ^>=1.2.3.0 || ^>=2.0
95-
, time >=1.4 && <1.5 || >=1.5.0.1 && <1.6 || >=1.6.0.1 && <1.7 || >=1.8.0.2 && <1.9 || >=1.9.3 && <1.13
94+
, text ^>=1.2.3.0 || ^>=2.0
95+
, time >=1.4 && <1.5 || >=1.5.0.1 && <1.6 || >=1.6.0.1 && <1.7 || >=1.8.0.2 && <1.9 || >=1.9.3 && <1.13
9696

9797
build-depends:
98-
, aeson ^>=1.4.6.0 || ^>=1.5.6.0 || ^>=2.0.0.0 || ^>=2.1.0.0
99-
, ansi-terminal >=0.10 && <0.12
98+
, aeson ^>=1.4.6.0 || ^>=1.5.6.0 || ^>=2.0.0.0 || ^>=2.1.0.0
99+
, ansi-terminal >=0.10 && <0.12
100100
, ansi-wl-pprint ^>=0.6.8.2
101-
, base-compat >=0.10.5 && <0.11 || >=0.11.0 && <0.13
101+
, base-compat >=0.10.5 && <0.11 || >=0.11.0 && <0.13
102102
, bytestring-builder ^>=0.10.8.2.0
103-
, hashable ^>=1.2.7.0 || ^>=1.3.0.0 || ^>=1.4.0.1
103+
, hashable ^>=1.2.7.0 || ^>=1.3.0.0 || ^>=1.4.0.1
104104
, parsers ^>=0.12.10
105105
, primitive ^>=0.7.1.0
106106
, QuickCheck ^>=2.14.2
@@ -111,7 +111,7 @@ library
111111
, these ^>=1.1.1.1
112112
, unordered-containers ^>=0.2.8.0
113113
, uuid-types ^>=1.0.3
114-
, vector ^>=0.12.0.0 || ^>=0.13.0.0
114+
, vector ^>=0.12.0.0 || ^>=0.13.0.0
115115

116116
if impl(ghc <7.5)
117117
build-depends: ghc-prim
@@ -128,6 +128,9 @@ library
128128
, transformers ^>=0.3.0.0 || ^>=0.4.2.0 || ^>=0.5.2.0
129129
, void ^>=0.7.3
130130

131+
if impl(ghc >= 8) && !impl(ghc >=9.4)
132+
build-depends: data-array-byte >=0.1.0.1 && <0.2
133+
131134
other-extensions:
132135
CPP
133136
ConstraintKinds
@@ -160,16 +163,17 @@ test-suite tree-diff-test
160163
, QuickCheck
161164
, tagged
162165
, tree-diff
166+
, unordered-containers
163167

164168
if impl(ghc <7.5)
165169
build-depends: ghc-prim
166170

167171
-- extra dependencies
168172
build-depends:
169-
, tasty ^>=1.2 || ^>=1.3.1 || ^>=1.4.2
173+
, tasty ^>=1.2 || ^>=1.3.1 || ^>=1.4.2
170174
, tasty-golden ^>=2.3.1.1
171175
, tasty-quickcheck ^>=0.10.1
172-
, trifecta >=2 && <2.2
176+
, trifecta >=2 && <2.2
173177

174178
benchmark tree-diff-bench
175179
default-language: Haskell2010

0 commit comments

Comments
 (0)