Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Sharpy.Compiler.Tests/Formatting/LineDiffTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ private static bool HasBareLineFeed(string text)
// (iii) + (vi) — CsCheck over random line lists
// ================================================================

private static readonly Gen<string[]> GenLines = Gen.OneOfConst("a", "b", "c", "", " d", "e e").Array[0, 14];
private static readonly Gen<string> GenBreak = Gen.OneOfConst("\n", "\r\n", "\r");
private static readonly Gen<string[]> GenLines = Gen.OneOf("a", "b", "c", "", " d", "e e").Array[0, 14];
private static readonly Gen<string> GenBreak = Gen.OneOf("\n", "\r\n", "\r");

/// <summary>(iii) + (ii): <c>Apply(a, Hunks(a, b)) == b</c>, and the reference diff applies to the same text.</summary>
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))");
Expand All @@ -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()))");
Expand All @@ -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(
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})");
Expand All @@ -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(
Expand All @@ -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})");
Expand Down
30 changes: 15 additions & 15 deletions src/Sharpy.Compiler.Tests/Properties/Algebraic/SetPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}))");
Expand All @@ -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}))");
Expand All @@ -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}))");
Expand All @@ -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}))");
Expand All @@ -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}))");
Expand All @@ -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}))");
Expand All @@ -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}))");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}\")");
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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})");
Expand All @@ -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})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/Sharpy.Compiler.Tests/Properties/Generators/GenComments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ internal static class GenComments
};

public static Gen<string> SourceWithLeadingComment { get; } =
Gen.OneOfConst(LeadingSources);
Gen.OneOf(LeadingSources);

public static Gen<string> SourceWithTrailingComment { get; } =
Gen.OneOfConst(TrailingSources);
Gen.OneOf(TrailingSources);

public static Gen<string> SourceWithMultipleComments { get; } =
Gen.OneOfConst(MultiCommentSources);
Gen.OneOf(MultiCommentSources);

public static Gen<string> SourceWithNestedComments { get; } =
Gen.OneOfConst(NestedSources);
Gen.OneOf(NestedSources);

public static Gen<string> SourceWithMixedComments { get; } =
Gen.OneOfConst(MixedSources);
Gen.OneOf(MixedSources);

public static Gen<string> SourceWithBlankLines { get; } =
Gen.OneOfConst(BlankLineSources);
Gen.OneOf(BlankLineSources);

public static Gen<string> CommentText { get; } =
Gen.OneOfConst(CommentTexts);
Gen.OneOf(CommentTexts);
}
24 changes: 12 additions & 12 deletions src/Sharpy.Compiler.Tests/Properties/Generators/GenExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static Gen<Identifier> IdentifierExpr(GenContext ctx) =>

public static Gen<UnaryOp> 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 });

Expand All @@ -86,7 +86,7 @@ public static Gen<UnaryOp> UnaryOpExpr(GenContext ctx) =>

public static Gen<BinaryOp> 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 });
Expand Down Expand Up @@ -174,7 +174,7 @@ public static Gen<SliceAccess> SliceAccessExpr(GenContext ctx) =>
public static Gen<ComparisonChain> 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
Expand Down Expand Up @@ -312,14 +312,14 @@ public static Gen<WalrusExpression> WalrusExpr(GenContext ctx) =>
// SourceText is exactly what the lexer recaptures ("<name>="), so they round-trip.
private static Gen<FStringPart> 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,
Expand All @@ -331,7 +331,7 @@ private static Gen<FStringPart> FStringPartGen(GenContext ctx) =>
// A nested replacement field inside the spec (PEP 701): {e:<prefix>{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
{
Expand Down Expand Up @@ -368,7 +368,7 @@ public static Gen<TStringLiteral> TStringLiteralExpr(GenContext ctx) =>
.Select(parts => new TStringLiteral { Parts = parts }));

public static Gen<BytesLiteralExpression> BytesLiteralExpr() =>
Gen.OneOfConst("hello", "test", "data", "bytes", "", "abc")
Gen.OneOf("hello", "test", "data", "bytes", "", "abc")
.Select(v => new BytesLiteralExpression { Value = v });

public static Gen<SetComprehension> SetComprehensionExpr(GenContext ctx) =>
Expand Down Expand Up @@ -474,7 +474,7 @@ public static Gen<SpreadElement> SpreadElementExpr(GenContext ctx) =>

public static Gen<ModifiedArgument> 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
{
Expand Down Expand Up @@ -541,7 +541,7 @@ public static Gen<Expression> AmbiguousHotspot(GenContext ctx) =>
// quote-containing f-string with a colliding delimiter that would not re-parse.
public static Gen<FStringLiteral> FStringWithQuotesExpr(GenContext ctx) =>
Gen.Select(
Gen.OneOfConst("\"", "\"x\"", "say \"", "[\"]"),
Gen.OneOf("\"", "\"x\"", "say \"", "[\"]"),
IdentifierExpr(ctx),
(quoted, e) => new FStringLiteral
{
Expand Down Expand Up @@ -642,7 +642,7 @@ private static Gen<Expression> SubscriptBase(GenContext ctx) =>

private static Gen<KeywordArgument> KeywordArgGen(GenContext ctx) =>
Gen.Select(
Gen.OneOfConst(KeywordArgNames),
Gen.OneOf(KeywordArgNames),
CallArg(ctx),
(name, val) => new KeywordArgument { Name = name, Value = val });

Expand Down
Loading
Loading