1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 15:24:10 +02:00
Beef/BeefLibs/corlib/src/Test.bf

79 lines
1.4 KiB
Beef
Raw Normal View History

using System.IO;
2019-08-23 11:56:54 -07:00
namespace System
{
class Test
{
public class TestStream : Stream
2019-08-23 11:56:54 -07:00
{
public override int64 Position
{
get
{
Runtime.FatalError();
}
set
{
}
}
public override int64 Length
{
get
{
Runtime.FatalError();
}
}
public override bool CanRead
{
get
{
return false;
}
}
public override bool CanWrite
{
get
{
return true;
}
}
public override Result<int> TryRead(Span<uint8> data)
{
return default;
}
public override Result<int> TryWrite(Span<uint8> data)
{
String str = scope String();
str.Append((char8*)data.Ptr, data.Length);
Internal.[Friend]Test_Write(str.CStr());
return .Ok(data.Length);
}
public override void Close()
{
}
2019-08-23 11:56:54 -07:00
}
public static void FatalError(String msg = "Test fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
2019-08-23 11:56:54 -07:00
{
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
Internal.[Friend]Test_Error(failStr);
2019-08-23 11:56:54 -07:00
}
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
2019-08-23 11:56:54 -07:00
{
if (!condition)
{
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
Internal.[Friend]Test_Error(failStr);
}
2019-08-23 11:56:54 -07:00
}
}
}