Skip to content

Commit 7b0da8d

Browse files
Merge pull request #23 from estebanzimanyi/gen/tostring-from-text-output
Print a value as the text MEOS writes it as
2 parents 92dc17c + 8906d80 commit 7b0da8d

33 files changed

Lines changed: 200 additions & 3 deletions

ExampleApp/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
Console.WriteLine("Reading a temporal float instant from \"25.0@2024-12-06\"");
1111
Temporal tfi = TFloat.In("25.0@2024-12-06")!;
1212
Console.WriteLine($" class : {tfi.GetType().Name}");
13-
Console.WriteLine($" text : {Meos.TfloatOut(tfi.Ptr, 15)}");
13+
Console.WriteLine($" text : {tfi}");
1414
Console.WriteLine($" start timestamp : {tfi.StartTimestamptz():u}");
1515
Console.WriteLine($" MF-JSON : {tfi.AsMFJSON(false, 0, 6, string.Empty)}");
1616
Console.WriteLine($" always 25.0? : {Meos.AlwaysEqTfloatFloat(tfi.Ptr, 25.0) == 1}\n");
1717

1818
Console.WriteLine("Making one from a value and a moment");
1919
Temporal made = TFloatInst.Make(26.0, DateTime.UtcNow)!;
20-
Console.WriteLine($" text : {Meos.TfloatOut(made.Ptr, 15)}");
20+
Console.WriteLine($" text : {made}");
2121
Console.WriteLine(" adding 34 to its value");
2222
Temporal sum = MEOSFactory.WrapTemporal(Meos.AddTfloatFloat(made.Ptr, 34.0))!;
2323
Console.WriteLine($" text : {Meos.TfloatOut(sum.Ptr, 15)}");
@@ -29,7 +29,7 @@
2929
Console.WriteLine($" spans : {spanset.NumSpans()}");
3030
foreach (Span? span in spanset.Spanarr())
3131
{
32-
Console.WriteLine($" {((FloatSpan)span!).Out(15)}");
32+
Console.WriteLine($" {span}");
3333
}
3434

3535
Console.WriteLine($" contains 9.0? : {Meos.ContainsSpansetFloat(spanset.Ptr, 9.0)}");

MEOS.NET.Tests/TextOutputTests.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using MEOS.NET.Types;
2+
3+
namespace MEOS.NET.Tests
4+
{
5+
/// <summary>
6+
/// A value prints as the text MEOS writes it as. MEOS publishes that text per
7+
/// concrete type, so a class carries <c>ToString</c> exactly where MEOS
8+
/// publishes an output for its own type.
9+
/// </summary>
10+
[TestClass]
11+
public class TextOutputTests : MeosTest
12+
{
13+
[TestMethod]
14+
public void ATemporalFloatPrintsAsMeosWritesIt()
15+
{
16+
Temporal temp = TFloat.In("[25.5@2024-12-06, 27.5@2024-12-07]")!;
17+
18+
Assert.AreEqual(
19+
"[25.5@2024-12-06 00:00:00+00, 27.5@2024-12-07 00:00:00+00]",
20+
temp.ToString());
21+
}
22+
23+
[TestMethod]
24+
public void ASpanPrintsAsMeosWritesIt()
25+
{
26+
SpanSet spanset = FloatSpanSet.In("{[8, 10], [11, 12]}")!;
27+
28+
Assert.AreEqual("[8, 10]", spanset.StartSpan()!.ToString());
29+
Assert.AreEqual("{[8, 10], [11, 12]}", spanset.ToString());
30+
}
31+
32+
[TestMethod]
33+
public void ABoxPrintsAsMeosWritesIt()
34+
{
35+
STBox box = STBox.In("STBOX X((1,1),(2,2))")!;
36+
37+
Assert.AreEqual("STBOX X((1,1),(2,2))", box.ToString());
38+
}
39+
40+
[TestMethod]
41+
public void TheTextComesFromTheClassOfTheValue()
42+
{
43+
// Wrapping answers the concrete class, so the text is that class's.
44+
Temporal instant = TFloat.In("25.5@2024-12-06")!;
45+
46+
Assert.IsInstanceOfType(instant, typeof(TFloatInst));
47+
Assert.AreEqual("25.5@2024-12-06 00:00:00+00", instant.ToString());
48+
}
49+
}
50+
}

MEOS.NET/Types/BigIntSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class BigIntSet : Set
1111
{
1212
internal BigIntSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public long EndValue()
1519
=> Meos.BigintsetEndValue(this.Ptr);
1620

MEOS.NET/Types/BigIntSpan.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class BigIntSpan : Span
1111
{
1212
internal BigIntSpan(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public Span? Expand(long value)
1519
=> MEOSFactory.WrapSpan(Meos.BigintspanExpand(this.Ptr, value));
1620

MEOS.NET/Types/BigIntSpanSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class BigIntSpanSet : SpanSet
1111
{
1212
internal BigIntSpanSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public long Lower()
1519
=> Meos.BigintspansetLower(this.Ptr);
1620

MEOS.NET/Types/CbufferSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class CbufferSet : Set
1111
{
1212
internal CbufferSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out(15);
17+
1418
public string Out(int maxdd)
1519
=> Meos.CbuffersetOut(this.Ptr, maxdd);
1620

MEOS.NET/Types/DateSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class DateSet : Set
1111
{
1212
internal DateSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public DateOnly EndValue()
1519
=> MEOSConvert.ToDateOnly(Meos.DatesetEndValue(this.Ptr));
1620

MEOS.NET/Types/DateSpan.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class DateSpan : Span
1111
{
1212
internal DateSpan(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public DateOnly Lower()
1519
=> MEOSConvert.ToDateOnly(Meos.DatespanLower(this.Ptr));
1620

MEOS.NET/Types/DateSpanSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class DateSpanSet : SpanSet
1111
{
1212
internal DateSpanSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out();
17+
1418
public Set? Dates()
1519
=> MEOSFactory.WrapSet(Meos.DatespansetDates(this.Ptr));
1620

MEOS.NET/Types/FloatSet.g.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class FloatSet : Set
1111
{
1212
internal FloatSet(IntPtr ptr) : base(ptr) { }
1313

14+
/// <summary>The text MEOS writes this value as.</summary>
15+
public override string ToString()
16+
=> this.Out(15);
17+
1418
public Set? Ceil()
1519
=> MEOSFactory.WrapSet(Meos.FloatsetCeil(this.Ptr));
1620

0 commit comments

Comments
 (0)