Skip to content

Commit

Permalink
Add traits test extension for TokenKind
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Mar 26, 2019
1 parent cf176e3 commit 563e7e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/CSharpMinifier/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public static TokenKindTraits GetTraits(this TokenKind kind)
? TraitsByKind[i]
: throw new ArgumentOutOfRangeException(nameof(kind));
}

public static bool HasTraits(this TokenKind kind, TokenKindTraits traits) =>
(kind.GetTraits() & traits) == traits;
}

public readonly struct Token : IEquatable<Token>
Expand Down
4 changes: 3 additions & 1 deletion tests/TokenKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public class TokenKindTests

public void Traits(TokenKind kind, TokenKindTraits traits)
{
Assert.That(kind.GetTraits(), Is.EqualTo(traits));
Assert.That(kind.GetTraits() , Is.EqualTo(traits));
Assert.That(kind.HasTraits(traits) , Is.True);
Assert.That(kind.HasTraits(~traits), Is.False);
}

[Test]
Expand Down

0 comments on commit 563e7e6

Please sign in to comment.