diff --git a/glean/schema/cpp/schema.h b/glean/schema/cpp/schema.h index 393d3403c..09cf27abb 100644 --- a/glean/schema/cpp/schema.h +++ b/glean/schema/cpp/schema.h @@ -14583,7 +14583,7 @@ template<> struct Repr_ struct Repr_ { - using Type = Tuple>, Tuple, Sum, Enum<3>, Repr, Repr, Repr, Array, Array, Array, Array, Array, Array>, Array>, Array>, Array>, Array>, Array>, Array>>; + using Type = Tuple>, Tuple, Sum, Enum<3>, Repr, Repr, Repr, Array, Array, Array, Array, Array, Array>, Array>, Array>, Array>, Array>, Array>, Array>, Set, Set, Set>; }; @@ -14618,33 +14618,36 @@ struct KitchenSink { std::vector array2_of_nat; std::vector array2_of_bool; std::vector array2_of_string; + std::set set_of_nat; + std::set set_of_string; + std::set> set_of_pred; bool operator==(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - == std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + == std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } bool operator!=(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - != std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + != std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } bool operator<(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - < std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + < std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } bool operator<=(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - <= std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + <= std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } bool operator>(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - > std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + > std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } bool operator>=(const KitchenSink& other) const { - return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string) - >= std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string); + return std::tie(byt,nat,bool_,string_,pred,maybe_,record_,sum_,enum_,named_record_,named_sum_,named_enum_,array_of_byte,array_of_nat,array_of_bool,array_of_string,array_of_pred,array_of_named_record,array_of_named_sum,array_of_named_enum,array2_of_byte,array2_of_nat,array2_of_bool,array2_of_string,set_of_nat,set_of_string,set_of_pred) + >= std::tie(other.byt,other.nat,other.bool_,other.string_,other.pred,other.maybe_,other.record_,other.sum_,other.enum_,other.named_record_,other.named_sum_,other.named_enum_,other.array_of_byte,other.array_of_nat,other.array_of_bool,other.array_of_string,other.array_of_pred,other.array_of_named_record,other.array_of_named_sum,other.array_of_named_enum,other.array2_of_byte,other.array2_of_nat,other.array2_of_bool,other.array2_of_string,other.set_of_nat,other.set_of_string,other.set_of_pred); } void outputRepr(Output> out) const { - outputValue(out, std::make_tuple(byt, nat, bool_, string_, pred, maybe_, record_, sum_, enum_, named_record_, named_sum_, named_enum_, array_of_byte, array_of_nat, array_of_bool, array_of_string, array_of_pred, array_of_named_record, array_of_named_sum, array_of_named_enum, array2_of_byte, array2_of_nat, array2_of_bool, array2_of_string)); + outputValue(out, std::make_tuple(byt, nat, bool_, string_, pred, maybe_, record_, sum_, enum_, named_record_, named_sum_, named_enum_, array_of_byte, array_of_nat, array_of_bool, array_of_string, array_of_pred, array_of_named_record, array_of_named_sum, array_of_named_enum, array2_of_byte, array2_of_nat, array2_of_bool, array2_of_string, set_of_nat, set_of_string, set_of_pred)); } }; // struct KitchenSink diff --git a/glean/schema/source/test.angle b/glean/schema/source/test.angle index f46662f30..c7717fbb6 100644 --- a/glean/schema/source/test.angle +++ b/glean/schema/source/test.angle @@ -209,6 +209,9 @@ type KitchenSink = array2_of_nat : [ArrayNat], array2_of_bool : [ArrayBool], array2_of_string : [ArrayString], + set_of_nat : set nat, + set_of_string : set string, + set_of_pred : set Predicate, } predicate Predicate : KitchenSink @@ -276,4 +279,3 @@ predicate Qux : string predicate FooToFoo : Foo -> Foo } - diff --git a/glean/test/lib/TestData.hs b/glean/test/lib/TestData.hs index e82f7d5b3..14eeb356f 100644 --- a/glean/test/lib/TestData.hs +++ b/glean/test/lib/TestData.hs @@ -15,6 +15,7 @@ module TestData ) where import Data.Default +import qualified Data.Set as Set import Glean.Typed import Glean.Types @@ -42,6 +43,8 @@ kitchenSink1 = def , Glean.Test.kitchenSink_maybe_ = Just def , Glean.Test.kitchenSink_bool_ = True , Glean.Test.kitchenSink_string_ = "Hello\0world!\0" + , Glean.Test.kitchenSink_set_of_nat = Set.fromList [toNat 1, toNat 2] + , Glean.Test.kitchenSink_set_of_string = Set.fromList ["apa", "bepa"] } mkTestFacts :: NewFact m => (m () -> m ()) -> (m () -> m ()) -> m () @@ -92,8 +95,8 @@ mkTestFacts first second = do kitchenSink2Fact0b <- makeFact @Glean.Test.Predicate kitchenSink2Term0b let - -- refers to kitchenSink2Fact0 through the sum_ field and the - -- array_of_pred field + -- refers to kitchenSink2Fact0 through the sum_ field, the + -- array_of_pred field and the set_of_pred field. kitchenSink2Term1 = def { Glean.Test.kitchenSink_pred = sysBlobFact2 , Glean.Test.kitchenSink_sum_ = @@ -104,6 +107,7 @@ mkTestFacts first second = do , Glean.Test.kitchenSink_named_sum_ = Glean.Test.Sum_wed True , Glean.Test.kitchenSink_named_record_ = rec , Glean.Test.kitchenSink_maybe_ = Nothing + , Glean.Test.kitchenSink_set_of_pred = Set.fromList [kitchenSink2Fact0] } kitchenSink2Term1b = kitchenSink2Term1 diff --git a/glean/test/tests/Angle/AngleTest.hs b/glean/test/tests/Angle/AngleTest.hs index 8d96b5489..28aee2e73 100644 --- a/glean/test/tests/Angle/AngleTest.hs +++ b/glean/test/tests/Angle/AngleTest.hs @@ -42,6 +42,7 @@ main = withUnitTest $ testRunner $ TestList , TestLabel "angleIfThenElse" $ angleIfThenElse id , TestLabel "angleIfThenElse/page" $ angleIfThenElse (limit 1) , TestLabel "angleTypeTest" angleTypeTest + , TestLabel "angleSet" angleSetTest ] ignorePredK :: Glean.Test.KitchenSink -> Glean.Test.KitchenSink @@ -979,3 +980,10 @@ angleTypeTest = dbTestCase $ \env repo -> do |] print r assertEqual "angle - inference 6" 1 (length r) + +angleSetTest :: Test +angleSetTest = dbTestCase $ \env repo -> do + r <- runQuery_ env repo $ angleData @Glean.Test.Predicate + [s| glean.test.Predicate { set_of_string = all ("bepa" | "apa") } |] + print r + assertEqual "angle - set matching" 2 (length r) diff --git a/glean/test/tests/EncodingTest.hs b/glean/test/tests/EncodingTest.hs index 251defccd..90e758c3c 100644 --- a/glean/test/tests/EncodingTest.hs +++ b/glean/test/tests/EncodingTest.hs @@ -14,6 +14,7 @@ import qualified Data.ByteString.Base16 as Hex import qualified Data.ByteString.Char8 as ByteString import Data.Default import Data.IntMap.Strict (IntMap) +import qualified Data.Set as Set import Foreign.C.String import Foreign.C.Types import Foreign.Ptr @@ -88,6 +89,12 @@ kitchenSink = KitchenSink , [ False ] ] , kitchenSink_array2_of_string = [ [ "a", "bc", "def" ] ] + , kitchenSink_set_of_nat = + Set.fromList [ Nat 1, Nat 3 ] + , kitchenSink_set_of_string = + Set.fromList [ "foo", "bar" ] + , kitchenSink_set_of_pred = + Set.fromList [ Glean.Test.Predicate 5432 Nothing ] } data E = E diff --git a/glean/test/tests/RTSTest.hs b/glean/test/tests/RTSTest.hs index e86f9d2c7..ac12ec202 100644 --- a/glean/test/tests/RTSTest.hs +++ b/glean/test/tests/RTSTest.hs @@ -48,6 +48,7 @@ instance Arbitrary Type where , pure T.NatTy , pure T.StringTy , T.ArrayTy <$> arbitrary + , T.SetTy <$> arbitrary , T.RecordTy . fields <$> children 0 , T.SumTy . fields <$> children 1 , T.PredicateTy <$> arbitrary @@ -65,6 +66,22 @@ instance Arbitrary Type where fields tys = [ T.FieldDef (Text.pack $ 'x' : show (i :: Int)) ty | (i,ty) <- zip [0..] tys ] + shrink (T.ArrayTy ty) = ty : [T.ArrayTy sty | sty <- shrink ty] + shrink (T.SetTy ty) = ty : [T.SetTy sty | sty <- shrink ty] + shrink (T.RecordTy fields) = [ ty | T.FieldDef _ ty <- fields ] ++ + (T.RecordTy <$> shrinkList shrinkField fields) + shrink (T.SumTy fields) = (T.SumTy <$> + filter (not . null) (shrinkList shrinkField fields)) ++ + [ ty | T.FieldDef _ ty <- fields ] + shrink (T.EnumeratedTy enums) = T.EnumeratedTy <$> + filter (not . null) (shrinkList (const []) enums) + shrink (T.MaybeTy ty) = ty : (T.MaybeTy <$> shrink ty) + shrink _ = [] + +shrinkField + :: Arbitrary (T.Type_ pref tref) + => T.FieldDef_ pref tref -> [T.FieldDef_ pref tref] +shrinkField (T.FieldDef name ty) = T.FieldDef name <$> shrink ty valueFor :: Type -> Gen Value valueFor T.ByteTy = Byte <$> arbitrary @@ -82,7 +99,7 @@ valueFor (T.SumTy fields) = do Alt i <$> valueFor (T.fieldDefType field) valueFor (T.SetTy ty) = fmap Set $ sized $ \n -> do k <- choose (0,n) - nub <$> vectorOf k (resize (n `div` k) $ valueFor ty) + nub . sort <$> vectorOf k (resize (n `div` k) $ valueFor ty) valueFor T.PredicateTy{} = Ref <$> arbitrary valueFor (T.NamedTy (ExpandedType _ ty)) = valueFor ty valueFor (T.MaybeTy ty) = do @@ -112,8 +129,10 @@ main = withUnitTest $ testRunner $ TestList forAll arbitrary $ \ty -> forAll (valueFor ty) $ \val -> prop_roundtripValue ty val - , TestLabel "value typecheck" $ TestCase $ assertProperty "mismatch" $ - forAll arbitrary $ \ty -> + , TestLabel "value typecheck" $ TestCase $ + assertPropertyWithArgs "mismatch" stdArgs{ maxSuccess = 1000 } $ + forAllShrink arbitrary shrink $ \ty -> + collect ty $ forAll (valueFor ty) $ \val -> prop_typecheckValue ty val -- test strings more thoroughly as they are quite complicated