use inline_csharp::csharp;
#[test]
fn csharp_runtime_list_of_nullable_string_array() {
let v: Vec<Option<Vec<String>>> = csharp! {
using System.Collections.Generic;
static List<string[]?> Run() {
return new List<string[]?> {
new string[] { "a", "b" },
null,
new string[] { "c" }
};
}
}
.unwrap();
assert_eq!(
v,
vec![
Some(vec!["a".to_string(), "b".to_string()]),
None,
Some(vec!["c".to_string()]),
]
);
}
#[test]
fn csharp_runtime_nullable_list_int_present() {
let v: Option<Vec<i32>> = csharp! {
using System.Collections.Generic;
static List<int>? Run() {
return new List<int> { 1, 2, 3 };
}
}
.unwrap();
assert_eq!(v, Some(vec![1i32, 2, 3]));
}
#[test]
fn csharp_runtime_nullable_list_int_absent() {
let v: Option<Vec<i32>> = csharp! {
using System.Collections.Generic;
static List<int>? Run() {
return null;
}
}
.unwrap();
assert_eq!(v, None);
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_int_present() {
let v: Option<Vec<Option<i32>>> = csharp! {
using System.Collections.Generic;
static List<int?>? Run() {
return new List<int?> { 1, null, 3 };
}
}
.unwrap();
assert_eq!(v, Some(vec![Some(1i32), None, Some(3)]));
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_int_absent() {
let v: Option<Vec<Option<i32>>> = csharp! {
using System.Collections.Generic;
static List<int?>? Run() {
return null;
}
}
.unwrap();
assert_eq!(v, None);
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_int_array_present() {
let v: Option<Vec<Option<Vec<i32>>>> = csharp! {
using System.Collections.Generic;
static List<int[]?>? Run() {
return new List<int[]?> {
new int[] { 10, 20 },
null,
new int[] { 30 }
};
}
}
.unwrap();
assert_eq!(
v,
Some(vec![Some(vec![10i32, 20]), None, Some(vec![30i32]),])
);
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_int_array_absent() {
let v: Option<Vec<Option<Vec<i32>>>> = csharp! {
using System.Collections.Generic;
static List<int[]?>? Run() {
return null;
}
}
.unwrap();
assert_eq!(v, None);
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_2d_string_array_present() {
let v: Option<Vec<Option<Vec<Vec<String>>>>> = csharp! {
using System.Collections.Generic;
static List<string[][]?>? Run() {
return new List<string[][]?> {
new string[][] {
new string[] { "foo", "bar" },
new string[] { "baz" }
},
null
};
}
}
.unwrap();
assert_eq!(
v,
Some(vec![
Some(vec![
vec!["foo".to_string(), "bar".to_string()],
vec!["baz".to_string()],
]),
None,
])
);
}
#[test]
fn csharp_runtime_nullable_list_of_nullable_2d_string_array_absent() {
let v: Option<Vec<Option<Vec<Vec<String>>>>> = csharp! {
using System.Collections.Generic;
static List<string[][]?>? Run() {
return null;
}
}
.unwrap();
assert_eq!(v, None);
}