1 /++
2 $(H1 Mutable CSV scalar value)
3 
4 This module contains a single alias definition and doesn't provide CSV serialization API.
5 
6 License: $(HTTP www.apache.org/licenses/LICENSE-2.0, Apache-2.0)
7 Authors: Ilia Ki 
8 Macros:
9 +/
10 module mir.algebraic_alias.csv;
11 /++
12 Definition union for $(LREF JsonAlgebraic).
13 +/
14 import mir.algebraic: Variant;
15 
16 import mir.algebraic: Algebraic;
17 
18 public import mir.timestamp: Timestamp;
19 
20 /++
21 CSV tagged algebraic alias.
22 +/
23 alias CsvAlgebraic = Algebraic!Csv_;
24 
25 ///
26 union Csv_
27 {
28     /// Used for empty CSV scalar like one between two separators: `,,`
29     typeof(null) null_;
30     /// Used for false, true, False, True, and friends. Follows YAML conversion
31     bool boolean;
32     ///
33     long integer;
34     ///
35     double float_;
36     ///
37     Timestamp timestamp;
38     ///
39     immutable(char)[] string;
40 }
41 
42 ///
43 version(mir_ion_test)
44 unittest
45 {
46     CsvAlgebraic value;
47 
48     // Default
49     assert(value.isNull);
50     assert(value.kind == CsvAlgebraic.Kind.null_);
51 
52     // Boolean
53     value = true;
54 
55     assert(!value.isNull);
56     assert(value == true);
57     assert(value.kind == CsvAlgebraic.Kind.boolean);
58     assert(value.boolean == true);
59     assert(value.get!bool == true);
60     assert(value.get!(CsvAlgebraic.Kind.boolean) == true);
61 
62     // Null
63     value = null;
64     assert(value.isNull);
65     assert(value == null);
66     assert(value.kind == CsvAlgebraic.Kind.null_);
67     assert(value.null_ == null);
68     assert(value.get!(typeof(null)) == null);
69     assert(value.get!(CsvAlgebraic.Kind.null_) == null);
70 
71     // String
72     value = "s";
73     assert(value.kind == CsvAlgebraic.Kind..string);
74     assert(value == "s");
75     assert(value..string == "s");
76     assert(value.get!string == "s");
77     assert(value.get!(CsvAlgebraic.Kind..string) == "s");
78 
79     // Integer
80     value = 4;
81     assert(value.kind == CsvAlgebraic.Kind.integer);
82     assert(value == 4);
83     assert(value != 4.0);
84     assert(value.integer == 4);
85 
86     // Float
87     value = 3.0;
88     assert(value.kind == CsvAlgebraic.Kind.float_);
89     assert(value != 3);
90     assert(value == 3.0);
91     assert(value.float_ == 3.0);
92     assert(value.get!double == 3.0);
93     assert(value.get!(CsvAlgebraic.Kind.float_) == 3.0);
94 }