Skip to content
Open
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
8 changes: 7 additions & 1 deletion kerboscript_tests/integration/func.ks
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ function a
print("a").
}

a().
a().

set b to {
print("b").
}.

b().
15 changes: 15 additions & 0 deletions kerboscript_tests/integration/short_circuit.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function a {
print("a").
return false.
}

function b {
print("b").
return true.
}

print(a() and b()).
print(a() or b()).
print(b() and a()).
print(b() or a()).
25 changes: 24 additions & 1 deletion src/kOS.Safe.Test/Execution/SimpleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void TestFunc()
RunScript("integration/func.ks");
RunSingleStep();
AssertOutput(
"a"
"a",
"b"
);
}

Expand Down Expand Up @@ -116,5 +117,27 @@ public void TestSuffixes()
"False"
);
}

[Test]
public void TestShortCircuit()
{
// Test that boolean logic short circuits
RunScript("integration/short_circuit.ks");
RunSingleStep();
AssertOutput(
"a",
// short circuit away b
"False",
"a",
"b",
"True",
"b",
"a",
"False",
"b",
// short circuit away a
"True"
);
}
}
}
1,460 changes: 443 additions & 1,017 deletions src/kOS.Safe/Compilation/KS/Compiler.cs

Large diffs are not rendered by default.

Loading