Исходный код СУБД 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
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using Xunit;
using System.Linq;
 
public abstract class BaseModifyIntervalFsharpTests : PlDotNetTest
{
    protected abstract string FunctionBody { get; }
 
    protected abstract LanguageType Language { get; }
 
    public BaseModifyIntervalFsharpTests()
    {
        FunctionInfo = new SqlFunctionInfo { Name = "ModifyIntervalFsharp", Arguments = new List<FunctionArgument> { new FunctionArgument("orig_interval", "INTERVAL"), new FunctionArgument("days_to_add", "INT"), new FunctionArgument("months_to_add", "INT") }, ReturnType = "INTERVAL", Body = FunctionBody, Language = Language, IsStrict = false, };
    }
 
    public static object[][] TestCases()
    {
        return new object[][] { new object[] { "f#-interval", "modifyIntervalFSharp1", "INTERVAL '4 hours 5 minutes 6 seconds', 15, 20", "= INTERVAL '1 YEAR 8 MONTHS 15 DAYS 4 HOURS 5 MINUTES 6 SECONDS'" }, new object[] { "f#-interval-null", "modifyIntervalFSharp2", "NULL::INTERVAL, 15, 20", "= INTERVAL '2 YEAR 40 DAYS 15 MINUTES'" }, };
    }
 
    [Theory]
    [MemberData(nameof(TestCases))]
    public void TestModifyIntervalFsharp(string featureName, string testName, string input, string expectedResult)
    {
        RunGenericTest(featureName, testName, input, expectedResult);
    }
}
 
[Trait("Language", "FSharp")]
[Trait("Category", "DateTime")]
public class ModifyIntervalFsharpTestsFSharp : BaseModifyIntervalFsharpTests
{
    protected override string FunctionBody => @"
let orig_interval = if orig_interval.HasValue then orig_interval.Value else NpgsqlInterval(4, 25, 900000000)
NpgsqlInterval(orig_interval.Months + months_to_add.Value, orig_interval.Days + days_to_add.Value, orig_interval.Time)
    ";
    protected override LanguageType Language => LanguageType.PlfSharp;
}