diff --git a/src/Sharpy.Compiler.Tests/Formatting/LineDiffTests.cs b/src/Sharpy.Compiler.Tests/Formatting/LineDiffTests.cs index 9317d9f67..bc6a23378 100644 --- a/src/Sharpy.Compiler.Tests/Formatting/LineDiffTests.cs +++ b/src/Sharpy.Compiler.Tests/Formatting/LineDiffTests.cs @@ -222,8 +222,8 @@ private static bool HasBareLineFeed(string text) // (iii) + (vi) — CsCheck over random line lists // ================================================================ - private static readonly Gen GenLines = Gen.OneOfConst("a", "b", "c", "", " d", "e e").Array[0, 14]; - private static readonly Gen GenBreak = Gen.OneOfConst("\n", "\r\n", "\r"); + private static readonly Gen GenLines = Gen.OneOf("a", "b", "c", "", " d", "e e").Array[0, 14]; + private static readonly Gen GenBreak = Gen.OneOf("\n", "\r\n", "\r"); /// (iii) + (ii): Apply(a, Hunks(a, b)) == b, and the reference diff applies to the same text. [Fact] diff --git a/src/Sharpy.Compiler.Tests/Properties/Algebraic/DictPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Algebraic/DictPropertyTests.cs index c211493bf..c4cfaa95a 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Algebraic/DictPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Algebraic/DictPropertyTests.cs @@ -15,7 +15,7 @@ public DictPropertyTests(ITestOutputHelper output) : base(output) { } [Fact] public void DictMerge_HasIdentity() { - Gen.OneOfConst("{\"a\": 1, \"b\": 2}", "{\"c\": 3}", "{}", "{\"x\": 0, \"y\": 0}").Sample(a => + Gen.OneOf("{\"a\": 1, \"b\": 2}", "{\"c\": 3}", "{}", "{\"x\": 0, \"y\": 0}").Sample(a => { var r1 = RunAndCapture($"def main():\n print(sorted(({a} | {{}}).items()))"); var r2 = RunAndCapture($"def main():\n print(sorted(({a}).items()))"); @@ -28,9 +28,9 @@ public void DictMerge_HasIdentity() public void DictMerge_IsAssociative() { Gen.Select( - Gen.OneOfConst("{\"a\": 1}", "{\"b\": 2, \"c\": 3}", "{}"), - Gen.OneOfConst("{\"d\": 4}", "{\"b\": 5, \"e\": 6}", "{}"), - Gen.OneOfConst("{\"f\": 7}", "{\"c\": 8, \"g\": 9}", "{}") + Gen.OneOf("{\"a\": 1}", "{\"b\": 2, \"c\": 3}", "{}"), + Gen.OneOf("{\"d\": 4}", "{\"b\": 5, \"e\": 6}", "{}"), + Gen.OneOf("{\"f\": 7}", "{\"c\": 8, \"g\": 9}", "{}") ).Sample((a, b, c) => { var r1 = RunAndCapture($"def main():\n print(sorted((({a} | {b}) | {c}).items()))"); @@ -44,8 +44,8 @@ public void DictMerge_IsAssociative() public void DictMerge_SizeUpperBound() { Gen.Select( - Gen.OneOfConst("{\"a\": 1, \"b\": 2}", "{\"c\": 3}", "{}"), - Gen.OneOfConst("{\"a\": 10}", "{\"d\": 4, \"e\": 5}", "{}") + Gen.OneOf("{\"a\": 1, \"b\": 2}", "{\"c\": 3}", "{}"), + Gen.OneOf("{\"a\": 10}", "{\"d\": 4, \"e\": 5}", "{}") ).Sample((a, b) => { var r = RunAndCapture( @@ -59,8 +59,8 @@ public void DictMerge_SizeUpperBound() public void DictMerge_LastWriteWins() { Gen.Select( - Gen.OneOfConst("{\"a\": 1, \"b\": 2}", "{\"a\": 100}", "{\"a\": 1, \"b\": 2, \"c\": 3}"), - Gen.OneOfConst("{\"a\": 99}", "{\"a\": 7, \"b\": 8}", "{\"b\": 50}") + Gen.OneOf("{\"a\": 1, \"b\": 2}", "{\"a\": 100}", "{\"a\": 1, \"b\": 2, \"c\": 3}"), + Gen.OneOf("{\"a\": 99}", "{\"a\": 7, \"b\": 8}", "{\"b\": 50}") ).Sample((a, b) => { // For every key present in b, the merged value must equal b's value. diff --git a/src/Sharpy.Compiler.Tests/Properties/Algebraic/ListPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Algebraic/ListPropertyTests.cs index 80075c113..cc51a82c1 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Algebraic/ListPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Algebraic/ListPropertyTests.cs @@ -15,7 +15,7 @@ public ListPropertyTests(ITestOutputHelper output) : base(output) { } [Fact] public void ListConcat_HasIdentity() { - Gen.OneOfConst("[1, 2, 3]", "[10]", "[]", "[0, 0]").Sample(xs => + Gen.OneOf("[1, 2, 3]", "[10]", "[]", "[0, 0]").Sample(xs => { var r1 = RunAndCapture($"def main():\n print({xs} + [])"); var r2 = RunAndCapture($"def main():\n print({xs})"); @@ -28,8 +28,8 @@ public void ListConcat_HasIdentity() public void ListConcat_LengthIsAdditive() { Gen.Select( - Gen.OneOfConst("[1, 2]", "[3]", "[]", "[0, 0, 0]"), - Gen.OneOfConst("[4, 5]", "[6]", "[]", "[7]") + Gen.OneOf("[1, 2]", "[3]", "[]", "[0, 0, 0]"), + Gen.OneOf("[4, 5]", "[6]", "[]", "[7]") ).Sample((a, b) => { var r = RunAndCapture( @@ -43,9 +43,9 @@ public void ListConcat_LengthIsAdditive() public void ListConcat_IsAssociative() { Gen.Select( - Gen.OneOfConst("[1]", "[2, 3]", "[]"), - Gen.OneOfConst("[4]", "[5, 6]", "[]"), - Gen.OneOfConst("[7]", "[8, 9]", "[]") + Gen.OneOf("[1]", "[2, 3]", "[]"), + Gen.OneOf("[4]", "[5, 6]", "[]"), + Gen.OneOf("[7]", "[8, 9]", "[]") ).Sample((a, b, c) => { var r1 = RunAndCapture($"def main():\n print(({a} + {b}) + {c})"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Algebraic/SetPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Algebraic/SetPropertyTests.cs index 0cd27da5a..9a104460c 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Algebraic/SetPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Algebraic/SetPropertyTests.cs @@ -15,7 +15,7 @@ public SetPropertyTests(ITestOutputHelper output) : base(output) { } [Fact] public void SetUnion_IsIdempotent() { - Gen.OneOfConst("{1, 2, 3}", "{10}", "{0, 0}").Sample(xs => + Gen.OneOf("{1, 2, 3}", "{10}", "{0, 0}").Sample(xs => { var r1 = RunAndCapture($"def main():\n print(sorted({xs} | {xs}))"); var r2 = RunAndCapture($"def main():\n print(sorted({xs}))"); @@ -28,8 +28,8 @@ public void SetUnion_IsIdempotent() public void SetUnion_IsCommutative() { Gen.Select( - Gen.OneOfConst("{1, 2}", "{3}", "{4, 5, 6}"), - Gen.OneOfConst("{2, 3}", "{7}", "{1, 8}") + Gen.OneOf("{1, 2}", "{3}", "{4, 5, 6}"), + Gen.OneOf("{2, 3}", "{7}", "{1, 8}") ).Sample((a, b) => { var r1 = RunAndCapture($"def main():\n print(sorted({a} | {b}))"); @@ -43,9 +43,9 @@ public void SetUnion_IsCommutative() public void SetUnion_IsAssociative() { Gen.Select( - Gen.OneOfConst("{1}", "{2, 3}", "{4}"), - Gen.OneOfConst("{5}", "{6, 7}", "{2}"), - Gen.OneOfConst("{8}", "{1, 9}", "{3}") + Gen.OneOf("{1}", "{2, 3}", "{4}"), + Gen.OneOf("{5}", "{6, 7}", "{2}"), + Gen.OneOf("{8}", "{1, 9}", "{3}") ).Sample((a, b, c) => { var r1 = RunAndCapture($"def main():\n print(sorted(({a} | {b}) | {c}))"); @@ -60,8 +60,8 @@ public void SetUnion_IsAssociative() public void SetDifference_RemovesElements() { Gen.Select( - Gen.OneOfConst("{1, 2}", "{3}", "{4, 5, 6}"), - Gen.OneOfConst("{2, 3}", "{7}", "{1, 8}") + Gen.OneOf("{1, 2}", "{3}", "{4, 5, 6}"), + Gen.OneOf("{2, 3}", "{7}", "{1, 8}") ).Sample((a, b) => { var r1 = RunAndCapture($"def main():\n print(sorted({a} - {b}))"); @@ -77,8 +77,8 @@ public void SetDifference_RemovesElements() public void SetIntersection_IsCommutative() { Gen.Select( - Gen.OneOfConst("{1, 2}", "{3}", "{4, 5, 6}"), - Gen.OneOfConst("{2, 3}", "{7}", "{1, 8}") + Gen.OneOf("{1, 2}", "{3}", "{4, 5, 6}"), + Gen.OneOf("{2, 3}", "{7}", "{1, 8}") ).Sample((a, b) => { var r1 = RunAndCapture($"def main():\n print(sorted({a} & {b}))"); @@ -92,8 +92,8 @@ public void SetIntersection_IsCommutative() public void SetSymmetricDifference_IsCommutative() { Gen.Select( - Gen.OneOfConst("{1, 2}", "{3}", "{4, 5, 6}"), - Gen.OneOfConst("{2, 3}", "{7}", "{1, 8}") + Gen.OneOf("{1, 2}", "{3}", "{4, 5, 6}"), + Gen.OneOf("{2, 3}", "{7}", "{1, 8}") ).Sample((a, b) => { var r1 = RunAndCapture($"def main():\n print(sorted({a} ^ {b}))"); @@ -107,9 +107,9 @@ public void SetSymmetricDifference_IsCommutative() public void DeMorgans_ForSets() { Gen.Select( - Gen.OneOfConst("{1}", "{2, 3}", "{4}"), - Gen.OneOfConst("{5}", "{6, 7}", "{2}"), - Gen.OneOfConst("{8}", "{1, 9}", "{3}") + Gen.OneOf("{1}", "{2, 3}", "{4}"), + Gen.OneOf("{5}", "{6, 7}", "{2}"), + Gen.OneOf("{8}", "{1, 9}", "{3}") ).Sample((a, b, c) => { var r1 = RunAndCapture($"def main():\n print(sorted(({a} | {b}) - {c}))"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Algebraic/StringPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Algebraic/StringPropertyTests.cs index d9967158f..0f1a41b40 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Algebraic/StringPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Algebraic/StringPropertyTests.cs @@ -15,7 +15,7 @@ public StringPropertyTests(ITestOutputHelper output) : base(output) { } [Fact] public void StringConcat_HasIdentity() { - Gen.OneOfConst("hello", "world", "test", "abc").Sample(s => + Gen.OneOf("hello", "world", "test", "abc").Sample(s => { var r1 = RunAndCapture($"def main():\n print(\"{s}\" + \"\")"); var r2 = RunAndCapture($"def main():\n print(\"{s}\")"); @@ -28,8 +28,8 @@ public void StringConcat_HasIdentity() public void StringConcat_LengthIsAdditive() { Gen.Select( - Gen.OneOfConst("hello", "world", "x", ""), - Gen.OneOfConst("foo", "bar", "y", "") + Gen.OneOf("hello", "world", "x", ""), + Gen.OneOf("foo", "bar", "y", "") ).Sample((a, b) => { var r = RunAndCapture( diff --git a/src/Sharpy.Compiler.Tests/Properties/Algebraic/TuplePropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Algebraic/TuplePropertyTests.cs index 769a9ee4f..da74d81f0 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Algebraic/TuplePropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Algebraic/TuplePropertyTests.cs @@ -16,8 +16,8 @@ public TuplePropertyTests(ITestOutputHelper output) : base(output) { } public void TupleConcat_LengthIsAdditive() { Gen.Select( - Gen.OneOfConst("(1, 2)", "(3,)", "()", "(0, 0, 0)"), - Gen.OneOfConst("(4, 5)", "(6,)", "()", "(7,)") + Gen.OneOf("(1, 2)", "(3,)", "()", "(0, 0, 0)"), + Gen.OneOf("(4, 5)", "(6,)", "()", "(7,)") ).Sample((a, b) => { var r = RunAndCapture( @@ -31,9 +31,9 @@ public void TupleConcat_LengthIsAdditive() public void TupleConcat_IsAssociative() { Gen.Select( - Gen.OneOfConst("(1,)", "(2, 3)", "()"), - Gen.OneOfConst("(4,)", "(5, 6)", "()"), - Gen.OneOfConst("(7,)", "(8, 9)", "()") + Gen.OneOf("(1,)", "(2, 3)", "()"), + Gen.OneOf("(4,)", "(5, 6)", "()"), + Gen.OneOf("(7,)", "(8, 9)", "()") ).Sample((a, b, c) => { var r1 = RunAndCapture($"def main():\n print(({a} + {b}) + {c})"); @@ -46,7 +46,7 @@ public void TupleConcat_IsAssociative() [Fact] public void TupleConcat_HasIdentity() { - Gen.OneOfConst("(1, 2, 3)", "(10,)", "()", "(0, 0)").Sample(xs => + Gen.OneOf("(1, 2, 3)", "(10,)", "()", "(0, 0)").Sample(xs => { var r1 = RunAndCapture($"def main():\n print({xs} + ())"); var r2 = RunAndCapture($"def main():\n print({xs})"); diff --git a/src/Sharpy.Compiler.Tests/Properties/CodeGen/CsCleanPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/CodeGen/CsCleanPropertyTests.cs index fd8f72ced..a53386a2e 100644 --- a/src/Sharpy.Compiler.Tests/Properties/CodeGen/CsCleanPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/CodeGen/CsCleanPropertyTests.cs @@ -48,7 +48,7 @@ public void SemanticClean_ImpliesZeroCsErrors() // GenTyped.TypedProgram already emits well-typed programs, so the filter passes // nearly every sample (wrapping the raw GenSharpy.Module generator instead makes // the filter reject ~85% of candidates and CsCheck aborts with a Where-max-count). - var baseGen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)); var sink = new RejectionSink("CsClean.SemanticClean_ImpliesZeroCsErrors"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Differential/DifferentialExecutionTests.cs b/src/Sharpy.Compiler.Tests/Properties/Differential/DifferentialExecutionTests.cs index e6abfeddf..074c50bde 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Differential/DifferentialExecutionTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Differential/DifferentialExecutionTests.cs @@ -989,9 +989,9 @@ from sv in GenLiterals.SimpleString from flagv in GenLiterals.Boolean from nums in intElem.Array[0, 3] from words in strElem.Array[0, 3] - from t1 in Gen.OneOfConst(types) + from t1 in Gen.OneOf(types) from e1 in GenTyped.ExpressionOfType(env, t1, 1) - from t2 in Gen.OneOfConst(types) + from t2 in Gen.OneOf(types) from e2 in GenTyped.ExpressionOfType(env, t2, 1) select BuildGeneratedMain(xv, yv, sv, flagv, nums.ToImmutableArray(), words.ToImmutableArray(), e1, e2); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenComments.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenComments.cs index 94a47dd66..8774f8682 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenComments.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenComments.cs @@ -90,23 +90,23 @@ internal static class GenComments }; public static Gen SourceWithLeadingComment { get; } = - Gen.OneOfConst(LeadingSources); + Gen.OneOf(LeadingSources); public static Gen SourceWithTrailingComment { get; } = - Gen.OneOfConst(TrailingSources); + Gen.OneOf(TrailingSources); public static Gen SourceWithMultipleComments { get; } = - Gen.OneOfConst(MultiCommentSources); + Gen.OneOf(MultiCommentSources); public static Gen SourceWithNestedComments { get; } = - Gen.OneOfConst(NestedSources); + Gen.OneOf(NestedSources); public static Gen SourceWithMixedComments { get; } = - Gen.OneOfConst(MixedSources); + Gen.OneOf(MixedSources); public static Gen SourceWithBlankLines { get; } = - Gen.OneOfConst(BlankLineSources); + Gen.OneOf(BlankLineSources); public static Gen CommentText { get; } = - Gen.OneOfConst(CommentTexts); + Gen.OneOf(CommentTexts); } diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenExpressions.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenExpressions.cs index 544379f05..0bdaff12c 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenExpressions.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenExpressions.cs @@ -71,7 +71,7 @@ public static Gen IdentifierExpr(GenContext ctx) => public static Gen UnaryOpExpr(GenContext ctx) => Gen.Select( - Gen.OneOfConst(UnaryOperator.Plus, UnaryOperator.Minus, UnaryOperator.Not, UnaryOperator.BitwiseNot), + Gen.OneOf(UnaryOperator.Plus, UnaryOperator.Minus, UnaryOperator.Not, UnaryOperator.BitwiseNot), Expression(ctx), (op, operand) => new UnaryOp { Operator = op, Operand = operand }); @@ -86,7 +86,7 @@ public static Gen UnaryOpExpr(GenContext ctx) => public static Gen BinaryOpExpr(GenContext ctx) => Gen.Select( - Gen.OneOfConst(SafeBinaryOps), + Gen.OneOf(SafeBinaryOps), Expression(ctx), Expression(ctx), (op, left, right) => new BinaryOp { Operator = op, Left = left, Right = right }); @@ -174,7 +174,7 @@ public static Gen SliceAccessExpr(GenContext ctx) => public static Gen ComparisonChainExpr(GenContext ctx) => Gen.Select( Expression(ctx).Array[2, 4], - Gen.OneOfConst( + Gen.OneOf( ComparisonOperator.Equal, ComparisonOperator.NotEqual, ComparisonOperator.LessThan, ComparisonOperator.LessThanOrEqual, ComparisonOperator.GreaterThan, ComparisonOperator.GreaterThanOrEqual @@ -312,14 +312,14 @@ public static Gen WalrusExpr(GenContext ctx) => // SourceText is exactly what the lexer recaptures ("="), so they round-trip. private static Gen FStringPartGen(GenContext ctx) => Gen.Frequency( - (3, Gen.OneOfConst(FStringTextParts).Select(t => + (3, Gen.OneOf(FStringTextParts).Select(t => new FStringPart { Text = t })), (3, Expression(ctx.Burn()).Select(e => new FStringPart { Expression = e })), - (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOfConst(FStringConversionFlags), + (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOf(FStringConversionFlags), (e, conv) => new FStringPart { Expression = e, Conversion = conv })), - (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOfConst(FStringConversionFlags), - Gen.OneOfConst(FStringFormatSpecs), + (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOf(FStringConversionFlags), + Gen.OneOf(FStringFormatSpecs), (e, conv, spec) => new FStringPart { Expression = e, @@ -331,7 +331,7 @@ private static Gen FStringPartGen(GenContext ctx) => // A nested replacement field inside the spec (PEP 701): {e:{w}}. The leading // (possibly empty) text part is mandatory because the lexer always emits it — this is the // canonical form the round-trip must match. - (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOfConst(FStringNestedSpecPrefixes), + (1, Gen.Select(IdentifierExpr(ctx), Gen.OneOf(FStringNestedSpecPrefixes), GenIdentifier.Name, (e, prefix, wname) => new FStringPart { @@ -368,7 +368,7 @@ public static Gen TStringLiteralExpr(GenContext ctx) => .Select(parts => new TStringLiteral { Parts = parts })); public static Gen BytesLiteralExpr() => - Gen.OneOfConst("hello", "test", "data", "bytes", "", "abc") + Gen.OneOf("hello", "test", "data", "bytes", "", "abc") .Select(v => new BytesLiteralExpression { Value = v }); public static Gen SetComprehensionExpr(GenContext ctx) => @@ -474,7 +474,7 @@ public static Gen SpreadElementExpr(GenContext ctx) => public static Gen ModifiedArgumentExpr(GenContext ctx) => Gen.Select( - Gen.OneOfConst(ParameterModifier.Ref, ParameterModifier.Out, ParameterModifier.In), + Gen.OneOf(ParameterModifier.Ref, ParameterModifier.Out, ParameterModifier.In), IdentifierExpr(ctx), (mod, id) => new ModifiedArgument { @@ -541,7 +541,7 @@ public static Gen AmbiguousHotspot(GenContext ctx) => // quote-containing f-string with a colliding delimiter that would not re-parse. public static Gen FStringWithQuotesExpr(GenContext ctx) => Gen.Select( - Gen.OneOfConst("\"", "\"x\"", "say \"", "[\"]"), + Gen.OneOf("\"", "\"x\"", "say \"", "[\"]"), IdentifierExpr(ctx), (quoted, e) => new FStringLiteral { @@ -642,7 +642,7 @@ private static Gen SubscriptBase(GenContext ctx) => private static Gen KeywordArgGen(GenContext ctx) => Gen.Select( - Gen.OneOfConst(KeywordArgNames), + Gen.OneOf(KeywordArgNames), CallArg(ctx), (name, val) => new KeywordArgument { Name = name, Value = val }); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenIdentifier.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenIdentifier.cs index 73d557a77..466b81fbe 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenIdentifier.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenIdentifier.cs @@ -26,24 +26,24 @@ internal static class GenIdentifier }; public static Gen Name { get; } = - Gen.OneOfConst(SimpleNames).Where(n => !KeywordSet.Contains(n)); + Gen.OneOf(SimpleNames).Where(n => !KeywordSet.Contains(n)); public static Gen FreshName { get; } = - Gen.Select(Gen.OneOfConst(SimpleNames), Gen.Int[0, 99], + Gen.Select(Gen.OneOf(SimpleNames), Gen.Int[0, 99], (name, suffix) => $"{name}_{suffix}"); public static Gen ClassName { get; } = - Gen.OneOfConst("Foo", "Bar", "Baz", "Animal", "Shape", "Node", "Item", "Point"); + Gen.OneOf("Foo", "Bar", "Baz", "Animal", "Shape", "Node", "Item", "Point"); public static Gen FunctionName { get; } = - Gen.OneOfConst("compute", "process", "transform", "calculate", "get_value", + Gen.OneOf("compute", "process", "transform", "calculate", "get_value", "do_work", "make_thing", "run_task", "check_it", "apply_fn"); public static Gen NameFromContext(GenContext ctx) => ctx.InScopeNames.IsEmpty ? Name : Gen.Frequency( - (3, Gen.OneOfConst(ctx.InScopeNames.ToArray())), + (3, Gen.OneOf(ctx.InScopeNames.ToArray())), (1, Name)); private static readonly string[] BacktickContents = @@ -58,7 +58,7 @@ public static Gen NameFromContext(GenContext ctx) => }; public static Gen BacktickContent { get; } = - Gen.OneOfConst(BacktickContents); + Gen.OneOf(BacktickContents); public static Gen BacktickIdentifier { get; } = BacktickContent.Select(content => $"`{content}`"); @@ -71,7 +71,7 @@ public static Gen NameFromContext(GenContext ctx) => }; public static Gen BacktickContentWithDot { get; } = - Gen.OneOfConst(BacktickWithDot); + Gen.OneOf(BacktickWithDot); private static readonly string[] InvalidBacktickWithNewline = { @@ -79,7 +79,7 @@ public static Gen NameFromContext(GenContext ctx) => }; public static Gen BacktickContentWithNewline { get; } = - Gen.OneOfConst(InvalidBacktickWithNewline); + Gen.OneOf(InvalidBacktickWithNewline); // --- Name mangling generators --- diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenLineContinuation.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenLineContinuation.cs index d366fe2c3..da63c9b60 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenLineContinuation.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenLineContinuation.cs @@ -11,27 +11,27 @@ internal static class GenLineContinuation public static Gen<(string WithContinuation, string Equivalent)> ExplicitContinuation { get; } = Gen.Select( - Gen.OneOfConst(LeftOperands), - Gen.OneOfConst(BinaryOps), - Gen.OneOfConst(RightOperands), + Gen.OneOf(LeftOperands), + Gen.OneOf(BinaryOps), + Gen.OneOf(RightOperands), (left, op, right) => ( WithContinuation: $"result = {left} {op}\\\n {right}\n", Equivalent: $"result = {left} {op} {right}\n")); public static Gen<(string WithContinuation, string Equivalent)> ImplicitContinuationParens { get; } = Gen.Select( - Gen.OneOfConst(LeftOperands), - Gen.OneOfConst(BinaryOps), - Gen.OneOfConst(RightOperands), + Gen.OneOf(LeftOperands), + Gen.OneOf(BinaryOps), + Gen.OneOf(RightOperands), (left, op, right) => ( WithContinuation: $"result = ({left} {op}\n {right})\n", Equivalent: $"result = ({left} {op} {right})\n")); public static Gen<(string WithContinuation, string Equivalent)> ImplicitContinuationBrackets { get; } = Gen.Select( - Gen.OneOfConst(LeftOperands), - Gen.OneOfConst(RightOperands), - Gen.OneOfConst(RightOperands), + Gen.OneOf(LeftOperands), + Gen.OneOf(RightOperands), + Gen.OneOf(RightOperands), (a, b, c) => ( WithContinuation: $"items = [{a},\n {b},\n {c}]\n", Equivalent: $"items = [{a}, {b}, {c}]\n")); @@ -40,8 +40,8 @@ internal static class GenLineContinuation public static Gen<(string WithContinuation, string Equivalent)> ImplicitContinuationBraces { get; } = Gen.Select( - Gen.OneOfConst(LeftOperands), - Gen.OneOfConst(DictValues), + Gen.OneOf(LeftOperands), + Gen.OneOf(DictValues), (key, val) => ( WithContinuation: $"d = {{\"{key}\":\n {val}}}\n", Equivalent: $"d = {{\"{key}\": {val}}}\n")); @@ -59,15 +59,15 @@ internal static class GenLineContinuation }; public static Gen BackslashWithTrailingWhitespace { get; } = - Gen.OneOfConst(TrailingWhitespaceSources); + Gen.OneOf(TrailingWhitespaceSources); public static Gen<(string WithContinuation, string Equivalent)> MixedContinuation { get; } = Gen.Select( - Gen.OneOfConst(LeftOperands), - Gen.OneOfConst(BinaryOps), - Gen.OneOfConst(RightOperands), - Gen.OneOfConst(BinaryOps), - Gen.OneOfConst(RightOperands), + Gen.OneOf(LeftOperands), + Gen.OneOf(BinaryOps), + Gen.OneOf(RightOperands), + Gen.OneOf(BinaryOps), + Gen.OneOf(RightOperands), (a, op1, b, op2, c) => ( WithContinuation: $"result = ({a} {op1}\\\n {b} {op2}\n {c})\n", Equivalent: $"result = ({a} {op1} {b} {op2} {c})\n")); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenLiterals.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenLiterals.cs index b1145f1e1..6e06999c5 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenLiterals.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenLiterals.cs @@ -11,7 +11,7 @@ internal static class GenLiterals new IntegerLiteral { Value = v.ToString() }); public static Gen IntegerWithSuffix { get; } = - Gen.Select(Gen.Long[0, 10000], Gen.OneOfConst("", "L", "u"), + Gen.Select(Gen.Long[0, 10000], Gen.OneOf("", "L", "u"), (v, s) => new IntegerLiteral { Value = v.ToString(), @@ -37,7 +37,7 @@ internal static class GenLiterals .Select(s => new StringLiteral { Value = s }); public static Gen SimpleString { get; } = - Gen.OneOfConst("hello", "world", "test", "foo", "bar", "", "abc 123", "x") + Gen.OneOf("hello", "world", "test", "foo", "bar", "", "abc 123", "x") .Select(s => new StringLiteral { Value = s }); public static Gen Boolean { get; } = diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenPatterns.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenPatterns.cs index ba3887900..13c97d292 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenPatterns.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenPatterns.cs @@ -92,7 +92,7 @@ public static Gen GuardPat(GenContext ctx) => public static Gen RelationalPat() => Gen.Select( - Gen.OneOfConst(RelationalOperator.GreaterThan, RelationalOperator.GreaterThanOrEqual, + Gen.OneOf(RelationalOperator.GreaterThan, RelationalOperator.GreaterThanOrEqual, RelationalOperator.LessThan, RelationalOperator.LessThanOrEqual), GenLiterals.Integer.Select(x => (Expression)x), (op, val) => new RelationalPattern { Operator = op, Value = val }); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenStatements.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenStatements.cs index d6a0f9615..4cd281397 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenStatements.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenStatements.cs @@ -114,7 +114,7 @@ public static Gen Assign(GenContext ctx) => Gen.Select( GenExpressions.IdentifierExpr(ctx).Select(x => (Expression)x), GenExpressions.Expression(ctx), - Gen.OneOfConst( + Gen.OneOf( AssignmentOperator.Assign, AssignmentOperator.PlusAssign, AssignmentOperator.MinusAssign, diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/GenTypes.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/GenTypes.cs index 8a1bbcaf7..b6d19afd9 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/GenTypes.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/GenTypes.cs @@ -17,7 +17,7 @@ internal static class GenTypes }; public static Gen SimpleType { get; } = - Gen.OneOfConst(SimpleTypeNames).Select(name => + Gen.OneOf(SimpleTypeNames).Select(name => new TypeAnnotation { Name = name }); public static Gen Annotation(int fuel) => @@ -30,7 +30,7 @@ public static Gen Annotation(int fuel) => (1, DictType(fuel - 1))); private static Gen GenericSingleArg(int fuel) => - Gen.Select(Gen.OneOfConst("list", "set"), Annotation(fuel), + Gen.Select(Gen.OneOf("list", "set"), Annotation(fuel), (name, arg) => new TypeAnnotation { Name = name, diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenAsync.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenAsync.cs index 697e00f39..e67fcc9b6 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenAsync.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenAsync.cs @@ -16,12 +16,12 @@ internal static class GenAsync public static Gen ModuleWithAsyncFunction(bool valid) => Gen.Select( - Gen.OneOfConst(ReturnTypes), + Gen.OneOf(ReturnTypes), Gen.Int[0, 2], (retType, paramCount) => BuildAsyncModule(retType, paramCount, valid)); public static Gen ModuleWithAwaitOutsideAsync() => - Gen.OneOfConst(ReturnTypes).Select(retType => + Gen.OneOf(ReturnTypes).Select(retType => { var asyncFunc = BuildAsyncFunctionDef("fetch_data", retType, 0); var syncFunc = new FunctionDef @@ -55,7 +55,7 @@ public static Gen ModuleWithAwaitOutsideAsync() => public static Gen ModuleWithAsyncDeterminism() => Gen.Select( - Gen.OneOfConst(ReturnTypes), + Gen.OneOf(ReturnTypes), Gen.Int[0, 2], (retType, paramCount) => BuildAsyncModule(retType, paramCount, valid: true)); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenClasses.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenClasses.cs index 789af9d8d..1b9dcf1af 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenClasses.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenClasses.cs @@ -15,7 +15,7 @@ public static Gen ClassDef(TypeEnv env, string className, ClassInfo in Gen.Select( Gen.Int[1, 2], Gen.Int[1, 2], - Gen.OneOfConst(FieldTypes), + Gen.OneOf(FieldTypes), (baseFieldCount, derivedFieldCount, methodRetType) => { var baseName = "BaseEntity"; diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenContextManagers.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenContextManagers.cs index 051823044..931e15980 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenContextManagers.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenContextManagers.cs @@ -8,7 +8,7 @@ internal static class GenContextManagers public static Gen ValidContextManagerProgram() => Gen.Select( - Gen.OneOfConst(ReturnTypes), + Gen.OneOf(ReturnTypes), Gen.Bool, (returnType, hasBody) => { @@ -44,7 +44,7 @@ public static Gen ValidContextManagerProgram() => }); public static Gen ContextManagerWithAsBinding() => - Gen.OneOfConst(ReturnTypes).Select(returnType => + Gen.OneOf(ReturnTypes).Select(returnType => { var lines = new List { @@ -72,7 +72,7 @@ public static Gen ContextManagerWithAsBinding() => }); public static Gen AsyncContextManagerProgram() => - Gen.OneOfConst(ReturnTypes).Select(returnType => + Gen.OneOf(ReturnTypes).Select(returnType => { var lines = new List { diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenDecorators.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenDecorators.cs index db22c50eb..930ece846 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenDecorators.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenDecorators.cs @@ -36,7 +36,7 @@ internal static class GenDecorators public static Gen ModuleWithDecoratedFunction(bool validDecorator) => validDecorator - ? Gen.OneOfConst(ValidMethodDecorators).Select(BuildValidDecoratedModule) + ? Gen.OneOf(ValidMethodDecorators).Select(BuildValidDecoratedModule) : Gen.Int[0, InvalidCombinations.Length - 1].Select(i => BuildInvalidDecoratedModule(InvalidCombinations[i])); @@ -50,7 +50,7 @@ public static Gen ModuleWithDataclass() => Gen.Int[1, 4].Select(BuildDataclassModule); public static Gen ModuleWithDecoratorDeterminism() => - Gen.OneOfConst(ValidMethodDecorators).Select(BuildValidDecoratedModule); + Gen.OneOf(ValidMethodDecorators).Select(BuildValidDecoratedModule); private static Module BuildValidDecoratedModule(string decorator) => // @final requires an @override chain; every other valid decorator sits on a diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenFunctions.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenFunctions.cs index bb3ffd5f0..cdc681d4c 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenFunctions.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenFunctions.cs @@ -43,7 +43,7 @@ public static Gen FunctionCall(TypeEnv env, string targetReturnType, if (candidates.Count == 0) return GenTyped.ExpressionOfType(env, targetReturnType, fuel); - return Gen.OneOfConst(candidates.ToArray()).SelectMany(funcName => + return Gen.OneOf(candidates.ToArray()).SelectMany(funcName => { var sig = env.Functions[funcName]; return sig.Parameters.Length == 0 @@ -210,7 +210,7 @@ private static Gen> BodyForReturnType(TypeEnv env, str var paramNames = new[] { "arg0", "arg1", "arg2" }; var paramTypes = new[] { "int", "str", "bool" }; var name = index < paramNames.Length ? paramNames[index] : $"arg{index}"; - return Gen.OneOfConst(paramTypes).Select(t => (name, t)); + return Gen.OneOf(paramTypes).Select(t => (name, t)); } private static Expression MakeCall(string funcName, ImmutableArray args) => diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenGenerics.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenGenerics.cs index e91a1bc1f..0d345d192 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenGenerics.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenGenerics.cs @@ -11,7 +11,7 @@ internal static class GenGenerics public static Gen GenericClassProgram(TypeEnv env, int fuel) => Gen.Select( Gen.Int[1, 2], - Gen.OneOfConst(ConcreteTypes), + Gen.OneOf(ConcreteTypes), (fieldCount, instantiationType) => { var typeParams = ImmutableArray.Create( @@ -66,8 +66,8 @@ public static Gen GenericClassProgram(TypeEnv env, int fuel) => public static Gen GenericFunctionProgram(TypeEnv env, int fuel) => Gen.Select( - Gen.OneOfConst(ConcreteTypes), - Gen.OneOfConst(ConcreteTypes), + Gen.OneOf(ConcreteTypes), + Gen.OneOf(ConcreteTypes), (type1, type2) => { var identityFn = new FunctionDef @@ -147,8 +147,8 @@ public static Gen GenericFunctionProgram(TypeEnv env, int fuel) => public static Gen MultiTypeParamProgram(TypeEnv env, int fuel) => Gen.Select( - Gen.OneOfConst(ConcreteTypes), - Gen.OneOfConst(ConcreteTypes), + Gen.OneOf(ConcreteTypes), + Gen.OneOf(ConcreteTypes), (typeA, typeB) => { var typeParams = ImmutableArray.Create( @@ -204,7 +204,7 @@ public static Gen MultiTypeParamProgram(TypeEnv env, int fuel) => }); public static Gen GenericWithInheritanceProgram(TypeEnv env, int fuel) => - Gen.OneOfConst(ConcreteTypes).Select(concreteType => + Gen.OneOf(ConcreteTypes).Select(concreteType => { var containerTypeParams = ImmutableArray.Create( new TypeParameterDef { Name = "T" }); @@ -352,7 +352,7 @@ public static Gen GenericWithInheritanceProgram(TypeEnv env, int fuel) = }); public static Gen WrongTypeArgCountProgram(TypeEnv env, int fuel) => - Gen.OneOfConst(ConcreteTypes).Select(concreteType => + Gen.OneOf(ConcreteTypes).Select(concreteType => { var typeParams = ImmutableArray.Create( new TypeParameterDef { Name = "T" }); @@ -393,8 +393,8 @@ public static Gen WrongTypeArgCountProgram(TypeEnv env, int fuel) => public static Gen TypeMismatchOnGenericFieldProgram(TypeEnv env, int fuel) => Gen.Select( - Gen.OneOfConst(ConcreteTypes), - Gen.OneOfConst(ConcreteTypes).Where(t => t != "int"), + Gen.OneOf(ConcreteTypes), + Gen.OneOf(ConcreteTypes).Where(t => t != "int"), (instantType, wrongType) => { var typeParams = ImmutableArray.Create( diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenImports.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenImports.cs index 0288819db..6fb9ae3d4 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenImports.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenImports.cs @@ -9,7 +9,7 @@ internal static class GenImports public static Gen<(string LibSource, (string Name, string ParamType)[] Exports)> LibraryModule(TypeEnv env, int fuel) => Gen.Select( Gen.Int[1, 3], - Gen.OneOfConst(SimpleTypes), + Gen.OneOf(SimpleTypes), (count, retType) => { var lines = new List(); @@ -62,7 +62,7 @@ internal static class GenImports })); public static Gen<(string FileA, string FileB)> CircularImportPair(TypeEnv env, int fuel) => - Gen.OneOfConst(SimpleTypes).Select(retType => + Gen.OneOf(SimpleTypes).Select(retType => { var fileA = $"from file_b import helper_b\n\ndef helper_a() -> {retType}:\n return helper_b()\n"; var fileB = $"from file_a import helper_a\n\ndef helper_b() -> {retType}:\n return helper_a()\n"; @@ -71,7 +71,7 @@ internal static class GenImports public static Gen<(string Main, string Lib1, string Lib2, string ConflictingName)> NameCollisionPair( TypeEnv env, int fuel) => - Gen.OneOfConst(SimpleTypes).Select(retType => + Gen.OneOf(SimpleTypes).Select(retType => { var conflictName = "shared_func"; var lib1 = $"def {conflictName}() -> {retType}:\n return {DefaultLiteral(retType)}\n"; @@ -83,7 +83,7 @@ internal static class GenImports public static Gen<(string Main, string Lib)> MultiFileProgram(TypeEnv env, int fuel) => Gen.Select( Gen.Int[1, 2], - Gen.OneOfConst(SimpleTypes), + Gen.OneOf(SimpleTypes), (funcCount, retType) => { var libLines = new List(); @@ -119,7 +119,7 @@ internal static class GenImports }); public static Gen<(string Main, string Lib)> UnusedImportProgram(TypeEnv env, int fuel) => - Gen.OneOfConst(SimpleTypes).Select(retType => + Gen.OneOf(SimpleTypes).Select(retType => { var lib = $"def unused_func() -> {retType}:\n return {DefaultLiteral(retType)}\n"; var main = "from lib import unused_func\n\ndef main():\n print(42)\n"; diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenIterators.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenIterators.cs index 73bae34f7..93c1e07c9 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenIterators.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenIterators.cs @@ -10,12 +10,12 @@ internal static class GenIterators public static Gen ModuleWithGenerator(bool valid) => Gen.Select( - Gen.OneOfConst(YieldTypes), + Gen.OneOf(YieldTypes), Gen.Int[1, 3], (yieldType, yieldCount) => BuildGeneratorModule(yieldType, yieldCount, valid)); public static Gen ModuleWithYieldFrom() => - Gen.OneOfConst(YieldTypes).Select(yieldType => + Gen.OneOf(YieldTypes).Select(yieldType => { var innerGen = BuildGeneratorFunctionDef("inner_gen", yieldType, 2); var outerGen = new FunctionDef @@ -43,12 +43,12 @@ public static Gen ModuleWithYieldFrom() => }); public static Gen ModuleWithIterProtocol(bool complete) => - Gen.OneOfConst(YieldTypes).Select(yieldType => + Gen.OneOf(YieldTypes).Select(yieldType => BuildIterProtocolModule(yieldType, complete)); public static Gen ModuleWithGeneratorValidator() => Gen.Select( - Gen.OneOfConst(YieldTypes), + Gen.OneOf(YieldTypes), Gen.Int[1, 3], (yieldType, yieldCount) => BuildGeneratorModule(yieldType, yieldCount, valid: true)); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenOperators.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenOperators.cs index 82b59eb41..8d1dfcdf7 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenOperators.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenOperators.cs @@ -184,7 +184,7 @@ public static Gen PrecedenceProgram() => /// different code (#2288). /// public static Gen WrongArityOperatorDunderProgram() => - Gen.OneOfConst( + Gen.OneOf( " def __add__(self) -> Bad:", " def __neg__(self, other: Bad) -> Bad:").Select(BadClassProgram); @@ -193,7 +193,7 @@ public static Gen WrongArityOperatorDunderProgram() => /// fact: SPY0414 (unknown dunder method). /// public static Gen UnknownDunderProgram() => - Gen.OneOfConst( + Gen.OneOf( " def __xyzzy__(self) -> Bad:", " def __frobnicate__(self, other: Bad) -> Bad:").Select(BadClassProgram); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenTyped.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenTyped.cs index f46989711..db6fc2451 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenTyped.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenTyped.cs @@ -27,7 +27,7 @@ private static Gen LeafOfType(TypeEnv env, string targetType) { var vars = env.VarsOfType(targetType); var varGen = vars.Count > 0 - ? Gen.OneOfConst(vars.ToArray()).Select(n => (Expression)new Identifier { Name = n }) + ? Gen.OneOf(vars.ToArray()).Select(n => (Expression)new Identifier { Name = n }) : null; return targetType switch @@ -93,14 +93,14 @@ private static Gen IntArithmetic(TypeEnv env, int fuel) => Gen.Select( ExpressionOfType(env, "int", fuel), ExpressionOfType(env, "int", fuel), - Gen.OneOfConst(BinaryOperator.Add, BinaryOperator.Subtract, BinaryOperator.Multiply), + Gen.OneOf(BinaryOperator.Add, BinaryOperator.Subtract, BinaryOperator.Multiply), (left, right, op) => (Expression)new BinaryOp { Left = left, Right = right, Operator = op }); private static Gen FloatArithmetic(TypeEnv env, int fuel) => Gen.Select( ExpressionOfType(env, "float", fuel), ExpressionOfType(env, "float", fuel), - Gen.OneOfConst(BinaryOperator.Add, BinaryOperator.Subtract, BinaryOperator.Multiply), + Gen.OneOf(BinaryOperator.Add, BinaryOperator.Subtract, BinaryOperator.Multiply), (left, right, op) => (Expression)new BinaryOp { Left = left, Right = right, Operator = op }); private static Gen StringConcat(TypeEnv env, int fuel) => @@ -119,15 +119,15 @@ private static Gen BooleanLogic(TypeEnv env, int fuel) => Gen.Select( ExpressionOfType(env, "bool", fuel), ExpressionOfType(env, "bool", fuel), - Gen.OneOfConst(BinaryOperator.And, BinaryOperator.Or), + Gen.OneOf(BinaryOperator.And, BinaryOperator.Or), (left, right, op) => (Expression)new BinaryOp { Left = left, Right = right, Operator = op }), ComparisonExpression(env, fuel)); private static Gen ComparisonExpression(TypeEnv env, int fuel) => Gen.Select( - Gen.OneOfConst("int", "float").SelectMany(t => ExpressionOfType(env, t, fuel)), - Gen.OneOfConst("int", "float").SelectMany(t => ExpressionOfType(env, t, fuel)), - Gen.OneOfConst( + Gen.OneOf("int", "float").SelectMany(t => ExpressionOfType(env, t, fuel)), + Gen.OneOf("int", "float").SelectMany(t => ExpressionOfType(env, t, fuel)), + Gen.OneOf( BinaryOperator.Equal, BinaryOperator.NotEqual, BinaryOperator.LessThan, BinaryOperator.LessThanOrEqual, BinaryOperator.GreaterThan, BinaryOperator.GreaterThanOrEqual), @@ -303,7 +303,7 @@ private static Gen AssignmentStatement(TypeEnv env, int fuel) }); } - return Gen.OneOfConst(mutableVars).SelectMany(kv => + return Gen.OneOf(mutableVars).SelectMany(kv => ExpressionOfType(env, kv.Value, fuel).Select(expr => (Statement)new VariableDeclaration { @@ -319,7 +319,7 @@ private static Gen LenExpression(TypeEnv env, int fuel) .ToList(); if (listVars.Count > 0) { - return Gen.OneOfConst(listVars.ToArray()).Select(n => + return Gen.OneOf(listVars.ToArray()).Select(n => (Expression)new FunctionCall { Function = new Identifier { Name = "len" }, @@ -370,8 +370,8 @@ private static Gen IsNoneCheck(TypeEnv env) .Select(kv => kv.Key) .ToArray(); return Gen.Select( - Gen.OneOfConst(optionalVars), - Gen.OneOfConst(ComparisonOperator.Is, ComparisonOperator.IsNot), + Gen.OneOf(optionalVars), + Gen.OneOf(ComparisonOperator.Is, ComparisonOperator.IsNot), (name, op) => (Expression)new ComparisonChain { Operands = ImmutableArray.Create( @@ -391,7 +391,7 @@ public static Gen NarrowedBlock(TypeEnv env, int fuel) if (optionalVars.Length == 0) return AssignmentStatement(env, fuel); - return Gen.OneOfConst(optionalVars).Select(name => + return Gen.OneOf(optionalVars).Select(name => (Statement)new IfStatement { Test = new ComparisonChain @@ -416,7 +416,7 @@ public static Gen NarrowedBlock(TypeEnv env, int fuel) } public static Gen ListSubscript(TypeEnv env, string elementType) => - Gen.OneOfConst(env.VarsOfType($"list[{elementType}]").ToArray()) + Gen.OneOf(env.VarsOfType($"list[{elementType}]").ToArray()) .Select(name => (Expression)new IndexAccess { Object = new Identifier { Name = name }, @@ -426,7 +426,7 @@ public static Gen ListSubscript(TypeEnv env, string elementType) => private static Gen StringMethodCall(TypeEnv env, int fuel) => Gen.Select( ExpressionOfType(env, "str", fuel), - Gen.OneOfConst("upper", "lower", "strip"), + Gen.OneOf("upper", "lower", "strip"), (obj, method) => (Expression)new FunctionCall { Function = new MemberAccess { Object = obj, Member = method }, diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenVariance.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenVariance.cs index 391d3f8a7..f73d5c4f7 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenVariance.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/GenVariance.cs @@ -8,7 +8,7 @@ internal static class GenVariance public static Gen CovariantInterfaceProgram() => Gen.Select( - Gen.OneOfConst(ConcreteTypes), + Gen.OneOf(ConcreteTypes), Gen.Int[1, 2], (concreteType, methodCount) => { @@ -45,7 +45,7 @@ public static Gen CovariantInterfaceProgram() => public static Gen ContravariantInterfaceProgram() => Gen.Select( - Gen.OneOfConst(ConcreteTypes), + Gen.OneOf(ConcreteTypes), Gen.Int[1, 2], (concreteType, methodCount) => { @@ -101,7 +101,7 @@ public static Gen VarianceOnClassProgram() => }); public static Gen CovariantInInputPositionProgram() => - Gen.OneOfConst(ConcreteTypes).Select(concreteType => + Gen.OneOf(ConcreteTypes).Select(concreteType => { var lines = new List { @@ -121,7 +121,7 @@ public static Gen CovariantInInputPositionProgram() => }); public static Gen ContravariantInOutputPositionProgram() => - Gen.OneOfConst(ConcreteTypes).Select(concreteType => + Gen.OneOf(ConcreteTypes).Select(concreteType => { var lines = new List { diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/Mutations/MutationBases.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/Mutations/MutationBases.cs index 362c22105..2b378ae67 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/Mutations/MutationBases.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/Mutations/MutationBases.cs @@ -15,17 +15,17 @@ internal static class MutationBases { /// GenTyped.TypedProgram with statements over the default env (the roster's TypedStatements). public static Gen TypedStatements() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)); /// GenTyped.TypedProgram with statements over the collections env. public static Gen TypedCollections() => - Gen.OneOfConst("int", "str", "list[int]").SelectMany(type => + Gen.OneOf("int", "str", "list[int]").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2, withStatements: true)); /// GenTyped.TypedProgram over the Optionals env (no statements). public static Gen TypedOptionals() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2)); /// GenFunctions.ModuleWithFunctions at fuel 2 (the roster's Functions). @@ -36,7 +36,7 @@ public static Gen TypedOptionals() => /// GenTyped.ListSubscript printed from a main declaring the collections env. public static Gen ListSubscripts() => - Gen.OneOfConst("int", "str").SelectMany(element => + Gen.OneOf("int", "str").SelectMany(element => GenTyped.ListSubscript(TypeEnv.WithCollections, element).Select(expr => InMain(TypeEnv.WithCollections, expr))); public static Gen GenericFunctions() => GenGenerics.GenericFunctionProgram(TypeEnv.WithGenerics, fuel: 2); diff --git a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/TypeEnv.cs b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/TypeEnv.cs index 51ca05ca4..9e5b47e46 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/TypeEnv.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Generators/Typed/TypeEnv.cs @@ -14,7 +14,7 @@ internal sealed record ClassInfo( internal sealed record TypeEnv { // Sorted by ordinal key, never hashed: the generators enumerate these maps (declarations, - // OneOfConst over variables/functions), and a hashed map's order follows .NET's per-process + // OneOf over variables/functions), and a hashed map's order follows .NET's per-process // randomized string hash — one CsCheck seed then drew different programs in different processes, // so a printed seed did not reproduce its sample (#2288). public ImmutableSortedDictionary Bindings { get; init; } = diff --git a/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicCorpusInvarianceTests.cs b/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicCorpusInvarianceTests.cs index a0aec522a..e9bcac09a 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicCorpusInvarianceTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicCorpusInvarianceTests.cs @@ -59,7 +59,7 @@ public void TransformedFixtures_PrintTheirFixturesExpectedOutput() var attempted = new HashSet(StringComparer.Ordinal); var executed = new List(); - Gen.OneOfConst(pairs.ToArray()).Sample(pair => + Gen.OneOf(pairs.ToArray()).Sample(pair => { if (executed.Count >= budget || !attempted.Add(pair.Key)) return; diff --git a/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicPropertyTests.cs index 9ced5e09f..4c5c8b15a 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Metamorphic/MetamorphicPropertyTests.cs @@ -23,7 +23,7 @@ public MetamorphicPropertyTests(ITestOutputHelper output) : base(output) { } public void CommentInsertion_PreservesOutput() { var transform = new CommentInsertionTransform(); - Gen.OneOfConst(SamplePrograms).Sample(source => + Gen.OneOf(SamplePrograms).Sample(source => { var r1 = CompileAndExecuteWithGC(source); if (!r1.Success) @@ -55,7 +55,7 @@ public void CommentInsertion_PreservesOutput() public void PassInsertion_PreservesOutput() { var transform = new PassInsertionTransform(); - Gen.OneOfConst(SamplePrograms).Sample(source => + Gen.OneOf(SamplePrograms).Sample(source => { var r1 = CompileAndExecuteWithGC(source); if (!r1.Success) @@ -121,7 +121,7 @@ public void AddRedundantTypeAnnotation_PreservesOutput() private void RunTransformProperty(IAstTransform transform) { - Gen.OneOfConst(SamplePrograms).Sample(source => + Gen.OneOf(SamplePrograms).Sample(source => { var r1 = CompileAndExecuteWithGC(source); if (!r1.Success) diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/BuiltinShadowingPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/BuiltinShadowingPropertyTests.cs index 0e97bf624..567528962 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/BuiltinShadowingPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/BuiltinShadowingPropertyTests.cs @@ -42,7 +42,7 @@ private static readonly (string Type, string Value, string Expected)[] Cases = [Fact] public void UserGenericShadowingBuiltin_ExplicitCall_ResolvesToUserFunction() { - Gen.Select(Gen.OneOfConst(BuiltinNames), Gen.OneOfConst(Cases)) + Gen.Select(Gen.OneOf(BuiltinNames), Gen.OneOf(Cases)) .Sample((name, c) => { var source = diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/CombinedFeaturePropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/CombinedFeaturePropertyTests.cs index 6769356e5..63ae0af8e 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/CombinedFeaturePropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/CombinedFeaturePropertyTests.cs @@ -25,7 +25,7 @@ public void AsyncGenerator_CompilesClean() { var sink = new RejectionSink("CombinedFeature.AsyncGenerator_CompilesClean"); - var gen = Gen.OneOfConst("int", "str").Select(yieldType => + var gen = Gen.OneOf("int", "str").Select(yieldType => { Expression yieldExpr = yieldType == "int" ? new IntegerLiteral { Value = "42" } @@ -83,7 +83,7 @@ public void DecoratedAsyncFunction_CompilesClean() { var sink = new RejectionSink("CombinedFeature.DecoratedAsyncFunction_CompilesClean"); - var gen = Gen.OneOfConst("int", "str", "bool").Select(retType => + var gen = Gen.OneOf("int", "str", "bool").Select(retType => { Expression returnExpr = retType switch { diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/DeterminismPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/DeterminismPropertyTests.cs index 83f819e54..713a5a144 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/DeterminismPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/DeterminismPropertyTests.cs @@ -41,7 +41,7 @@ public void Compilation_IsDeterministic() [Fact] public void TypedCompilation_ProducesIdenticalDiagnostics() { - var gen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var gen = Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)); gen.Sample(module => @@ -77,7 +77,7 @@ public void TypedCompilation_ProducesIdenticalCSharp() { var sink = new RejectionSink("Determinism.TypedCompilation_ProducesIdenticalCSharp"); var gen = SemanticFilter.CompilableProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/DiagnosticSpanPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/DiagnosticSpanPropertyTests.cs index 215ce17e5..860cb7ea3 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/DiagnosticSpanPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/DiagnosticSpanPropertyTests.cs @@ -129,7 +129,7 @@ public void TypedPrograms_DiagnosticSpans_AreWithinSourceBounds() var errors = new List(); int injected = 0; - var baseGen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)); var sink = new RejectionSink("DiagnosticSpan.TypedPrograms_DiagnosticSpans_AreWithinSourceBounds"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/ErrorCompletenessPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/ErrorCompletenessPropertyTests.cs index 69b352cdc..3f1b6193e 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/ErrorCompletenessPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/ErrorCompletenessPropertyTests.cs @@ -208,7 +208,7 @@ public void IsinstanceNarrowing_AnalysesClean() public void ConstReassignment_IsRejected() { RunInjectionTest(ErrorInjector.InjectConstReassignment, - "const reassignment", Gen.OneOfConst("int", "str", "bool").SelectMany(type => + "const reassignment", Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true))); } @@ -547,7 +547,7 @@ public void WrongTypedLibraryConstant_IsRejected() => RunProjectInjectionTest(ErrorInjector.InjectWrongTypedLibraryConstant, "wrong-typed library constant"); private static Gen ProgramWithNarrowing(int fuel) => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel, withStatements: true)); private static bool HasNarrowedBlock(Module module) => @@ -558,7 +558,7 @@ private static bool HasNarrowedBlock(Module module) => }); private static Gen ProgramWithOptionals() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2)); private static Gen ProgramWithConstraints() => @@ -636,7 +636,7 @@ private void RunInjectionTest( ErrorInjector.KnownRedCascade? cascade = null; int onCascadeShape = 0; - var baseGen = overrideGen ?? Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = overrideGen ?? Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)); var sink = new RejectionSink($"ErrorCompleteness base generator ({label})"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/FunctionSemanticsPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/FunctionSemanticsPropertyTests.cs index 14de621dd..585c05761 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/FunctionSemanticsPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/FunctionSemanticsPropertyTests.cs @@ -63,7 +63,7 @@ public void FunctionCall_TypeChecksCorrectly() var sink = new RejectionSink("FunctionSemantics.FunctionCall_TypeChecksCorrectly"); SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenFunctions.ModuleWithFunctions(TypeEnv.Default, type, fuel: 2)), sink) .Sample(_ => { }, print: m => Sharpy.Compiler.Pretty.Unparser.Unparse(m), iter: 50); @@ -82,7 +82,7 @@ public void ModuleWithEnvFunctions_AnalyzesClean() var sink = new RejectionSink("FunctionSemantics.ModuleWithEnvFunctions_AnalyzesClean"); SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenFunctions.ModuleWithFunctions(TypeEnv.WithFunctions, type, fuel: 2)), sink) .Sample(_ => { }, print: m => Sharpy.Compiler.Pretty.Unparser.Unparse(m), iter: 50); @@ -143,7 +143,7 @@ public void FunctionOverload_DispatchesCorrectly() public void ModuleWithFunctions_NeverThrowsInternalError() { var verdicts = ErrorInjector.JudgeSamples( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenFunctions.ModuleWithFunctions(TypeEnv.WithFunctions, type, fuel: 2)), source => ErrorInjector.JudgeNoInternalError(source, "function program"), iter: 50); _output.WriteLine($"Function programs: {verdicts.Tested - verdicts.Failures}/{verdicts.Tested} analysed without an internal error"); diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/GeneratorMemberSoundnessPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/GeneratorMemberSoundnessPropertyTests.cs index 1270d7ce1..540893072 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/GeneratorMemberSoundnessPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/GeneratorMemberSoundnessPropertyTests.cs @@ -69,7 +69,7 @@ public void ModuleWithNestedTry_AnalyzesClean() => [Fact] public void ListSubscript_AnalyzesClean() => AssertModulesClean("GenTyped.ListSubscript", - Gen.OneOfConst("int", "str").SelectMany(element => + Gen.OneOf("int", "str").SelectMany(element => InMain(TypeEnv.WithCollections, GenTyped.ListSubscript(TypeEnv.WithCollections, element)))); /// GenTyped.ListOfType is a list-literal fragment: printed from a main @@ -78,7 +78,7 @@ public void ListSubscript_AnalyzesClean() => [Fact] public void ListOfType_AnalyzesClean() => AssertModulesClean("GenTyped.ListOfType", - Gen.OneOfConst("int", "str").SelectMany(element => + Gen.OneOf("int", "str").SelectMany(element => InMain(TypeEnv.WithCollections, GenTyped.ListOfType(TypeEnv.WithCollections, element, fuel: 1))), ListIterations); @@ -88,7 +88,7 @@ public void ListOfType_AnalyzesClean() => [Fact] public void TypedProgram_ListResult_AnalyzesClean() => AssertModulesClean("GenTyped.TypedProgram(list result)", - Gen.OneOfConst("list[int]", "list[str]").SelectMany(type => + Gen.OneOf("list[int]", "list[str]").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2, withStatements: true)), ListIterations); diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/ImportResolutionPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/ImportResolutionPropertyTests.cs index 119488693..9825935ac 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/ImportResolutionPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/ImportResolutionPropertyTests.cs @@ -62,7 +62,7 @@ public void ImportedClass_IsInstantiable() { var sink = new RejectionSink("ImportResolution.ImportedClass_IsInstantiable"); - SemanticFilter.CompilableProject(Gen.OneOfConst("int", "str", "bool").Select(fieldType => + SemanticFilter.CompilableProject(Gen.OneOf("int", "str", "bool").Select(fieldType => { var lib = $"class Widget:\n value: {fieldType}\n\n def __init__(self, value: {fieldType}):\n self.value = value\n"; var main = $"from lib import Widget\n\ndef main():\n w = Widget({GenImports_DefaultLiteral(fieldType)})\n print(w.value)\n"; diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/InterfacePropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/InterfacePropertyTests.cs index 8b8b53ded..56d7f0d7d 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/InterfacePropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/InterfacePropertyTests.cs @@ -64,7 +64,7 @@ public void InterfaceImplementation_FailsWhenMissing() public void ProtocolSynthesis_AddsInterfaceForDunder() { var samples = PropertyCorpus.CompileAll( - Gen.OneOfConst("__len__", "__bool__") + Gen.OneOf("__len__", "__bool__") .SelectMany(GenInterfaces.ModuleWithProtocolDunder), m => Sharpy.Compiler.Pretty.Unparser.Unparse(m), iter: 50); PropertyCorpus.AssertAllPassOrAllowed(samples, allowedCodes: null, _output, diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/MultiFileDeterminismTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/MultiFileDeterminismTests.cs index 6f58c25ac..d9d9409df 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/MultiFileDeterminismTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/MultiFileDeterminismTests.cs @@ -57,10 +57,10 @@ public void CompilationOrder_DoesNotAffectResult(string name, string mainSpy, st public void GeneratedMultiFilePrograms_AreOrderIndependent() { Gen.Select( - Gen.OneOfConst("greet", "compute", "transform", "process"), - Gen.OneOfConst("int", "str", "bool"), - Gen.OneOfConst("Widget", "Item", "Entry", "Record"), - Gen.OneOfConst("int", "str") + Gen.OneOf("greet", "compute", "transform", "process"), + Gen.OneOf("int", "str", "bool"), + Gen.OneOf("Widget", "Item", "Entry", "Record"), + Gen.OneOf("int", "str") ).Sample((funcName, paramType, className, fieldType) => { var defaultVal = paramType switch diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/OverloadOrderIndependencePropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/OverloadOrderIndependencePropertyTests.cs index 108ee4c64..2d6f6c14e 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/OverloadOrderIndependencePropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/OverloadOrderIndependencePropertyTests.cs @@ -64,9 +64,9 @@ private static readonly (string Type, string Literal)[] TypePool = private sealed record Scenario(Engine Engine, string[] ParamSet, string ArgLiteral); private static Gen GenScenario => - from engine in Gen.OneOfConst(Engine.Function, Engine.Method, Engine.Operator) - from paramSet in Gen.OneOfConst(ParamSets) - from arg in Gen.OneOfConst(TypePool) + from engine in Gen.OneOf(Engine.Function, Engine.Method, Engine.Operator) + from paramSet in Gen.OneOf(ParamSets) + from arg in Gen.OneOf(TypePool) select new Scenario(engine, paramSet, arg.Literal); [Fact] diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/SemanticInfoConsistencyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/SemanticInfoConsistencyTests.cs index c9a6f5e5e..0f7f9154d 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/SemanticInfoConsistencyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/SemanticInfoConsistencyTests.cs @@ -27,7 +27,7 @@ public void AllExpressions_HaveResolvedTypes() var sink = new RejectionSink("SemanticInfoConsistency.AllExpressions_HaveResolvedTypes"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => @@ -68,7 +68,7 @@ public void AllVariableReferences_ResolveToSymbols() var sink = new RejectionSink("SemanticInfoConsistency.AllVariableReferences_ResolveToSymbols"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => @@ -113,7 +113,7 @@ public void AllExpressions_HaveResolvedTypes_WithCollections() { var sink = new RejectionSink("SemanticInfoConsistency.AllExpressions_HaveResolvedTypes_WithCollections"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2)), sink); AssertAllExpressionsResolved(gen, sink, iter: 30); } @@ -123,7 +123,7 @@ public void AllExpressions_HaveResolvedTypes_WithOptionals() { var sink = new RejectionSink("SemanticInfoConsistency.AllExpressions_HaveResolvedTypes_WithOptionals"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2)), sink); AssertAllExpressionsResolved(gen, sink, iter: 30); } @@ -153,7 +153,7 @@ public void ExpressionTypes_AreConsistentWithNodeKind() var sink = new RejectionSink("SemanticInfoConsistency.ExpressionTypes_AreConsistentWithNodeKind"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2)), sink); gen.Sample(module => diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/SymbolPositionPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/SymbolPositionPropertyTests.cs index afe5dc521..c985caddf 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/SymbolPositionPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/SymbolPositionPropertyTests.cs @@ -24,7 +24,7 @@ public void SymbolPositions_AreWithinSourceBounds() { var sink = new RejectionSink("SymbolPosition.SymbolPositions_AreWithinSourceBounds"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => @@ -57,7 +57,7 @@ public void NameDeclarationPosition_IsAtOrAfterDeclarationPosition() { var sink = new RejectionSink("SymbolPosition.NameDeclarationPosition_IsAtOrAfterDeclarationPosition"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => @@ -89,7 +89,7 @@ public void EffectiveNamePosition_FallsBackCorrectly() { var sink = new RejectionSink("SymbolPosition.EffectiveNamePosition_FallsBackCorrectly"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => @@ -212,7 +212,7 @@ public void DeclarationSpan_IsConsistentWithLineColumn() { var sink = new RejectionSink("SymbolPosition.DeclarationSpan_IsConsistentWithLineColumn"); var gen = SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2)), sink); gen.Sample(module => diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypeSoundnessPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypeSoundnessPropertyTests.cs index bcf73d882..397364d15 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypeSoundnessPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypeSoundnessPropertyTests.cs @@ -20,7 +20,7 @@ public void TypedProgram_ExecutesWithoutRuntimeTypeErrors() { var errors = new List(); - var baseGen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)); var sink = new RejectionSink("TypeSoundness.TypedProgram_ExecutesWithoutRuntimeTypeErrors"); @@ -54,7 +54,7 @@ public void TypedProgram_WithCollections_ExecutesWithoutRuntimeTypeErrors() { var errors = new List(); - var baseGen = Gen.OneOfConst("int", "str", "list[int]").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "list[int]").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2, withStatements: true)); var sink = new RejectionSink("TypeSoundness.TypedProgram_WithCollections_ExecutesWithoutRuntimeTypeErrors"); @@ -88,7 +88,7 @@ public void TypedProgram_WithOptionals_AnalyzesCleanly() { var errors = new List(); - var baseGen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2)); var sink = new RejectionSink("TypeSoundness.TypedProgram_WithOptionals_AnalyzesCleanly"); @@ -119,7 +119,7 @@ public void FilteredTypedProgram_ProducesExpectedTypeOutput() var errors = new List(); var sink = new RejectionSink("TypeSoundness.FilteredTypedProgram_ProducesExpectedTypeOutput"); - Gen.OneOfConst("int", "str", "bool").Sample(resultType => + Gen.OneOf("int", "str", "bool").Sample(resultType => { var gen = SemanticFilter.CompilableProgram( GenTyped.TypedProgram(TypeEnv.Default, resultType, fuel: 2), sink); diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedAnalyzePropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedAnalyzePropertyTests.cs index 4a4a120a5..9e0c207b5 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedAnalyzePropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedAnalyzePropertyTests.cs @@ -29,7 +29,7 @@ public void TypedProgram_AnalyzesClean() var sink = new RejectionSink("TypedAnalyze.TypedProgram_AnalyzesClean"); SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => { var env = new TypeEnv() .WithBinding("x", "int") @@ -46,7 +46,7 @@ public void TypedProgram_AnalyzesClean() [Fact] public void FilteredTypedProgram_AnalyzesClean() { - var baseGen = Gen.OneOfConst("int", "str", "bool").SelectMany(type => + var baseGen = Gen.OneOf("int", "str", "bool").SelectMany(type => { var env = new TypeEnv() .WithBinding("x", "int") @@ -101,15 +101,15 @@ public void TypedProgram_NeverThrowsInternalError(string config) /// result types are the ones the acceptance lanes over the same env draw. private static Gen NeverThrowsConfig(string config) => config switch { - "bare-fuel3" => Gen.OneOfConst("int", "str", "bool").SelectMany(type => + "bare-fuel3" => Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(new TypeEnv(), type, fuel: 3)), - "Default" => Gen.OneOfConst("int", "str", "bool").SelectMany(type => + "Default" => Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)), - "WithOptionals" => Gen.OneOfConst("int", "str", "bool").SelectMany(type => + "WithOptionals" => Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2, withStatements: true)), - "WithCollections" => Gen.OneOfConst("int", "str", "list[int]").SelectMany(type => + "WithCollections" => Gen.OneOf("int", "str", "list[int]").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2, withStatements: true)), - "WithGenerics" => Gen.OneOfConst("int", "str", "bool").SelectMany(type => + "WithGenerics" => Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithGenerics, type, fuel: 2, withStatements: true)), _ => throw new ArgumentOutOfRangeException(nameof(config), config, "unknown NeverThrows config"), }; diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedGeneratorRosterTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedGeneratorRosterTests.cs index 6d506c143..86b9f8d67 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedGeneratorRosterTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/TypedGeneratorRosterTests.cs @@ -98,17 +98,17 @@ private static RosterRow NoConstructRow(string file, string title, string reason /// TypeSoundnessPropertyTests.TypedProgram_ExecutesWithoutRuntimeTypeErrors. private static Gen TypedStatements() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)); /// TypeSoundnessPropertyTests' collections fact. private static Gen TypedCollections() => - Gen.OneOfConst("int", "str", "list[int]").SelectMany(type => + Gen.OneOf("int", "str", "list[int]").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithCollections, type, fuel: 2, withStatements: true)); /// TypeSoundnessPropertyTests' optionals fact. private static Gen TypedOptionals() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2)); /// ErrorCompletenessPropertyTests.NarrowedProgram_AnalysesClean — the first caller of @@ -116,7 +116,7 @@ private static Gen TypedOptionals() => /// helper said 1, a configuration no acceptance property sampled — found by the argument-identity link, /// #2324). private static Gen TypedOptionalStatements() => - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.WithOptionals, type, fuel: 2, withStatements: true)); /// ClassInheritancePropertyTests. @@ -370,7 +370,7 @@ private static bool IsNoneTest(Node n) => // declaration shape — a hand lane (DeclarationShapes), the axis the site enumerator cannot list new YInjected("ErrorInjector.InjectDunderWrongReturnType", "SPY0321", CompilerDiagnosticSeverity.Error)), new("dunder_methods.md", "Special Methods", "__len__ / __bool__ protocol synthesis", - new Y("GenInterfaces.ModuleWithProtocolDunder", () => Gen.OneOfConst("__len__", "__bool__").SelectMany(GenInterfaces.ModuleWithProtocolDunder), n => DefNamed(n, "__len__", "__bool__")), + new Y("GenInterfaces.ModuleWithProtocolDunder", () => Gen.OneOf("__len__", "__bool__").SelectMany(GenInterfaces.ModuleWithProtocolDunder), n => DefNamed(n, "__len__", "__bool__")), new YInjected("ErrorInjector.InjectProtocolDunderRemoved", "SPY0320", CompilerDiagnosticSeverity.Error)), new("dunder_methods.md", "Special Methods", "__iter__ / __next__ iterator protocol", new Y("GenIterators.ModuleWithIterProtocol", () => GenIterators.ModuleWithIterProtocol(complete: true), n => DefNamed(n, "__next__")), @@ -442,7 +442,7 @@ private static bool IsNoneTest(Node n) => new Y("GenFunctions.ModuleWithFunctions", () => Functions(), n => CallTo(n, "compute", "process", "transform")), new YInjected("ErrorInjector.InjectUndefinedFunctionCall", "SPY0200", CompilerDiagnosticSeverity.Error)), new("expressions.md", "Index Access", "list[index]", - new Y("GenTyped.ListSubscript", () => Gen.OneOfConst("int", "str").SelectMany(element => GenTyped.ListSubscript(TypeEnv.WithCollections, element)), n => n is IndexAccess), + new Y("GenTyped.ListSubscript", () => Gen.OneOf("int", "str").SelectMany(element => GenTyped.ListSubscript(TypeEnv.WithCollections, element)), n => n is IndexAccess), new YInjected("ErrorInjector.InjectWrongTypedIndex", "SPY0220", CompilerDiagnosticSeverity.Error)), // extended_numeric_literals.md diff --git a/src/Sharpy.Compiler.Tests/Properties/Semantic/ValidatorOrderingPropertyTests.cs b/src/Sharpy.Compiler.Tests/Properties/Semantic/ValidatorOrderingPropertyTests.cs index 578ce6ffc..b1b30701d 100644 --- a/src/Sharpy.Compiler.Tests/Properties/Semantic/ValidatorOrderingPropertyTests.cs +++ b/src/Sharpy.Compiler.Tests/Properties/Semantic/ValidatorOrderingPropertyTests.cs @@ -66,7 +66,7 @@ public void ValidationDiagnostics_AreRegistrationOrderIndependent() var sink = new RejectionSink("ValidatorOrdering.ValidationDiagnostics_AreRegistrationOrderIndependent"); var gen = Gen.Select( SemanticFilter.WellTypedProgram( - Gen.OneOfConst("int", "str", "bool").SelectMany(type => + Gen.OneOf("int", "str", "bool").SelectMany(type => GenTyped.TypedProgram(TypeEnv.Default, type, fuel: 2, withStatements: true)), sink), Gen.Int, (module, shuffleSeed) => (module, shuffleSeed)); diff --git a/src/Sharpy.Compiler.Tests/Sharpy.Compiler.Tests.csproj b/src/Sharpy.Compiler.Tests/Sharpy.Compiler.Tests.csproj index 1f6114c66..41b6fea0e 100644 --- a/src/Sharpy.Compiler.Tests/Sharpy.Compiler.Tests.csproj +++ b/src/Sharpy.Compiler.Tests/Sharpy.Compiler.Tests.csproj @@ -20,7 +20,7 @@ all - + diff --git a/src/Sharpy.Core.Tests/Sharpy.Core.Tests.csproj b/src/Sharpy.Core.Tests/Sharpy.Core.Tests.csproj index 4805e80d6..86bfa7c0f 100644 --- a/src/Sharpy.Core.Tests/Sharpy.Core.Tests.csproj +++ b/src/Sharpy.Core.Tests/Sharpy.Core.Tests.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Sharpy.Lsp.Tests/Sharpy.Lsp.Tests.csproj b/src/Sharpy.Lsp.Tests/Sharpy.Lsp.Tests.csproj index b1db261f1..c5a4887a0 100644 --- a/src/Sharpy.Lsp.Tests/Sharpy.Lsp.Tests.csproj +++ b/src/Sharpy.Lsp.Tests/Sharpy.Lsp.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Sharpy.Stdlib.Tests/Sharpy.Stdlib.Tests.csproj b/src/Sharpy.Stdlib.Tests/Sharpy.Stdlib.Tests.csproj index b659a3b40..704222fba 100644 --- a/src/Sharpy.Stdlib.Tests/Sharpy.Stdlib.Tests.csproj +++ b/src/Sharpy.Stdlib.Tests/Sharpy.Stdlib.Tests.csproj @@ -19,7 +19,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/Sharpy.TestInfrastructure/Sharpy.TestInfrastructure.csproj b/src/Sharpy.TestInfrastructure/Sharpy.TestInfrastructure.csproj index e75e94e08..98ae0d6ea 100644 --- a/src/Sharpy.TestInfrastructure/Sharpy.TestInfrastructure.csproj +++ b/src/Sharpy.TestInfrastructure/Sharpy.TestInfrastructure.csproj @@ -12,7 +12,7 @@ - +