Skip to content

Commit 37fee69

Browse files
committed
Update the string tests to use unicode strings instead.
Reenable the prevsiouly-broken stringTest3. Fixes #132.
1 parent d1e0e32 commit 37fee69

File tree

1 file changed

+46
-49
lines changed

1 file changed

+46
-49
lines changed

what4/test/ExprBuilderSMTLib2.hs

+46-49
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import Test.Tasty.HUnit
1919
import Control.Exception (bracket, try, finally, SomeException)
2020
import Control.Monad (void)
2121
import qualified Data.BitVector.Sized as BV
22-
import qualified Data.ByteString as BS
2322
import Data.Char ( toLower )
2423
import Data.Foldable
2524
import qualified Data.List as L
2625
import qualified Data.Map as Map
2726
import Data.Maybe ( catMaybes, fromMaybe )
27+
import qualified Data.Text as Text
2828
import System.Environment ( lookupEnv )
2929
import System.Exit ( ExitCode(..) )
3030
import System.Process ( readProcessWithExitCode )
@@ -634,14 +634,14 @@ stringTest1 ::
634634
SolverProcess t solver ->
635635
IO ()
636636
stringTest1 sym solver =
637-
do let bsx = "asdf\nasdf"
638-
let bsz = "qwe\x1crty"
639-
let bsw = "QQ\"QQ"
637+
do let bsx = "asdf\nasdf" -- length 9
638+
let bsz = "qwe\x1c\&rty" -- length 7
639+
let bsw = "QQ\"QQ" -- length 5
640640

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)
645645

646646
s <- stringConcat sym x =<< stringConcat sym y z
647647
s' <- stringConcat sym s w
@@ -653,12 +653,12 @@ stringTest1 sym solver =
653653

654654
checkSatisfiableWithModel solver "test" p $ \case
655655
Sat fn ->
656-
do Char8Literal slit <- groundEval fn s'
656+
do UnicodeLiteral slit <- groundEval fn s'
657657
llit <- groundEval fn n
658658

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"
662662

663663
_ -> fail "expected satisfiable model"
664664

@@ -675,17 +675,17 @@ stringTest2 ::
675675
IO ()
676676
stringTest2 sym solver =
677677
do let bsx = "asdf\nasdf"
678-
let bsz = "qwe\x1crty"
678+
let bsz = "qwe\x1c\&rty"
679679
let bsw = "QQ\"QQ"
680680

681681
q <- freshConstant sym (userSymbol' "q") BaseBoolRepr
682682

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)
686686

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)
689689

690690
ax <- stringConcat sym x a
691691

@@ -716,19 +716,19 @@ stringTest3 ::
716716
SolverProcess t solver ->
717717
IO ()
718718
stringTest3 sym solver =
719-
do let bsz = "qwe\x1crtyQQ\"QQ"
720-
z <- stringLit sym (Char8Literal bsz)
719+
do let bsz = "qwe\x1c\&rtyQQ\"QQ"
720+
z <- stringLit sym (UnicodeLiteral bsz)
721721

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)
725725

726726
pfx <- stringIsPrefixOf sym a z
727727
sfx <- stringIsSuffixOf sym b z
728728

729729
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")
732732
cnt <- andPred sym cnt1 =<< andPred sym cnt2 cnt3
733733

734734
lena <- stringLength sym a
@@ -748,13 +748,13 @@ stringTest3 sym solver =
748748

749749
checkSatisfiableWithModel solver "test" p $ \case
750750
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
754754

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"
758758

759759
_ -> fail "expected satisfable model"
760760

@@ -766,19 +766,19 @@ stringTest4 ::
766766
IO ()
767767
stringTest4 sym solver =
768768
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)
771771
i <- stringIndexOf sym a x =<< intLit sym 5
772772

773773
zero <- intLit sym 0
774774
p <- intLe sym zero i
775775

