-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathNativeStructTest.cs
111 lines (81 loc) · 3.4 KB
/
NativeStructTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*!
* Copyright (c) 2016 Denis Kuzmin <x-3F@outlook.com> github/3F
* Copyright (c) Conari contributors https://github.com/3F/Conari/graphs/contributors
* Licensed under the MIT License (MIT).
* See accompanying LICENSE.txt file or visit https://github.com/3F/Conari
*/
using System;
using System.Runtime.InteropServices;
using net.r_eg.Conari;
using net.r_eg.Conari.Types;
using Xunit;
using static net.r_eg.Conari.Static.Members;
namespace ConariTest.Types
{
using static _svc.TestHelper;
public class NativeStructTest
{
[Fact]
public void allocTest1()
{
using var c = ConariL.Make(new(gCfgIsolatedRxW), out dynamic l);
using var u = NativeStruct.Make.f<UIntPtr>("start", "end").Struct;
Assert.True(l.match<bool>(c._T("0123456"), c._T("234"), EngineOptions.F_MATCH_RESULT, u));
dynamic v = u.Access;
Assert.Equal((UIntPtr)2, v.start);
Assert.Equal((UIntPtr)5, v.end);
Assert.True(l.match<bool>(c._T("0123456"), c._T("1*5"), EngineOptions.F_MATCH_RESULT, (IntPtr)u));
v = u.Access;
Assert.Equal((UIntPtr)1, v.start);
Assert.Equal((UIntPtr)6, v.end);
}
[Fact]
public void allocTest2()
{
using var c = ConariL.Make(new(gCfgIsolatedRxW), out dynamic l);
using var u = new NativeStruct();
Assert.True(l.match<bool>(c._T("0123456"), c._T("234"), EngineOptions.F_MATCH_RESULT, u));
u.Native
.f<UIntPtr>("start", "end")
.build(out dynamic mres);
Assert.Equal((UIntPtr)2, mres.start);
Assert.Equal((UIntPtr)5, mres.end);
}
[Fact]
public void allocTest3()
{
using var c = ConariL.Make(new(gCfgIsolatedRxW), out dynamic l);
using var u = new NativeStruct<MatchResult>();
Assert.True(l.match<bool>(c._T("system"), c._T("syStem"), EngineOptions.F_ICASE | EngineOptions.F_MATCH_RESULT, u));
Assert.Equal(n(0), u.Data.start);
Assert.Equal(n(6), u.Data.end);
Assert.False(l.match<bool>(c._T("system"), c._T("1"), EngineOptions.F_NONE, (IntPtr)u));
Assert.Equal(MatchResult.npos, u.read().Data.start);
Assert.True(l.matchOfs<bool>(c._T("number_str = '+12'"), c._T("str"), n(5), EngineOptions.F_NONE, u));
Assert.Equal(MatchResult.npos, u.read().Data.start);
Assert.True(l.matchOfs<bool>(c._T("number_str = '+12'"), c._T("str"), n(5), EngineOptions.F_MATCH_RESULT, (IntPtr)u));
u.read();
Assert.Equal(n(7), u.Data.start);
Assert.Equal(n(10), u.Data.end);
Assert.False(l.matchOfs<bool>(c._T("number_str = '+12'"), c._T("str"), n(8), EngineOptions.F_NONE, u));
Assert.Equal(MatchResult.npos, u.read().Data.start);
}
#region decl struct way
private static UIntPtr n(nuint v) => v;
[StructLayout(LayoutKind.Sequential)]
private struct MatchResult
{
public static readonly UIntPtr npos = new(Is64bit ? ulong.MaxValue : uint.MaxValue);
public UIntPtr start;
public UIntPtr end;
}
[Flags]
private enum EngineOptions: uint
{
F_NONE = 0,
F_ICASE = 0x001,
F_MATCH_RESULT = 0x002,
}
#endregion
}
}