Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using Xunit;
 
public abstract class BaseStringToIntegerArrayTests : PlDotNetTest
{
    protected abstract string FunctionBody { get; }
    protected abstract LanguageType Language { get; }
 
    protected string cteStatement = string.Empty;
 
    public BaseStringToIntegerArrayTests()
    {
        FunctionInfo = new SqlFunctionInfo
        {
            Name = "StringToIntegerArray",
            Arguments = new List<FunctionArgument> { new FunctionArgument("args", "text[]") },
            ReturnType = "SETOF integer",
            Body = FunctionBody,
            Language = Language,
            IsStrict = false,
        };
    }
 
    protected void SetupTest(string cteStatement)
    {
        this.cteStatement = cteStatement;
        FunctionInfo!.CteStatement = cteStatement;
    }
 
    public static IEnumerable<object[]> TestCases()
    {
        yield return new object[]
        {
            "c#-srf-comparison",
            "comparison-1",
            @"WITH data1 AS (
    WITH data2 AS (
        SELECT ARRAY ['1', '0 ', '-3', NULL::text, '99'] as input
    )
    SELECT
        StringToIntegerArray(input) AS col1,
        string_to_integer_array_plsql(input) AS col2
    FROM data2
)",
            "bool_and(COALESCE(col1 = col2, false)) AS all_equal"
        };
    }
 
    [Theory]
    [MemberData(nameof(TestCases))]
    public void TestStringToIntegerArray(
        string featureName,
        string testName,
        string cteStatement,
        string customAssertion,
        string querySuffix = null!
    )
    {
        SetupTest(cteStatement);
        RunTestWithSuffix(featureName, testName, this.cteStatement, customAssertion, querySuffix);
    }
}
 
[Trait("Language", "Csharp")]
[Trait("Category", "SRF")]
public class StringToIntegerArrayTestsCsharp : BaseStringToIntegerArrayTests
{
    protected override string FunctionBody =>
        @"
        return args.Cast<string>().Select(arg => (int?)(arg == null ? 0 : int.Parse(arg)));
    ";
    protected override LanguageType Language => LanguageType.PlcSharp;
}
 
// [Trait("Language", "SQL")]
// [Trait("Category", "SRF")]
// public class StringToIntegerArrayPlSqlTestsSQL : BaseStringToIntegerArrayPlSqlTests
// {
//     protected override string FunctionBody =>
//         @"
// DECLARE
//       value text;
//     BEGIN
//       FOREACH value IN ARRAY strings
//       LOOP
//         IF value IS NULL THEN
//           RETURN NEXT 0;
//         ELSE
//           RETURN NEXT value::integer;
//         END IF;
//       END LOOP;
//       RETURN;
//     END;
//     ";
//     protected override LanguageType Language => LanguageType.PlPgSQL;
// }