summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver/cc2/regression-tests/pure2-enum.cpp2
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2023-12-30 23:39:37 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2023-12-30 23:39:37 +0100
commit263915832993dd12beee10e204f9ebcc6c786ed2 (patch)
tree862e51208a99c35746e574a76564a4532b3a4a49 /CompilerDriver/cc2/regression-tests/pure2-enum.cpp2
Meta: initial commit of WestCo optimized toolchain.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver/cc2/regression-tests/pure2-enum.cpp2')
-rw-r--r--CompilerDriver/cc2/regression-tests/pure2-enum.cpp2120
1 files changed, 120 insertions, 0 deletions
diff --git a/CompilerDriver/cc2/regression-tests/pure2-enum.cpp2 b/CompilerDriver/cc2/regression-tests/pure2-enum.cpp2
new file mode 100644
index 0000000..4f1f886
--- /dev/null
+++ b/CompilerDriver/cc2/regression-tests/pure2-enum.cpp2
@@ -0,0 +1,120 @@
+
+skat_game: @enum type = {
+ diamonds := 9;
+ hearts; // 10
+ spades; // 11
+ clubs; // 12
+ grand := 20;
+ null := 23;
+}
+
+janus: @enum type = {
+ past;
+ future;
+
+ flip: (inout this) == {
+ if this == past { this = future; }
+ else { this = past; }
+ }
+}
+
+file_attributes: @flag_enum<u8> type = {
+ cached; // 1
+ current; // 2
+ obsolete; // 4
+ cached_and_current := cached | current;
+}
+
+main: () = {
+ j := janus::past;
+ j.flip();
+ _ = j;
+
+ // x : skat_game = 9; // error, can't construct skat_game from integer
+
+ x: skat_game = skat_game::clubs;
+ x2 := skat_game::diamonds;
+ x2 = x;
+
+ // if x == 9 { } // error, can't compare skat_game and integer
+ // if x == rgb::red { } // error, can't compare skat_game and rgb color
+
+ std::cout << "x.to_string() is (x.to_string())$\n";
+ std::cout << "x2.to_string() is (x2.to_string())$\n";
+
+ std::cout << "with if else: ";
+ if x == skat_game::diamonds { // ok, can compare two skat_games
+ std::cout << "diamonds";
+ }
+ else if skat_game::hearts == x { // ok, in either order
+ std::cout << "hearts";
+ }
+ else if x is (skat_game::spades) { // ok, using is
+ std::cout << "spades";
+ }
+ else if skat_game::clubs is (x) { // ok, using is
+ std::cout << "clubs";
+ }
+ else {
+ std::cout << "not a suit";
+ }
+
+ std::cout << "\nwith inspect: " << inspect x -> std::string {
+ is (skat_game::diamonds) = "diamonds";
+ is (skat_game::hearts ) = "hearts";
+ is (skat_game::spades ) = "spades";
+ is (skat_game::clubs ) = "clubs";
+ is _ = "not a suit";
+ } << "\n\n";
+
+ // x = 9; // error, can't assign skat_game from integer
+ // x = rgb::red; // error, can't assign skat_game from rgb color
+
+ x = skat_game::diamonds; // ok, can assign one skat_game from another
+
+ std::cout << "file_attributes::cached.get_raw_value() is (file_attributes::cached.get_raw_value())$\n";
+ std::cout << "file_attributes::current.get_raw_value() is (file_attributes::current.get_raw_value())$\n";
+ std::cout << "file_attributes::obsolete.get_raw_value() is (file_attributes::obsolete.get_raw_value())$\n";
+ std::cout << "file_attributes::cached_and_current.get_raw_value() is (file_attributes::cached_and_current.get_raw_value())$\n";
+
+ f: file_attributes = file_attributes::cached_and_current;
+ f &= file_attributes::cached | file_attributes::obsolete;
+ std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
+
+ f2 := file_attributes::cached;
+ std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
+
+ std::cout << "f is " << f.to_string() << "\n";
+ std::cout << "f2 is " << f2.to_string() << "\n";
+
+ f2.clear( f2 );
+ std::cout << "f2 is " << f2.to_string() << "\n";
+ f2.set(file_attributes::cached);
+ std::cout << "f2 is " << f2.to_string() << "\n";
+
+ std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
+ std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
+
+ std::cout << "f is (f2) is (f is (f2))$\n";
+ std::cout << "f2 is (f ) is (f2 is (f ))$\n\n";
+
+ f.clear( f2 );
+ f.set( file_attributes::current | f2 );
+ f |= file_attributes::obsolete;
+ f2 |= file_attributes::current;
+
+ std::cout << "f is " << f.to_string() << "\n";
+ std::cout << "f2 is " << f2.to_string() << "\n";
+ std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
+ std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
+ std::cout << "f == f2 is (f == f2 )$\n";
+ std::cout << "f is (f2) is (f is (f2))$\n";
+ std::cout << "f2 is (f ) is (f2 is (f ))$\n";
+ std::cout << "(f & f2) == f2 is ((f & f2) == f2)$\n";
+
+ std::cout << "inspecting f: " << inspect f -> std::string {
+ is (file_attributes::current) = "exactly 'current'";
+ is (cpp2::has_flags(f2)) = "includes all f2's flags ('cached' and 'current')";
+ is _ = "something else";
+ } << "\n";
+}