776776
checkSatisfiableWithModel solver "test" p $ \case
777777
Sat fn ->
778-
do alit <- fromChar8Lit <$> groundEval fn a
778+
do alit <- fromUnicodeLit <$> groundEval fn a
779779
ilit <- groundEval fn i
780780

781-
BS.isPrefixOf bsx (BS.drop (fromIntegral ilit) alit) @? "correct index"
781+
Text.isPrefixOf bsx (Text.drop (fromIntegral ilit) alit) @? "correct index"
782782
ilit >= 5 @? "index large enough"
783783

784784
_ -> fail "expected satisfable model"
@@ -791,10 +791,10 @@ stringTest4 sym solver =
791791

792792
checkSatisfiableWithModel solver "test" q $ \case
793793
Sat fn ->
794-
do alit <- fromChar8Lit <$> groundEval fn a
794+
do alit <- fromUnicodeLit <$> groundEval fn a
795795
ilit <- groundEval fn i
796796

797-
not (BS.isInfixOf bsx (BS.drop 5 alit)) @? "substring not found"
797+
not (Text.isInfixOf bsx (Text.drop 5 alit)) @? "substring not found"
798798
ilit == (-1) @? "expected neg one"
799799

800800
_ -> fail "expected satisfable model"
@@ -805,7 +805,7 @@ stringTest5 ::
805805
SolverProcess t solver ->
806806
IO ()
807807
stringTest5 sym solver =
808-
do a <- freshConstant sym (userSymbol' "a") (BaseStringRepr Char8Repr)
808+
do a <- freshConstant sym (userSymbol' "a") (BaseStringRepr UnicodeRepr)
809809
off <- freshConstant sym (userSymbol' "off") BaseIntegerRepr
810810
len <- freshConstant sym (userSymbol' "len") BaseIntegerRepr
811811

@@ -815,19 +815,19 @@ stringTest5 sym solver =
815815
let qlit = "qwerty"
816816

817817
sub <- stringSubstring sym a off len
818-
p1 <- stringEq sym sub =<< stringLit sym (Char8Literal qlit)
818+
p1 <- stringEq sym sub =<< stringLit sym (UnicodeLiteral qlit)
819819
p2 <- intLe sym n5 off
820820
p3 <- intLe sym n20 =<< stringLength sym a
821821

822822
p <- andPred sym p1 =<< andPred sym p2 p3
823823

824824
checkSatisfiableWithModel solver "test" p $ \case
825825
Sat fn ->
826-
do alit <- fromChar8Lit <$> groundEval fn a
826+
do alit <- fromUnicodeLit <$> groundEval fn a
827827
offlit <- groundEval fn off
828828
lenlit <- groundEval fn len
829829

830-
let q = BS.take (fromIntegral lenlit) (BS.drop (fromIntegral offlit) alit)
830+
let q = Text.take (fromIntegral lenlit) (Text.drop (fromIntegral offlit) alit)
831831

832832
q == qlit @? "correct substring"
833833

@@ -1007,8 +1007,7 @@ main = do
10071007

10081008
, testCase "Z3 string1" $ withOnlineZ3 stringTest1
10091009
, 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
10121011
, testCase "Z3 string4" $ withOnlineZ3 stringTest4
10131012
, testCase "Z3 string5" $ withOnlineZ3 stringTest5
10141013

@@ -1021,17 +1020,15 @@ main = do
10211020
]
10221021
let cvc4Tests =
10231022
[
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
10281026
, testCase "CVC4 pair" $ withCVC4 pairTest
10291027
, testCase "CVC4 forall binder" $ withCVC4 forallTest
10301028

10311029
, testCase "CVC4 string1" $ withCVC4 stringTest1
10321030
, 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
10351032
, testCase "CVC4 string4" $ withCVC4 stringTest4
10361033
, testCase "CVC4 string5" $ withCVC4 stringTest5
10371034

0 commit comments

Comments
 (0)