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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ private string FormatStandardRecord(RecordValue record, HashSet<string> selected
{
StringBuilder resultString = new StringBuilder();

if (record == null)
{
return "Blank()";
}

IEnumerable<string> fieldNames = selectedFieldNames ?? record.Type.FieldNames;

var separator = string.Empty;
Expand Down Expand Up @@ -97,7 +102,8 @@ private HashSet<string> TryGetSpecialFieldNames(TableValue table)

private HashSet<string> TryGetSpecialFieldNames(RecordValue record)
{
if (record.TryGetSpecialFieldName(SpecialFieldKind.PrimaryKey, out var primaryKey) &&
if (record != null &&
record.TryGetSpecialFieldName(SpecialFieldKind.PrimaryKey, out var primaryKey) &&
record.TryGetSpecialFieldName(SpecialFieldKind.PrimaryName, out var primaryName))
{
return new HashSet<string>() { primaryName, primaryKey };
Expand Down Expand Up @@ -268,7 +274,7 @@ private string FormatStandardTable(TableValue table, HashSet<string> selectedFie
}
else
{
resultString.Append(row.IsError ? row.Error?.Errors?[0].Message : "Blank()");
resultString.Append(row.IsError ? row.Error?.Errors?[0].Message : "<blank record>");
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/tests/Microsoft.PowerFx.Repl.Tests.Shared/ReplTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
using Microsoft.PowerFx.Repl.Services;
using Microsoft.PowerFx.Types;
using Xunit;

Expand All @@ -20,6 +21,7 @@ public class ReplTests
{
private readonly PowerFxREPL _repl;
private readonly TestReplOutput _output = new TestReplOutput();
private readonly StandardFormatter _formatter = new StandardFormatter();

public ReplTests()
{
Expand All @@ -34,6 +36,7 @@ public ReplTests()
Engine = engine,
Output = _output,
AllowSetDefinitions = true,
ValueFormatter = _formatter,
AllowUserDefinedFunctions = true,
ParserOptions = new ParserOptions() { AllowsSideEffects = true }
};
Expand Down Expand Up @@ -527,6 +530,59 @@ a b
Assert.True(_output.Get(OutputKind.Repl, trim: false) == string.Empty);
}

[Fact]
public async Task BlankFormatTable()
{
await _repl.WritePromptAsync();

_formatter.FormatTable = true;

var log1p = _output.Get(OutputKind.Control, trim: false);
Assert.True(log1p == @"
>> ");

await _repl.HandleCommandAsync(
"Table(Blank(),{a:Blank(),b:true},Blank(),{a:42,b:Blank()})");
var log2 = _output.Get(OutputKind.Repl, trim: false);
var expected2 = @"
a b
==== ======
<BlankRecord>
true
<BlankRecord>
42
";
Assert.True(Regex.Replace(log2, @"[ ]*\r?\n", @"\n") == Regex.Replace(expected2, @"[ ]*\r?\n", @"\n"));

await _repl.WritePromptAsync();

var log2p = _output.Get(OutputKind.Control, trim: false);
Assert.True(log2p == @"
>> ");

_formatter.FormatTable = false;

await _repl.HandleCommandAsync(
"Table(Blank(),{a:Blank(),b:true},Blank(),{a:42,b:Blank()})");
var log3 = _output.Get(OutputKind.Repl, trim: false);
var expected3 =
@"[Blank(), {a:Blank(), b:true}, Blank(), {a:42, b:Blank()}]
";
Assert.True(Regex.Replace(log3, @"[ ]*\r?\n", @"\n") == Regex.Replace(expected3, @"[ ]*\r?\n", @"\n"));

_formatter.FormatTable = true;

await _repl.WritePromptAsync();

var log3p = _output.Get(OutputKind.Control, trim: false);
Assert.True(log3p == @"
>> ");

Assert.True(_output.Get(OutputKind.Error, trim: false) == string.Empty);
Assert.True(_output.Get(OutputKind.Warning, trim: false) == string.Empty);
Assert.True(_output.Get(OutputKind.Repl, trim: false) == string.Empty);
}

[Fact]
public async Task NewlinesNamedFormulaFormatTable()
{
Expand Down
Loading