Exemplo n.º 1
0
    public void PatternMask_UpdateFrom()
    {
        var mask = new PatternMask("(aaa) 000");

        mask.MaskChars.Length.Should().Be(3); // '0', 'a' and '*'
        mask.CleanDelimiters.Should().BeFalse();
        mask.Placeholder.Should().BeNull();
        mask.SetText("abc12");
        mask.Selection = (1, 2);
        mask.ToString().Should().Be("([a]bc) 12");
        mask.UpdateFrom(new PatternMask("999")
        {
            Placeholder = '#', MaskChars = new [] { new MaskChar('9', "[0-9]") }, CleanDelimiters = true
        });
        mask.MaskChars.Length.Should().Be(1); // '9'
        mask.MaskChars[0].Char.Should().Be('9');
        mask.MaskChars[0].Regex.Should().Be("[0-9]");
        mask.CleanDelimiters.Should().BeTrue();
        mask.Placeholder.Should().Be('#');
        // state should be preserved (Text, Caret/Selection)
        mask.ToString().Should().Be("1[2]#");
        mask.UpdateFrom(null);
        mask.MaskChars.Length.Should().Be(1); // '9'
        mask.MaskChars[0].Char.Should().Be('9');
        mask.MaskChars[0].Regex.Should().Be("[0-9]");
        mask.CleanDelimiters.Should().BeTrue();
        mask.Placeholder.Should().Be('#');
        // state should be preserved (Text, Caret/Selection)
        mask.ToString().Should().Be("1[2]#");
    }
Exemplo n.º 2
0
    public void PatternMask_TransformationFunc()
    {
        var mask = new PatternMask("(aaa) 000")
        {
            Transformation  = c => c.ToString().ToUpperInvariant()[0],
            CleanDelimiters = true,
        };

        mask.Insert("xyä123");
        mask.ToString().Should().Be("(XYÄ) 123|");
        mask.GetCleanText().Should().Be("XYÄ123");
        mask.SetText("ABß...");
        mask.ToString().Should().Be("(ABß) |");
        mask.GetCleanText().Should().Be("ABß");
    }