@@ -19,12 +19,12 @@ import Test.Tasty.HUnit
19
19
import Control.Exception (bracket , try , finally , SomeException )
20
20
import Control.Monad (void )
21
21
import qualified Data.BitVector.Sized as BV
22
- import qualified Data.ByteString as BS
23
22
import Data.Char ( toLower )
24
23
import Data.Foldable
25
24
import qualified Data.List as L
26
25
import qualified Data.Map as Map
27
26
import Data.Maybe ( catMaybes , fromMaybe )
27
+ import qualified Data.Text as Text
28
28
import System.Environment ( lookupEnv )
29
29
import System.Exit ( ExitCode (.. ) )
30
30
import System.Process ( readProcessWithExitCode )
@@ -634,14 +634,14 @@ stringTest1 ::
634
634
SolverProcess t solver ->
635
635
IO ()
636
636
stringTest1 sym solver =
637
- do let bsx = " asdf\n asdf"
638
- let bsz = " qwe\x1c rty "
639
- let bsw = " QQ\" QQ"
637
+ do let bsx = " asdf\n asdf" -- length 9
638
+ let bsz = " qwe\x1c \& rty " -- length 7
639
+ let bsw = " QQ\" QQ" -- length 5
640
640
641
- x <- stringLit sym (Char8Literal bsx)
642
- y <- freshConstant sym (userSymbol' " str" ) (BaseStringRepr Char8Repr )
643
- z <- stringLit sym (Char8Literal bsz)
644
- w <- stringLit sym (Char8Literal bsw)
641
+ x <- stringLit sym (UnicodeLiteral bsx)
642
+ y <- freshConstant sym (userSymbol' " str" ) (BaseStringRepr UnicodeRepr )
643
+ z <- stringLit sym (UnicodeLiteral bsz)
644
+ w <- stringLit sym (UnicodeLiteral bsw)
645
645
646
646
s <- stringConcat sym x =<< stringConcat sym y z
647
647
s' <- stringConcat sym s w
@@ -653,12 +653,12 @@ stringTest1 sym solver =
653
653
654
654
checkSatisfiableWithModel solver " test" p $ \ case
655
655
Sat fn ->
656
- do Char8Literal slit <- groundEval fn s'
656
+ do UnicodeLiteral slit <- groundEval fn s'
657
657
llit <- groundEval fn n
658
658
659
- (fromIntegral (BS .length slit) == llit) @? " model string length"
660
- BS . isPrefixOf bsx slit @? " prefix check"
661
- BS . isSuffixOf (bsz <> bsw) slit @? " suffix check"
659
+ (fromIntegral (Text .length slit) == llit) @? " model string length"
660
+ Text . isPrefixOf bsx slit @? " prefix check"
661
+ Text . isSuffixOf (bsz <> bsw) slit @? " suffix check"
662
662
663
663
_ -> fail " expected satisfiable model"
664
664
@@ -675,17 +675,17 @@ stringTest2 ::
675
675
IO ()
676
676
stringTest2 sym solver =
677
677
do let bsx = " asdf\n asdf"
678
- let bsz = " qwe\x1c rty "
678
+ let bsz = " qwe\x1c \& rty "
679
679
let bsw = " QQ\" QQ"
680
680
681
681
q <- freshConstant sym (userSymbol' " q" ) BaseBoolRepr
682
682
683
- x <- stringLit sym (Char8Literal bsx)
684
- z <- stringLit sym (Char8Literal bsz)
685
- w <- stringLit sym (Char8Literal bsw)
683
+ x <- stringLit sym (UnicodeLiteral bsx)
684
+ z <- stringLit sym (UnicodeLiteral bsz)
685
+ w <- stringLit sym (UnicodeLiteral bsw)
686
686
687
- a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr Char8Repr )
688
- b <- freshConstant sym (userSymbol' " strb" ) (BaseStringRepr Char8Repr )
687
+ a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr UnicodeRepr )
688
+ b <- freshConstant sym (userSymbol' " strb" ) (BaseStringRepr UnicodeRepr )
689
689
690
690
ax <- stringConcat sym x a
691
691
@@ -716,19 +716,19 @@ stringTest3 ::
716
716
SolverProcess t solver ->
717
717
IO ()
718
718
stringTest3 sym solver =
719
- do let bsz = " qwe\x1c rtyQQ \" QQ"
720
- z <- stringLit sym (Char8Literal bsz)
719
+ do let bsz = " qwe\x1c \& rtyQQ \" QQ"
720
+ z <- stringLit sym (UnicodeLiteral bsz)
721
721
722
- a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr Char8Repr )
723
- b <- freshConstant sym (userSymbol' " strb" ) (BaseStringRepr Char8Repr )
724
- c <- freshConstant sym (userSymbol' " strc" ) (BaseStringRepr Char8Repr )
722
+ a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr UnicodeRepr )
723
+ b <- freshConstant sym (userSymbol' " strb" ) (BaseStringRepr UnicodeRepr )
724
+ c <- freshConstant sym (userSymbol' " strc" ) (BaseStringRepr UnicodeRepr )
725
725
726
726
pfx <- stringIsPrefixOf sym a z
727
727
sfx <- stringIsSuffixOf sym b z
728
728
729
729
cnt1 <- stringContains sym z c
730
- cnt2 <- notPred sym =<< stringContains sym c =<< stringLit sym (Char8Literal " Q" )
731
- cnt3 <- notPred sym =<< stringContains sym c =<< stringLit sym (Char8Literal " q" )
730
+ cnt2 <- notPred sym =<< stringContains sym c =<< stringLit sym (UnicodeLiteral " Q" )
731
+ cnt3 <- notPred sym =<< stringContains sym c =<< stringLit sym (UnicodeLiteral " q" )
732
732
cnt <- andPred sym cnt1 =<< andPred sym cnt2 cnt3
733
733
734
734
lena <- stringLength sym a
@@ -748,13 +748,13 @@ stringTest3 sym solver =
748
748
749
749
checkSatisfiableWithModel solver " test" p $ \ case
750
750
Sat fn ->
751
- do alit <- fromChar8Lit <$> groundEval fn a
752
- blit <- fromChar8Lit <$> groundEval fn b
753
- clit <- fromChar8Lit <$> groundEval fn c
751
+ do alit <- fromUnicodeLit <$> groundEval fn a
752
+ blit <- fromUnicodeLit <$> groundEval fn b
753
+ clit <- fromUnicodeLit <$> groundEval fn c
754
754
755
- alit == (BS .take 9 bsz) @? " correct prefix"
756
- blit == (BS .drop (BS .length bsz - 9 ) bsz) @? " correct suffix"
757
- clit == (BS .take 6 (BS .drop 1 bsz)) @? " correct middle"
755
+ alit == (Text .take 9 bsz) @? " correct prefix"
756
+ blit == (Text .drop (Text .length bsz - 9 ) bsz) @? " correct suffix"
757
+ clit == (Text .take 6 (Text .drop 1 bsz)) @? " correct middle"
758
758
759
759
_ -> fail " expected satisfable model"
760
760
@@ -766,19 +766,19 @@ stringTest4 ::
766
766
IO ()
767
767
stringTest4 sym solver =
768
768
do let bsx = " str"
769
- x <- stringLit sym (Char8Literal bsx)
770
- a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr Char8Repr )
769
+ x <- stringLit sym (UnicodeLiteral bsx)
770
+ a <- freshConstant sym (userSymbol' " stra" ) (BaseStringRepr UnicodeRepr )
771
771
i <- stringIndexOf sym a x =<< intLit sym 5
772
772
773
773
zero <- intLit sym 0
774
774
p <- intLe sym zero i
775
775
776
776
checkSatisfiableWithModel solver " test" p $ \ case
777
777
Sat fn ->
778
- do alit <- fromChar8Lit <$> groundEval fn a
778
+ do alit <- fromUnicodeLit <$> groundEval fn a
779
779
ilit <- groundEval fn i
780
780
781
- BS . isPrefixOf bsx (BS .drop (fromIntegral ilit) alit) @? " correct index"
781
+ Text . isPrefixOf bsx (Text .drop (fromIntegral ilit) alit) @? " correct index"
782
782
ilit >= 5 @? " index large enough"
783
783
784
784
_ -> fail " expected satisfable model"
@@ -791,10 +791,10 @@ stringTest4 sym solver =
791
791
792
792
checkSatisfiableWithModel solver " test" q $ \ case
793
793
Sat fn ->
794
- do alit <- fromChar8Lit <$> groundEval fn a
794
+ do alit <- fromUnicodeLit <$> groundEval fn a
795
795
ilit <- groundEval fn i
796
796
797
- not (BS . isInfixOf bsx (BS .drop 5 alit)) @? " substring not found"
797
+ not (Text . isInfixOf bsx (Text .drop 5 alit)) @? " substring not found"
798
798
ilit == (- 1 ) @? " expected neg one"
799
799
800
800
_ -> fail " expected satisfable model"
@@ -805,7 +805,7 @@ stringTest5 ::
805
805
SolverProcess t solver ->
806
806
IO ()
807
807
stringTest5 sym solver =
808
- do a <- freshConstant sym (userSymbol' " a" ) (BaseStringRepr Char8Repr )
808
+ do a <- freshConstant sym (userSymbol' " a" ) (BaseStringRepr UnicodeRepr )
809
809
off <- freshConstant sym (userSymbol' " off" ) BaseIntegerRepr
810
810
len <- freshConstant sym (userSymbol' " len" ) BaseIntegerRepr
811
811
@@ -815,19 +815,19 @@ stringTest5 sym solver =
815
815
let qlit = " qwerty"
816
816
817
817
sub <- stringSubstring sym a off len
818
- p1 <- stringEq sym sub =<< stringLit sym (Char8Literal qlit)
818
+ p1 <- stringEq sym sub =<< stringLit sym (UnicodeLiteral qlit)
819
819
p2 <- intLe sym n5 off
820
820
p3 <- intLe sym n20 =<< stringLength sym a
821
821
822
822
p <- andPred sym p1 =<< andPred sym p2 p3
823
823
824
824
checkSatisfiableWithModel solver " test" p $ \ case
825
825
Sat fn ->
826
- do alit <- fromChar8Lit <$> groundEval fn a
826
+ do alit <- fromUnicodeLit <$> groundEval fn a
827
827
offlit <- groundEval fn off
828
828
lenlit <- groundEval fn len
829
829
830
- let q = BS .take (fromIntegral lenlit) (BS .drop (fromIntegral offlit) alit)
830
+ let q = Text .take (fromIntegral lenlit) (Text .drop (fromIntegral offlit) alit)
831
831
832
832
q == qlit @? " correct substring"
833
833
@@ -1007,8 +1007,7 @@ main = do
1007
1007
1008
1008
, testCase " Z3 string1" $ withOnlineZ3 stringTest1
1009
1009
, testCase " Z3 string2" $ withOnlineZ3 stringTest2
1010
- , ignoreTestBecause " https://github.com/GaloisInc/what4/issues/56 needs to be fixed" $
1011
- testCase " Z3 string3" $ withOnlineZ3 stringTest3
1010
+ , testCase " Z3 string3" $ withOnlineZ3 stringTest3
1012
1011
, testCase " Z3 string4" $ withOnlineZ3 stringTest4
1013
1012
, testCase " Z3 string5" $ withOnlineZ3 stringTest5
1014
1013
@@ -1021,17 +1020,15 @@ main = do
1021
1020
]
1022
1021
let cvc4Tests =
1023
1022
[
1024
- -- TODO, enable this test when we figure out why it
1025
- -- doesnt work...
1026
- -- , testCase "CVC4 0-tuple" $ withCVC4 zeroTupleTest
1027
- testCase " CVC4 1-tuple" $ withCVC4 oneTupleTest
1023
+ ignoreTestBecause " This test stalls the solver for some reason; line-buffering issue?" $
1024
+ testCase " CVC4 0-tuple" $ withCVC4 zeroTupleTest
1025
+ , testCase " CVC4 1-tuple" $ withCVC4 oneTupleTest
1028
1026
, testCase " CVC4 pair" $ withCVC4 pairTest
1029
1027
, testCase " CVC4 forall binder" $ withCVC4 forallTest
1030
1028
1031
1029
, testCase " CVC4 string1" $ withCVC4 stringTest1
1032
1030
, testCase " CVC4 string2" $ withCVC4 stringTest2
1033
- , ignoreTestBecause " https://github.com/GaloisInc/what4/issues/56 needs to be fixed" $
1034
- testCase " CVC4 string3" $ withCVC4 stringTest3
1031
+ , testCase " CVC4 string3" $ withCVC4 stringTest3
1035
1032
, testCase " CVC4 string4" $ withCVC4 stringTest4
1036
1033
, testCase " CVC4 string5" $ withCVC4 stringTest5
1037
1034
0 commit comments