Skip to content

Commit

Permalink
Merge branch 'main' into tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Sep 12, 2023
2 parents a4d7c20 + 10d26b5 commit a83b59d
Show file tree
Hide file tree
Showing 85 changed files with 4,418 additions and 379 deletions.
42 changes: 42 additions & 0 deletions src/Draco.Compiler.Tests/EndToEnd/BclUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,46 @@ public func foo(): string {

Assert.Equal("1;2;3", result);
}

[Fact]
public void ForLoopSumming()
{
var assembly = Compile("""
import System.Collections.Generic;
public func sum(ns: IEnumerable<int32>): int32 {
var s = 0;
for (n in ns) s += n;
return s;
}
""");
var result = Invoke<int>(
assembly: assembly,
methodName: "sum",
args: new[] { 1, 1, 2, 3, 5, 8, 13 });

Assert.Equal(33, result);
}

[Fact]
public void ForLoopPrinting()
{
var assembly = Compile("""
import System.Collections.Generic;
import System.Console;
public func log(ns: IEnumerable<int32>) {
for (n in ns) Write(n);
}
""");
var stringWriter = new StringWriter();
_ = Invoke<object?>(
assembly: assembly,
methodName: "log",
args: new[] { 1, 1, 2, 3, 5, 8, 13 },
stdin: null,
stdout: stringWriter);

Assert.Equal("11235813", stringWriter.ToString());
}
}
Loading

0 comments on commit a83b59d

Please sign in to comment.