public void TestSingletonRange()
 {
     var set = new CharacterSet(new[] { 'y' });
     Assert.False(set.Contains('x'));
     Assert.True(set.Contains('y'));
     Assert.False(set.Contains('z'));
 }
 public void TestProperRange()
 {
     var set = new CharacterSet(Enumerable.Range(0, 20).Select(x => (char)('b' + x)));
     Assert.False(set.Contains('a'));
     Assert.True(set.Contains('b'));
     Assert.True(set.Contains((char)('b' + 19)));
     Assert.False(set.Contains((char)('b' + 20)));
 }
 public void TestEmpty()
 {
     var set = new CharacterSet(new char[0]);
     Assert.False(set.Contains(' '));
     Assert.False(set.Contains('\x0'));
     Assert.False(set.Contains('\x9f93'));
     Assert.False(set.Contains('ä'));
 }
 public void TestProperAndSingletonRanges()
 {
     var set = new CharacterSet(Enumerable.Range(0, 3).Select(x => (char)('b' + x)).Union(
         new[] { '5' }));
     Assert.False(set.Contains('a'));
     Assert.True(set.Contains('b'));
     Assert.True(set.Contains('c'));
     Assert.True(set.Contains('d'));
     Assert.False(set.Contains('e'));
     Assert.False(set.Contains('4'));
     Assert.True(set.Contains('5'));
     Assert.False(set.Contains('6'));
 }
 public void TestTwoProperRanges()
 {
     var set = new CharacterSet(Enumerable.Range(0, 3).Select(x => (char)('b' + x)).Union(
         Enumerable.Range(0, 5).Select(x => (char)('2' + x))));
     Assert.False(set.Contains('a'));
     Assert.True(set.Contains('b'));
     Assert.True(set.Contains('c'));
     Assert.True(set.Contains('d'));
     Assert.False(set.Contains('e'));
     Assert.False(set.Contains('1'));
     Assert.True(set.Contains('2'));
     Assert.True(set.Contains('6'));
     Assert.False(set.Contains('7'));
 }
Beispiel #6
0
 public EditableText(string content, int maxLength, CharacterSet allowedChars, AssaultWingCore game, Action changedCallback)
 {
     if (maxLength < 0) throw new ArgumentException("Maximum length cannot be negative");
     if (content.Length > maxLength) throw new ArgumentException("Initial content is longer than maximum length");
     MaxLength = maxLength;
     _allowedChars = allowedChars;
     _content = new StringBuilder(content, maxLength);
     _game = game;
     _changedCallback = changedCallback;
     WeakEventHandler<char>.Register(game.Window,
         (window, handler) => window.KeyPress += handler,
         (window, handler) => window.KeyPress -= handler,
         this,
         (self, sender, args) => self.KeyPressHandler(sender, args));
 }