1
1
# SPDX-License-Identifier: MIT
2
2
3
+ include (" compat.jl" )
4
+
3
5
module runtests
4
6
5
- using AutoHashEquals: @auto_hash_equals
7
+ using AutoHashEquals: AutoHashEquals, @auto_hash_equals
6
8
using Markdown: plain
7
9
using Match: Match, @match , MatchFailure
8
10
using Random
@@ -23,15 +25,6 @@ macro noop(x)
23
25
esc (x)
24
26
end
25
27
26
- macro _const (x)
27
- # const fields were introduced in Julia 1.8
28
- if VERSION >= v " 1.8"
29
- esc (Expr (:const , x))
30
- else
31
- esc (x)
32
- end
33
- end
34
-
35
28
"""
36
29
@auto_hash_equals_cached struct Foo ... end
37
30
@@ -114,14 +107,12 @@ abstract type B{T} end
114
107
end
115
108
116
109
@testset " the macro sees through `const`" begin
117
- if VERSION >= v " 1.8"
118
- T33 = eval (:(@auto_hash_equals mutable struct T33
119
- @_const x
120
- end ))
121
- @test T33 (1 ) == T33 (1 )
122
- @test hash (T33 (1 )) == hash (T33 (1 ))
123
- @test hash (T33 (1 )) != hash (T33 (2 ))
124
- end
110
+ T33 = eval (:(@auto_hash_equals mutable struct T33
111
+ const x
112
+ end ))
113
+ @test T33 (1 ) == T33 (1 )
114
+ @test hash (T33 (1 )) == hash (T33 (1 ))
115
+ @test hash (T33 (1 )) != hash (T33 (2 ))
125
116
end
126
117
127
118
@testset " misuse of the macro" begin
@@ -288,12 +279,7 @@ abstract type B{T} end
288
279
end
289
280
290
281
# @test_throws requires a type before v1.8.
291
- internal_constructor_error =
292
- if VERSION >= v " 1.7"
293
- ErrorException
294
- else
295
- LoadError
296
- end
282
+ internal_constructor_error = ErrorException
297
283
298
284
@testset " give an error if the struct contains internal constructors 1" begin
299
285
@test_throws internal_constructor_error begin
@@ -663,89 +649,49 @@ abstract type B{T} end
663
649
x
664
650
end
665
651
666
- if VERSION < v " 1.7"
667
- @test 0x67d66c8ebce604c4 === hash (Box1 (1 ))
668
- @test 0x57ce10fa6d65774c === hash (Box1 (:x ))
669
- @test 0x7951851906420162 === hash (Box1 (" a" ))
670
- @test 0x6a46c6ef41c6b97d === hash (Box1 (1 ), UInt (1 ))
671
- @test 0x0ef668a2dd4500a0 === hash (Box1 (:x ), UInt (1 ))
672
- @test 0x7398684da66deba5 === hash (Box1 (" a" ), UInt (1 ))
673
- else
674
- @test 0x05014b35fc91d289 === hash (Box1 (1 ))
675
- @test 0x91d7652c7a24efb3 === hash (Box1 (:x ))
676
- @test 0x1d9ac96f957cc50a === hash (Box1 (" a" ))
677
- @test 0x6e0378444e962be8 === hash (Box1 (1 ), UInt (1 ))
678
- @test 0xa31a1cd3c72d944c === hash (Box1 (:x ), UInt (1 ))
679
- @test 0xe563b59c847e3d2f === hash (Box1 (" a" ), UInt (1 ))
680
- end
652
+ @test 0x05014b35fc91d289 === hash (Box1 (1 ))
653
+ @test 0x91d7652c7a24efb3 === hash (Box1 (:x ))
654
+ @test 0x1d9ac96f957cc50a === hash (Box1 (" a" ))
655
+ @test 0x6e0378444e962be8 === hash (Box1 (1 ), UInt (1 ))
656
+ @test 0xa31a1cd3c72d944c === hash (Box1 (:x ), UInt (1 ))
657
+ @test 0xe563b59c847e3d2f === hash (Box1 (" a" ), UInt (1 ))
681
658
682
659
@auto_hash_equals struct Box2{T}
683
660
x:: T
684
661
end
685
662
686
- if VERSION < v " 1.7"
687
- @test 0x97e8e85cce6400e5 === hash (Box2 (1 ))
688
- @test 0x97e8e85cce6400e5 === hash (Box2 {Any} (1 ))
689
- @test 0x95c1c5ce8a9d4310 === hash (Box2 (:x ))
690
- @test 0x9424a3ad9ea0312c === hash (Box2 (" a" ))
691
- @test 0xd7caed9a4e280b13 === hash (Box2 (1 ), UInt (1 ))
692
- @test 0xd7caed9a4e280b13 === hash (Box2 {Any} (1 ), UInt (1 ))
693
- @test 0x3c6236446852acfb === hash (Box2 (:x ), UInt (1 ))
694
- @test 0x08aaed0ddd68f482 === hash (Box2 (" a" ), UInt (1 ))
695
- else
696
- @test 0xfddfe30b106aa2f0 === hash (Box2 (1 ))
697
- @test 0xfddfe30b106aa2f0 === hash (Box2 {Any} (1 ))
698
- @test 0xb9abdfa5883b32bb === hash (Box2 (:x ))
699
- @test 0x6c49b14653a071c6 === hash (Box2 (" a" ))
700
- @test 0x451b0ebf9ee0f99c === hash (Box2 (1 ), UInt (1 ))
701
- @test 0x451b0ebf9ee0f99c === hash (Box2 {Any} (1 ), UInt (1 ))
702
- @test 0x175e9079609f34c5 === hash (Box2 (:x ), UInt (1 ))
703
- @test 0x77cf64ab93060d1e === hash (Box2 (" a" ), UInt (1 ))
704
- end
663
+ @test 0xfddfe30b106aa2f0 === hash (Box2 (1 ))
664
+ @test 0xfddfe30b106aa2f0 === hash (Box2 {Any} (1 ))
665
+ @test 0xb9abdfa5883b32bb === hash (Box2 (:x ))
666
+ @test 0x6c49b14653a071c6 === hash (Box2 (" a" ))
667
+ @test 0x451b0ebf9ee0f99c === hash (Box2 (1 ), UInt (1 ))
668
+ @test 0x451b0ebf9ee0f99c === hash (Box2 {Any} (1 ), UInt (1 ))
669
+ @test 0x175e9079609f34c5 === hash (Box2 (:x ), UInt (1 ))
670
+ @test 0x77cf64ab93060d1e === hash (Box2 (" a" ), UInt (1 ))
705
671
706
672
@auto_hash_equals struct Box3
707
673
x
708
674
end
709
675
710
- if VERSION < v " 1.7"
711
- @test 0xa28c5530534e00ff === hash (Box3 (1 ))
712
- @test 0xbd098dc8d84b2b3c === hash (Box3 (:x ))
713
- @test 0x306232d62b351152 === hash (Box3 (" a" ))
714
- @test 0xd4f16da2b818329f === hash (Box3 (1 ), UInt (1 ))
715
- @test 0xbc02b85a84d59f22 === hash (Box3 (:x ), UInt (1 ))
716
- @test 0xf3298984f3d3f10e === hash (Box3 (" a" ), UInt (1 ))
717
- else
718
- @test 0x6c8a62ecebe7d0ce === hash (Box3 (1 ))
719
- @test 0xb3dc0f774c8dbf65 === hash (Box3 (:x ))
720
- @test 0x18c77bdc2543b944 === hash (Box3 (" a" ))
721
- @test 0x1fe5e7cdd29edab1 === hash (Box3 (1 ), UInt (1 ))
722
- @test 0x55e8647bf53d5ecd === hash (Box3 (:x ), UInt (1 ))
723
- @test 0xf556f204c1f1bc53 === hash (Box3 (" a" ), UInt (1 ))
724
- end
676
+ @test 0x6c8a62ecebe7d0ce === hash (Box3 (1 ))
677
+ @test 0xb3dc0f774c8dbf65 === hash (Box3 (:x ))
678
+ @test 0x18c77bdc2543b944 === hash (Box3 (" a" ))
679
+ @test 0x1fe5e7cdd29edab1 === hash (Box3 (1 ), UInt (1 ))
680
+ @test 0x55e8647bf53d5ecd === hash (Box3 (:x ), UInt (1 ))
681
+ @test 0xf556f204c1f1bc53 === hash (Box3 (" a" ), UInt (1 ))
725
682
726
683
@auto_hash_equals struct Box4{T}
727
684
x:: T
728
685
end
729
686
730
- if VERSION < v " 1.7"
731
- @test 0xa0164c66e926af40 === hash (Box4 (1 ))
732
- @test 0xa0164c66e926af40 === hash (Box4 {Any} (1 ))
733
- @test 0xcb0ce1b2da05840b === hash (Box4 (:x ))
734
- @test 0xc10479084e27e5db === hash (Box4 (" a" ))
735
- @test 0xdbc4ab0260836c4a === hash (Box4 (1 ), UInt (1 ))
736
- @test 0xdbc4ab0260836c4a === hash (Box4 {Any} (1 ), UInt (1 ))
737
- @test 0x485f0ce7fd57b390 === hash (Box4 (:x ), UInt (1 ))
738
- @test 0xaff3b9595e40223d === hash (Box4 (" a" ), UInt (1 ))
739
- else
740
- @test 0x98dc0cd9a86cbdee === hash (Box4 (1 ))
741
- @test 0x98dc0cd9a86cbdee === hash (Box4 {Any} (1 ))
742
- @test 0x3dbd99c859966133 === hash (Box4 (:x ))
743
- @test 0xa7d6e8579ef5a8cd === hash (Box4 (" a" ))
744
- @test 0x44ac08ef000cb686 === hash (Box4 (1 ), UInt (1 ))
745
- @test 0x44ac08ef000cb686 === hash (Box4 {Any} (1 ), UInt (1 ))
746
- @test 0xc7dc8347992b452d === hash (Box4 (:x ), UInt (1 ))
747
- @test 0x3dcb6b6168a2c18d === hash (Box4 (" a" ), UInt (1 ))
748
- end
687
+ @test 0x98dc0cd9a86cbdee === hash (Box4 (1 ))
688
+ @test 0x98dc0cd9a86cbdee === hash (Box4 {Any} (1 ))
689
+ @test 0x3dbd99c859966133 === hash (Box4 (:x ))
690
+ @test 0xa7d6e8579ef5a8cd === hash (Box4 (" a" ))
691
+ @test 0x44ac08ef000cb686 === hash (Box4 (1 ), UInt (1 ))
692
+ @test 0x44ac08ef000cb686 === hash (Box4 {Any} (1 ), UInt (1 ))
693
+ @test 0xc7dc8347992b452d === hash (Box4 (:x ), UInt (1 ))
694
+ @test 0x3dcb6b6168a2c18d === hash (Box4 (" a" ), UInt (1 ))
749
695
750
696
end
751
697
@@ -806,7 +752,7 @@ abstract type B{T} end
806
752
w:: T
807
753
end
808
754
@test hash (S640 {Int} (1 )) == hash (1 , hash (S640{Int}))
809
- @test hash (S640 {Int} (1 ), UInt (2 )) == hash (1 , UInt ( 2 ) + hash (S640{Int}))
755
+ @test hash (S640 {Int} (1 ), UInt (2 )) == hash (1 , hash (S640{Int}, UInt ( 2 ) ))
810
756
end
811
757
812
758
@testset " test typearg=false typeseed=K generic type" begin
@@ -822,7 +768,7 @@ abstract type B{T} end
822
768
w
823
769
end
824
770
@test hash (S650 (1 )) == hash (1 , hash (S650))
825
- @test hash (S650 (1 ), UInt (2 )) == hash (1 , UInt (2 ) + hash (S650 ))
771
+ @test hash (S650 (1 ), UInt (2 )) == hash (1 , hash (S650, UInt (2 )))
826
772
end
827
773
828
774
@testset " test typearg=false typeseed=e non-generic type" begin
@@ -902,6 +848,7 @@ abstract type B{T} end
902
848
@test Box891 (missing ) != Box891 (1 )
903
849
@test ! isequal (Box891 (missing ), Box891 (1 ))
904
850
end
851
+
905
852
end
906
853
end
907
854
0 commit comments