Skip to content

Commit

Permalink
Add tests for ensuring predefined method list is consistent with impl…
Browse files Browse the repository at this point in the history
…ementation
  • Loading branch information
desplesda committed Sep 18, 2023
1 parent 9215e92 commit 5179d86
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions YarnSpinner.LanguageServer.Tests/LanguageServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,54 @@ public async Task Server_OnJumpCommand_ShouldReceiveNodeNameCompletions()
"because while 'Node2' is a node we could jump to, we're currently in a syntax error");
}
}

[Fact]
public void Workspace_BuiltInFunctions_MatchesDefaultLibrary()
{
// Given
var builtInActionDecls = Workspace.GetPredefinedActions().Where(a => a.Type == ActionType.Function).Select(f => f.Declaration).ToDictionary(d => d.Name);

var storage = new Yarn.MemoryVariableStore();
var dialogue = new Yarn.Dialogue(storage);
var library = dialogue.Library;

var libraryDecls = Yarn.Compiler.Compiler.GetDeclarationsFromLibrary(library).Item1.ToDictionary(d => d.Name);

// Then

// All entries in the predefined actions must map to an entry in the library
using (new AssertionScope()) {
foreach (var actionDecl in builtInActionDecls.Values) {

actionDecl.Should().NotBeNull();

libraryDecls.Should().ContainKey(actionDecl!.Name);

var libraryDecl = libraryDecls[actionDecl.Name];

actionDecl.Should().BeEquivalentTo(libraryDecl, (config) =>
{
return config.Excluding(info => info.Description);
});
}
}

// All entries in the library except operators must map to an entry
// in the predefined actions
using (new AssertionScope()) {
foreach (var libraryDecl in libraryDecls.Values) {

builtInActionDecls.Should().ContainKey(libraryDecl.Name);

var actionDecl = builtInActionDecls[libraryDecl.Name];

libraryDecl.Should().BeEquivalentTo(actionDecl, (config) =>
{
return config.Excluding(info => info.Description);
});
}
}
}
}

}

0 comments on commit 5179d86

Please sign in to comment.