зеркало из https://github.com/microsoft/Power-Fx.git
Fix OptionSets in symbol tables (#2705)
Make sure composed tables return all option sets
This commit is contained in:
Родитель
37533140c9
Коммит
2434fd3faf
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using Microsoft.PowerFx.Core.Binding;
|
||||
using Microsoft.PowerFx.Core.Binding.BindInfo;
|
||||
using Microsoft.PowerFx.Core.Entities;
|
||||
|
@ -163,6 +164,20 @@ namespace Microsoft.PowerFx
|
|||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<KeyValuePair<string, OptionSet>> OptionSets
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (ReadOnlySymbolTable st in _symbolTables)
|
||||
{
|
||||
foreach (KeyValuePair<string, OptionSet> kvp in st.OptionSets)
|
||||
{
|
||||
yield return kvp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Lookup(DName name, out NameLookupInfo nameInfo, NameLookupPreferences preferences = NameLookupPreferences.None)
|
||||
{
|
||||
foreach (INameResolver table in _symbolTables)
|
||||
|
|
|
@ -347,8 +347,8 @@ namespace Microsoft.PowerFx
|
|||
|
||||
public IEnumerable<string> FunctionNames => this.Functions.FunctionNames;
|
||||
|
||||
public IEnumerable<KeyValuePair<string, OptionSet>> OptionSets => _variables.Where(kvp => kvp.Value.Kind == BindKind.OptionSet)
|
||||
.Select(kvp => new KeyValuePair<string, OptionSet>(kvp.Key, (OptionSet)kvp.Value.Data));
|
||||
public virtual IEnumerable<KeyValuePair<string, OptionSet>> OptionSets => _variables.Where(kvp => kvp.Value.Kind == BindKind.OptionSet)
|
||||
.Select(kvp => new KeyValuePair<string, OptionSet>(kvp.Key, (OptionSet)kvp.Value.Data));
|
||||
|
||||
// Which enums are available.
|
||||
// These do not compose - only bottom one wins.
|
||||
|
|
|
@ -306,6 +306,25 @@ namespace Microsoft.PowerFx.Core.Tests
|
|||
Assert.Equal(2, func3.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OptionSetTests()
|
||||
{
|
||||
var os1 = new OptionSet("os1", DisplayNameProvider.New(new Dictionary<DName, DName>() { { new DName("ln1"), new DName("dn1") } }));
|
||||
var os2 = new OptionSet("os2", DisplayNameProvider.New(new Dictionary<DName, DName>() { { new DName("ln2"), new DName("dn2") }, { new DName("ln3"), new DName("dn3") } }));
|
||||
|
||||
var st1 = new SymbolTable();
|
||||
st1.AddOptionSet(os1);
|
||||
|
||||
Assert.Single(st1.OptionSets);
|
||||
|
||||
var st2 = new SymbolTable();
|
||||
st2.AddOptionSet(os2);
|
||||
|
||||
var st3 = SymbolTable.Compose(st1, st2);
|
||||
|
||||
Assert.Equal(2, st3.OptionSets.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VoidIsNotAllowed()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче