Browse Source
* BoolConverters.Not should support ConvertBack * Add previously missing BoolConvertersTests and StringConvertersTests * Fix "false & true" test casepull/17682/head
committed by
GitHub
3 changed files with 107 additions and 1 deletions
@ -0,0 +1,51 @@ |
|||
using System.Globalization; |
|||
using Avalonia.Data.Converters; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Base.UnitTests.Data; |
|||
|
|||
public class BoolConvertersTests |
|||
{ |
|||
[Fact] |
|||
public void BoolConverters_Not_Works_TwoWay() |
|||
{ |
|||
var converter = BoolConverters.Not; |
|||
var result = converter.Convert(true, typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.False(Assert.IsType<bool>(result)); |
|||
|
|||
result = converter.ConvertBack(false, typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.True(Assert.IsType<bool>(result)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void BoolConverters_Not_Returns_Unset_On_Invalid_Input() |
|||
{ |
|||
var converter = BoolConverters.Not; |
|||
var result = converter.Convert(1234, typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(false, false, false)] |
|||
[InlineData(false, true, false)] |
|||
[InlineData(true, false, false)] |
|||
[InlineData(true, true, true)] |
|||
public void BoolConverters_And_Works(bool a, bool b, bool y) |
|||
{ |
|||
var converter = BoolConverters.And; |
|||
var result = converter.Convert([a, b], typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.Equal(y, Assert.IsType<bool>(result)); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(false, false, false)] |
|||
[InlineData(false, true, true)] |
|||
[InlineData(true, false, true)] |
|||
[InlineData(true, true, true)] |
|||
public void BoolConverters_Or_Works(bool a, bool b, bool y) |
|||
{ |
|||
var converter = BoolConverters.Or; |
|||
var result = converter.Convert([a, b], typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.Equal(y, Assert.IsType<bool>(result)); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Globalization; |
|||
using Avalonia.Data.Converters; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Base.UnitTests.Data; |
|||
|
|||
public class StringConvertersTests |
|||
{ |
|||
[Theory] |
|||
[InlineData("hello", false)] |
|||
[InlineData("", true)] |
|||
[InlineData(null, true)] |
|||
public void StringConverters_IsNullOrEmpty_Works(string input, bool expected) |
|||
{ |
|||
var converter = StringConverters.IsNullOrEmpty; |
|||
var result = converter.Convert(input, typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.Equal(expected, Assert.IsType<bool>(result)); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("hello", true)] |
|||
[InlineData("", false)] |
|||
[InlineData(null, false)] |
|||
public void StringConverters_IsNotNullOrEmpty_Works(string input, bool expected) |
|||
{ |
|||
var converter = StringConverters.IsNotNullOrEmpty; |
|||
var result = converter.Convert(input, typeof(bool), null, CultureInfo.CurrentCulture); |
|||
Assert.Equal(expected, Assert.IsType<bool>(result)); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue