Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISXB-358 wildcards not working #1665

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

ritamerkl
Copy link
Collaborator

@ritamerkl ritamerkl commented Mar 29, 2023

Description

Fixes the wildcard not working bug

Changes made

Changed:
BindingMasks get compared to Bindings with another method (StringMatches)
Fixed:
Wildcards working now
Added:
tests for wildcards

cases checked:

  • sign at the beginning
  • sign at the end

Notes

Please write down any additional notes, remove the section if not applicable.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like various tests are failing.

I think at minimum MatchesMask needs a path!=null check at the start

[Error] NullReferenceException while resolving binding 'Move:/leftStick[Gamepad]' in action map 'InGameHintsActions (UnityEngine.InputSystem.InputActionAsset):Gameplay''.

https://unity-ci.cds.internal.unity3d.com/job/22912980

I'd also like to see more detail in the PR description about cases checked.
It would be useful to also add a new test for the specific case we are fixing in this PR

@lyndon-unity
Copy link
Collaborator

There are several test failures which seems to highlight problems with this change.

@ritamerkl ritamerkl changed the title ISXB-358 #resolve ISXB-358 wildcards not working Apr 4, 2023
Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable for the specific cases but I've left a query about the non path cases.

Assert.That(mask.MatchesMask(ref binding), Is.False);
mask.path = "<Keyboard>/*";
Assert.That(mask.MatchesMask(ref binding), Is.True);
mask.path = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to split some out into a new tests to improve readability

This is a good guide on test naming
https://internaldocs.unity.com/automation/Guidelines/naming/
UnitOfWork_WhenStateUnderTest_ProducesExpectedBehavior()

Perhaps some like:
Controls_BindingWithoutMask_Matches
Controls_BindingMaskWithSpecificKey_IgnoresOtherKey
Controls_BindingMaskWithWildcard_Matches
Controls_BindingMaskWithNullPath_Ignored
Controls_BindingMaskWithNullName_Ignored
Controls_BindingMaskWithMousePath_FiltersOutKeyboard

Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So overall I'm actually now nervous about this change and think we need to do more work on performance and robustness.

I.e. we'd need to add some test cases where binding path contains wildcards.

@@ -842,6 +842,14 @@ public bool Matches(InputBinding binding)
return Matches(ref binding);
}

internal bool MatchesMask(ref InputBinding binding)
{
if (path != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point but with nested ifs I usually add braces around the code within the outer if, just to make it clear and avoid errors if someone adds to the inner if.

However in this case you could also collapse into a single if (path != null && InputControlPath....)

Minor point and not needing to hold up PR.

@@ -481,6 +481,12 @@ private static string FindControlLayoutRecursive(ref PathParser parser, InputCon
return currentResult;
}

internal static bool BindingPathMatchesMask(string mask, string bindingPath)
{
var bindingPathString = new InternedString(bindingPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about the InternedString creation here which is creating a lowercase variant of the bindingPath string which will be doing a GC allocation

This BindingPathMatchesMask is called inside a loop over all bindings so this will be generating a lot of garbage.

Perhaps StringMatches could be altered to take a string variant. However I think it uses InternedString for the speed of the internal checks (as we've seen in the separate PR about turkish letter support)

I'm also seeing that StringMatches says the second 'matchTo' parameter may not contain wildcards and I think the bindingPath is allowed to contain wildcards.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes binding path can contain wildcards
https://docs.unity3d.com/Packages/[email protected]/manual/ActionBindings.html

A Binding path can also contain wildcards, such as /button*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants