Skip to content

Commit

Permalink
IsEmpty supports UO (#2672)
Browse files Browse the repository at this point in the history
Issue #2671.
Still need to verify other functions.
  • Loading branch information
anderson-joyle authored Oct 3, 2024
1 parent 1507ae4 commit 8cb6584
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ internal class BuiltinFunctionsCore
public static readonly TexlFunction IsBlankOptionSetValue = _library.Add(new IsBlankOptionSetValueFunction());
public static readonly TexlFunction IsBlankOrError = _library.Add(new IsBlankOrErrorFunction());
public static readonly TexlFunction IsBlankOrErrorOptionSetValue = _library.Add(new IsBlankOrErrorOptionSetValueFunction());
public static readonly TexlFunction IsEmpty = _library.Add(new IsEmptyFunction());
public static readonly TexlFunction IsEmpty = _library.Add(new IsEmptyFunction());
public static readonly TexlFunction IsEmpty_UO = _library.Add(new IsEmptyFunction_UO());
public static readonly TexlFunction IsError = _library.Add(new IsErrorFunction());
public static readonly TexlFunction IsNumeric = _library.Add(new IsNumericFunction());
public static readonly TexlFunction ISOWeekNum = _library.Add(new ISOWeekNumFunction());
Expand Down Expand Up @@ -253,7 +254,7 @@ internal class BuiltinFunctionsCore
public static readonly TexlFunction Decimal = _featureGateFunctions.Add(new DecimalFunction());
public static readonly TexlFunction Decimal_UO = _featureGateFunctions.Add(new DecimalFunction_UO());
public static readonly TexlFunction Float = _featureGateFunctions.Add(new FloatFunction());
public static readonly TexlFunction Float_UO = _featureGateFunctions.Add(new FloatFunction_UO());
public static readonly TexlFunction Float_UO = _featureGateFunctions.Add(new FloatFunction_UO());
public static readonly TexlFunction IsUTCToday = _featureGateFunctions.Add(new IsUTCTodayFunction());
public static readonly TexlFunction UTCNow = _featureGateFunctions.Add(new UTCNowFunction());
public static readonly TexlFunction UTCToday = _featureGateFunctions.Add(new UTCTodayFunction());
Expand Down
15 changes: 15 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/IsEmpty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp
return fValid;
}
}

internal sealed class IsEmptyFunction_UO : BuiltinFunction
{
public override bool IsSelfContained => true;

public IsEmptyFunction_UO()
: base("IsEmpty", TexlStrings.AboutIsEmpty, FunctionCategories.Table | FunctionCategories.Information, DType.Boolean, 0, 1, 1, DType.UntypedObject)
{
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
{
yield return new[] { TexlStrings.IsEmptyArg1 };
}
}
}
11 changes: 11 additions & 0 deletions src/libraries/Microsoft.PowerFx.Interpreter/Functions/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,17 @@ static Library()
returnBehavior: ReturnBehavior.AlwaysEvaluateAndReturnResult,
targetFunction: IsEmpty)
},
{
BuiltinFunctionsCore.IsEmpty_UO,
StandardErrorHandling<UntypedObjectValue>(
BuiltinFunctionsCore.IsEmpty_UO.Name,
expandArguments: NoArgExpansion,
replaceBlankValues: DoNotReplaceBlank,
checkRuntimeTypes: ExactValueTypeOrBlank<UntypedObjectValue>,
checkRuntimeValues: UntypedObjectArrayChecker,
returnBehavior: ReturnBehavior.ReturnBlankIfAnyArgIsBlank,
targetFunction: IsEmpty_UO)
},
{
BuiltinFunctionsCore.IsError,
NoErrorHandling(IsError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ public static FormulaValue First_UO(IRContext irContext, UntypedObjectValue[] ar
var result = element[0];

return new UntypedObjectValue(irContext, result);
}

public static FormulaValue IsEmpty_UO(IRContext irContext, UntypedObjectValue[] args)
{
var element = args[0].Impl;
var len = element.GetArrayLength();

if (len == 0)
{
return FormulaValue.New(true);
}

return FormulaValue.New(false);
}

public static FormulaValue Last_UO(IRContext irContext, UntypedObjectValue[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ true
),a > 10))
true

// Untyped object
>> IsEmpty(ParseJSON("[{""a"":1}]"))
false

>> IsEmpty(ParseJSON("[]"))
true

>> IsEmpty(ParseJSON("1"))
Error({Kind:ErrorKind.InvalidArgument})

// INVALID ARGUMENTS
>> IsEmpty("")
Errors: Error 8-10: Invalid argument type (Text). Expecting a Table value instead.
Expand Down

0 comments on commit 8cb6584

Please sign in to comment.